Skip to content

Chapter 3: Append and Merge

charlesisfeline edited this page Nov 16, 2024 · 3 revisions

Chapter 3: Append + Merge

There will often be times where you wanna modify the contents of an existing file. It's relatively easy for textures (.PNG and .XML) and audio (.OGG), however it gets more complicated when doing so with data files (.JSON). You often may not wanna replace the whole file, but instead just a smaller bit of it, or heck even a single value. Thankfully, Polymod provides a function for doing this.

Appending Files

Adding values to the end of a data file, yeah kinda easy, but it is dependent on the file type you want to append to.

Just create a new file in the _append/ folder of your mod, along with a path matching the file you want to append to. For example, to append to assets/data/introText.txt, you would place your file at mods//_append/data/introText.txt

Appending to .TXT Files

If the file extension of the append file is .txt, the contents of the file will be simply appended to the end of the target file.

Appending to .CSV/.TSV Files

If the file extension of the append file is .csv or .tsv, the rows in the sheet will be added to the end of the target sheet.

Appending to .XML Files

If the file extension of the append file is .xml-

todo nope nothing to see here lol!

Appending to .JSON Files

If the file extension of the append file is .json, the value will be parsed and appended to the target data, without judgement lol.

For example, given the source file data/gould.json:

{
  "youstoopid": [9, 10, 21],
  "eddcrew": {
    "tord": "red",
    "edd": "green",
    "tom": "blue"
  },
  "whoareyou": "alphamale"
}

We can provide the file mods/tordbot/_append/data/gould.json:

{
  "rockyIs": "gay",
  "eddcrew": {
    "tord": "red",
    "edd": "green",
    "tom": "blue",
    "matt": "idk"
  }
}

And Polymod will mix it up, resulting with this:

{
  // This shit not touched!
  "youstoopid": [9, 10, 21],
  // Included values aren't merged. Rather, they are placed in directly.
  "eddcrew": {
    "tord": "red",
    "edd": "green",
    "tom": "blue",
    "matt": "idk"
  },
  // Also untouched.
  "whoareyou": "alphamale",
  // New values just simply get added.
  "rockyIs": "gay"
}

If you want something more particular for ya, continue on until the "Merging into .JSON Files" part for a more powerful and flexible approach.