-
Notifications
You must be signed in to change notification settings - Fork 1
Chapter 3: Append and 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.
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
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.
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.
If the file extension of the append file is .xml
-
nope nothing to see here lol!
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.
-- Based off on Friday Night Funkin' --