Description
The purpose of this Plugin is to allow you to work with complex Json objects from within the event system. High level Objectives include
- Load multiple json files at one time.
- Each file represents a json object and can be loaded into a named slot.
- Query and set values from the Json file using standard javascript notation.
- Loop over sub object arrays and nested sub object arrays and retrieve and set values.
- Allow Caching to be utilized if required so that json changes will be available during the next run but without altering the json files themselves.
- Allow an altered slot to be reset back to original json
- Get the length of an array within the json object based on standard javascript notation.
- Create a new json slot from a copy of a sub object from another slot based on a query.
- Create a C3 Array plugin object from a query into a named slot.
- Create a C3 Dictionary plugin object from a query into a named slot.
Restrictions
- Note important info at the bottom of this page on local storage and looping.
- json files can only contain one root object, so the first character and last character should be { }
- When converting a sub object to a C3 array, the array can not contain anything other then basic 1D, 2D, and 3D arrays. Object in an array can not be converted to the C3 array.
- When converting a sub object to a C3 dictionary, the dictionary can not contain anything other then basic object with property keys and values. Any additional objects within the object you are converting will be ignored by the C3 dictionary.
Load in Json Files
To specify the files to load and what to label them for access later you must set the following properties on the JsonManager itself through the properties page. The two items to fill in are:
- Json Files to Load: Comma separated list of file names like file.json,file2.json
- Json File Slot List: Comma separated list of slot names to load the above files into like slot1,slot2
Available Functions
Please refer to the included example file, JsonAddOnTest.c3p, to view how to use all the features of the Plugin. It is well commented and show provide good examples of how to accomplish all of the different tasks.
Json files by url
Care must be taken when using a url to load a Json file. The plugin was originally designed to work with Json files included in the project. When testing on your local machine the preview pane runs with https, which makes loading a file from http an issue (If you are loading it from your local web server). If you use http://127.0.0.1:port#, it will trusted by the browser to make a call from https to http, but you'll need to make sure your local web server that is serving the Json file has Cors headers set. Once that is done you can load the file with a url in preview. Of course if you make a call to an external server that is using ssl already, it should work.
Local Stotage
This plugin uses local storage to manage it's internal function regardless of whether you use caching or not. It manages it's own named locations in storage so it won't interfere with other programs. However if you totally clear cache some where in your game, you could affect this plugin.
Looping
This only pertains to my Json array loops nested inside of another Json array loop condition.
Conditions (Loop) - There is a parameter to indicate if this loop is nested inside another Json array loop. Set this to Yes when you are nested inside another one so it knows to use the relative position of the first one to locate nodes. If there is only one Json loop array structure set this to No.
Actions - There is a parameter to indicate if this action is inside of a json array loop. Set to Yes if so and No otherwise. This allows the action to ignore the slot designation and use the relative path of the current loop item.
Expressions - There is a parameter to indicate if this expression is inside of a Json array loop. Set to Yes if so and No otherwise. This allows the expression to ignore the slot designation and use the relative path of the current loop item.