Skip to content

Commit

Permalink
add ability to have multiple mods in folder
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Sep 23, 2024
1 parent 81069db commit 3518ffc
Showing 1 changed file with 44 additions and 32 deletions.
76 changes: 44 additions & 32 deletions _transformers/modimport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

0 comments on commit 3518ffc

Please sign in to comment.