From 25e0466c9a40a7b153303015d599b5e3d8e4fe0e Mon Sep 17 00:00:00 2001 From: Rodrigoue9 Date: Tue, 18 Aug 2026 22:54:25 -0300 Subject: [PATCH] fix(api): provide seed npcs.json fixture and safe file loader (#83) --- api/src/jsons/npcs.json | 23 +++++++++++++++++++++++ api/src/lib/gameData.ts | 6 ++++++ 2 files changed, 29 insertions(+) create mode 100644 api/src/jsons/npcs.json diff --git a/api/src/jsons/npcs.json b/api/src/jsons/npcs.json new file mode 100644 index 00000000..4a58401f --- /dev/null +++ b/api/src/jsons/npcs.json @@ -0,0 +1,23 @@ +{ + "1": { + "name": "Comerciante de Armas", + "npcType": 10, + "idHead": 1, + "idBody": 1, + "movement": 0, + "objs": [ + { "item": 1, "cant": 50 }, + { "item": 2, "cant": 50 } + ], + "drop": [] + }, + "2": { + "name": "Sacerdote", + "npcType": 2, + "idHead": 2, + "idBody": 2, + "movement": 0, + "objs": [], + "drop": [] + } +} diff --git a/api/src/lib/gameData.ts b/api/src/lib/gameData.ts index d1f123c9..02ef995b 100644 --- a/api/src/lib/gameData.ts +++ b/api/src/lib/gameData.ts @@ -250,12 +250,18 @@ export function loadSeedNpcsJson(): Array<{ data: GameNpcRecordData; }> { const filePath = resolveSeedJsonPath("npcs.json", "npcs.compact.json"); + if (!fs.existsSync(filePath)) { + return []; + } return loadNpcsJsonFromFile(filePath); } export function loadNpcsJsonFromFile( filePath: string, ): Array<{ id: number; data: GameNpcRecordData }> { + if (!fs.existsSync(filePath)) { + return []; + } const raw = JSON.parse(fs.readFileSync(filePath, "utf8")) as NpcsById; return Object.entries(raw) .map(([id, data]) => ({ id: Number(id), data: normalizeNpcData(data) }))