From fd5b30faf60872373e70ff14135cda3bb2ea8686 Mon Sep 17 00:00:00 2001 From: Cody Seibert Date: Wed, 16 Oct 2024 20:03:22 -0400 Subject: [PATCH] improving seed function to update existing maps if they were changed --- convex/maps.ts | 33 ++++++++++++++++++++++----------- models/index.ts | 1 + 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/convex/maps.ts b/convex/maps.ts index 7a07263..e0907af 100644 --- a/convex/maps.ts +++ b/convex/maps.ts @@ -22,23 +22,34 @@ const LEVELS = [ ["Z", " "], ], }, + { + grid: [ + [" ", " "], + ["R", " "], + ["Z", "Z"], + ["Z", "Z"], + ], + }, ]; export const seedMaps = internalMutation({ handler: async (ctx) => { - const firstMap = await ctx.db.query("maps").first(); - - if (firstMap) { - return; - } + const maps = await ctx.db.query("maps").collect(); await Promise.all( - LEVELS.map((map, idx) => - ctx.db.insert("maps", { - level: idx + 1, - grid: map.grid, - }), - ), + LEVELS.map((map, idx) => { + const existingMap = maps.find((it) => it.level === idx + 1); + if (existingMap) { + ctx.db.patch(existingMap._id, { + grid: map.grid, + }); + } else { + ctx.db.insert("maps", { + level: idx + 1, + grid: map.grid, + }); + } + }), ); }, }); diff --git a/models/index.ts b/models/index.ts index 9befe30..49c36c3 100644 --- a/models/index.ts +++ b/models/index.ts @@ -57,6 +57,7 @@ The 2d Grid is made up of characters, where each character has a meaning. - often it's good to wall off between the zombies and players if possible, this will slow the zombies down. - You should never put a player directly next to a zombie. - You should try to put blocks directly next to players +- If the player is behind a choke point, blocking the path to the player is the best option. # Output Format