KFNEXUS / KFNEXUS.github.io

GNU Lesser General Public License v3.0
3 stars 6 forks source link

split `data.json` into separate categories #37

Closed FND closed 6 years ago

FND commented 6 years ago

src/data/data.json has grown to >24k lines, making it rather unwieldy. Would you accept a pull request that splits this one big file into a bunch of smaller files (see below)?

That would also avoid confusion WRT people erroneously editing staw-utopia/data/data.json directly.


Implementing this should be pretty simple: After manually moving the data into separate files, the following Node.js script would be used to generate staw-utopia/data/data.json:

let fs = require("fs");
let path = require("path");

let shipData = require("./ships");
let data = {
    sets: require("./sets"),
    ships: shipData.ships,
    shipClasses: shipData.shipClasses,
    captains: require("./captains"),
    admirals: require("./admirals"),
    upgrades: require("./upgrades"),
    resources: require("./resources"),
    others: require("./others")
};

let filepath = path.resolve(__dirname, "../../staw-utopia/data/data.json");
fs.writeFileSync(filepath, JSON.stringify(data));

We can easily compare before and after to ensure the data itself hasn't changed.

FWIW, this would also allow us to use JavaScript instead of JSON in those source files - which means we could omit a bunch of quotation marks (e.g. type: "ship" vs. "type": "ship") and perhaps include some automated sanity checks - but that's something to be tackled separately (if at all).

CrazyVulcan commented 6 years ago

@FND I really like the idea, even on Notepad++ that file is really getting hard to navigate. When I open it I collapse the list completely anyway so this would be welcomed by me.

@KFNEXUS @jsterner73 Your thoughts?

jsterner73 commented 6 years ago

Yes, that's a nice idea. But make sure everything - including the grunt conversion - is working correctly and the output is the same on your local browser before you make that pull request.

FND commented 6 years ago

continued in #38