I'm writing a plugin for a little game I am developing that will need to load an additional JSON file into a variable used by the plugin itself.
Notes:
- custom.json exists and it is placed in "data/" folder together with the default JSon files.
- custom.json is a valid json file that it was generated by a python script I wrote
----
Well... the problem is that MyManager._mydata is actually null and did not load the json data. I'm reading deeper the core JS files and I tried to understand how DataManager.loadDataFile and DataManager.onLoad but I can't understand how (and where) the strings like "$dataActors'' are able to direct the code to actually fill the (global) variable with that name.
Side note: the data contained in custom.json is not an Array of values, but a dictionary that currently contains two keys and their values.
Here also the current version of custom.json:
The two main keys are "alfa" and "beta". Each key contains "index sub-key". Each of index subjey have a "stats" and "actors" dictorinaries.
So my doubt is: how can I load the JSON data in MyManager._mydata
Code:
(function () {
function MyManager() {
throw new Error("This is a static class");
}
MyManager._mydata = null;
DataManager._databaseFiles.push(
{ name: 'MyManager._mydata', src: 'custom.json' }
)
[...]
})();
Notes:
- custom.json exists and it is placed in "data/" folder together with the default JSon files.
- custom.json is a valid json file that it was generated by a python script I wrote
----
Well... the problem is that MyManager._mydata is actually null and did not load the json data. I'm reading deeper the core JS files and I tried to understand how DataManager.loadDataFile and DataManager.onLoad but I can't understand how (and where) the strings like "$dataActors'' are able to direct the code to actually fill the (global) variable with that name.
Side note: the data contained in custom.json is not an Array of values, but a dictionary that currently contains two keys and their values.
Here also the current version of custom.json:
{"alfa": {"1": {"stats": {"1,1": 1000}, "actors": {"1,1": [17, 18, 19, 20]}}, "2": {"stats": {"1,2": 200, "1,1": 800}, "actors": {"1,1": [17, 18, 19, 20]}}, "3": {"stats": {"1,2": 450, "1,1": 550}, "actors": {"1,1": [17, 18, 19, 20]}}, "4": {"stats": {"1,2": 1000}, "actors": {}}, "5": {"stats": {"1,2": 400, "1,3": 100, "1,1": 500}, "actors": {"1,1": [17, 18, 19, 20]}}, "6": {"stats": {"1,3": 1000}, "actors": {}}, "7": {"stats": {"1,3": 950, "1,4": 50}, "actors": {}}, "8": {"stats": {"1,2": 220, "1,3": 430, "1,4": 350}, "actors": {}}, "9": {"stats": {"1,2": 50, "1,1": 950}, "actors": {"1,1": [17, 18, 19, 20]}}, "10": {"stats": {"1,5": 30, "1,3": 700, "1,4": 270}, "actors": {}}}, "beta": {"0": {"stats": {"1,2": 450, "1,3": 50, "1,1": 500}, "actors": {"1,1": [17, 18, 19, 20]}}, "1": {"stats": {"1,3": 15.0, "1,4": 265.0}, "actors": {}}}}
The two main keys are "alfa" and "beta". Each key contains "index sub-key". Each of index subjey have a "stats" and "actors" dictorinaries.
So my doubt is: how can I load the JSON data in MyManager._mydata