diff --git a/_transformers/modimport.js b/_transformers/modimport.js index 9ba076a..e8955ae 100644 --- a/_transformers/modimport.js +++ b/_transformers/modimport.js @@ -46,44 +46,56 @@ fs.ensureDirSync(OUTPUT_DIR); fs.ensureDirSync(`${OUTPUT_DIR}/maps`); fs.ensureDirSync(`${OUTPUT_DIR}/simplemods`); +const joinedMod = {}; + fs.readdirSync("mods").forEach((mod) => { const modFile = fs.readJSONSync(`mods/${mod}`); - - fs.writeJSONSync(`${OUTPUT_DIR}/items.json`, modFile.items); - fs.writeJSONSync(`${OUTPUT_DIR}/npcs.json`, modFile.npcs); - fs.writeJSONSync(`${OUTPUT_DIR}/npc-scripts.json`, modFile.dialogs); - fs.writeJSONSync(`${OUTPUT_DIR}/recipes.json`, modFile.recipes); - fs.writeJSONSync(`${OUTPUT_DIR}/spawners.json`, modFile.spawners); - fs.writeJSONSync( - `${OUTPUT_DIR}/achievements.json`, - toHash(modFile.achievements, "name") - ); - - fs.writeJSONSync(`${OUTPUT_DIR}/quests.json`, toHash(modFile.quests, "name")); - - const globalDroptable = modFile.drops.find((drop) => drop.isGlobal); - const mapDrops = modFile.drops.filter((drop) => drop.mapName); - const regionDrops = modFile.drops - .filter((drop) => drop.regionName) - .map((drop) => ({ - ...drop, - drops: [...globalDroptable.drops, ...drop.drops], - })); - - fs.writeJSONSync(`${OUTPUT_DIR}/droptable-maps.json`, mapDrops); - fs.writeJSONSync(`${OUTPUT_DIR}/droptable-regions.json`, regionDrops); - - handleCoreFiles(modFile.cores); - handleSTEMs(modFile.stems); - handleTraitTrees(modFile.traitTrees); - - modFile.maps.forEach((mapData) => { - const { name, map } = mapData; - fs.writeJSONSync(`${OUTPUT_DIR}/maps/${name}.json`, map); + if (mod.includes("BaseGameContent")) { + joinedMod.meta = modFile.meta; + } + + Object.keys(modFile).forEach((key) => { + if (key === "meta") return; + joinedMod[key] ??= []; + joinedMod[key].push(...modFile[key]); }); const strippedMod = structuredClone(modFile); delete strippedMod.meta._backup; strippedMod.maps = []; + fs.writeJSONSync(`${OUTPUT_DIR}/simplemods/${mod}.json`, strippedMod); }); + +fs.writeJSONSync(`${OUTPUT_DIR}/items.json`, joinedMod.items); +fs.writeJSONSync(`${OUTPUT_DIR}/npcs.json`, joinedMod.npcs); +fs.writeJSONSync(`${OUTPUT_DIR}/npc-scripts.json`, joinedMod.dialogs); +fs.writeJSONSync(`${OUTPUT_DIR}/recipes.json`, joinedMod.recipes); +fs.writeJSONSync(`${OUTPUT_DIR}/spawners.json`, joinedMod.spawners); +fs.writeJSONSync( + `${OUTPUT_DIR}/achievements.json`, + toHash(joinedMod.achievements, "name") +); + +fs.writeJSONSync(`${OUTPUT_DIR}/quests.json`, toHash(joinedMod.quests, "name")); + +const globalDroptable = joinedMod.drops.find((drop) => drop.isGlobal); +const mapDrops = joinedMod.drops.filter((drop) => drop.mapName); +const regionDrops = joinedMod.drops + .filter((drop) => drop.regionName) + .map((drop) => ({ + ...drop, + drops: [...globalDroptable.drops, ...drop.drops], + })); + +fs.writeJSONSync(`${OUTPUT_DIR}/droptable-maps.json`, mapDrops); +fs.writeJSONSync(`${OUTPUT_DIR}/droptable-regions.json`, regionDrops); + +handleCoreFiles(joinedMod.cores); +handleSTEMs(joinedMod.stems); +handleTraitTrees(joinedMod.traitTrees); + +joinedMod.maps.forEach((mapData) => { + const { name, map } = mapData; + fs.writeJSONSync(`${OUTPUT_DIR}/maps/${name}.json`, map); +});