JSONConfigFile
JSONConfigFile copied to clipboard
JSONConfigFile 2.0.0 - Godot 4.0
Godot 4.0 migration
This is the pull request where I would explain the status of the Godot 4.0 port. This port is a full rewrite of the original plugin.
Main goals
Reduce the number of exposed classes
In the previous version, each JSON property was exposed as a named class, which could bloat the autocomplete features of the Godot editor. In this migration, the main objective was to reduce them to just two:
-
JSONConfigFile
: receives a file path and parses it as a JSON. -
JSONSchema
: represents the structure of the JSON data.
Simplify the API
This is a code example from version 1.0.0:
var json_config_file = JSONConfigFile.new()
json_config_file.add_property("name", JSONPropertyString.new())
json_config_file.add_property("age", JSONPropertyInteger.new())
var gender = JSONPropertyEnum.new()
gender.set_enum(["MALE", "FEMALE", "NON_BINARY"])
json_config_file.add_property("gender", gender)
var telephone_number = JSONPropertyString.new()
telephone_number.set_pattern("^( |[0-9])+$")
json_config_file.add_property("telephone_number", telephone_number)
var address = JSONPropertyObject.new()
address.add_property("street", JSONPropertyString.new())
address.add_property("number", JSONPropertyInteger.new())
json_config_file.add_property("address", address)
json_config_file.validate(json_config_file_path)
In 2.0.0, it would look like this:
var schema := JSONSchema.new()
schema.add_string("name")
schema.add_int("age")
schema.add_enum("gender").add_value("MALE", 0).add_value("FEMALE", 1).add_value("NON_BINARY", 2)
schema.add_string("telephone_number").set_pattern("^( |[0-9])+$")
var addess := JSONSchema.new()
addess.add_string("street")
addess.add_int("number")
schema.add_dictionary("address").set_schema(addess)
JSONConfigFile.parse_path(json_config_file_path, schema)
Make it similar to Godot's JSON API
I would try to make JSONConfigFile
as similar to JSON
as possible.
Tasks
In order of priority:
- [x] First Godot 4.0 port.
- [ ] Add Image Property.
- [ ] Add preprocessor
- [x] Add postprocessor.
- [x] Refactor
JSONConfigFile
'sparse
method for it to receive the schema. - [x] Add static method
parse_path
. - [ ] Create documentation.
- [ ] Create a demo project.
- [x] Add CI, unit testing & linting.