GitHub: https://github.com/Insality/defold-parser
Defold Parser - node module to encode and decode Defold files.
There are several tools to parse & edit Defold files like amazing DefTree, but in some cases probably you wanna use the Node/JS. So here is it!
I often use this instrument in my work and I wanna share it with you.
(still not using Defold proto files)
Install
To install defold-parser use npm
.
npm install --save defold-parser
Usage
Add require line to your .js
script:
const defold_parser = require("defold-parser")
All available API is:
// Parse any Defold file (go, gui, collection, particlefx, etc)
let object = defold_parser.load_from_file([path_to_defold_file])
// Save object to the Defold format
defold_parser.save_to_file([path_to_file], [object])
// You can pass text string directly
let object = defold_parser.decode_object([defold_text_string])
// And get Defold encoded text directly too
let defold_text_string = defold_parser.encode_object([js_object])
Every Defold parsed struct is array, even for single fields. To access any field you should access it on first array index. For example:
let parsed_collection = defold_parser.load_from_file("./tests/files/collection.collection")
let instance = parsed_collection.embedded_instances[0]
assert(instance.id[0] == "tile")
assert(inner_component.id[0] = "sprite")
assert(inner_component.type[0] = "sprite")
To know, which fields you wanna edit, see the file struct you parsing or just use console.log
in development