Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONConfigFile 2.0.0 - Godot 4.0 #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

JSONConfigFile 2.0.0 - Godot 4.0 #1

wants to merge 4 commits into from

Conversation

98teg
Copy link
Owner

@98teg 98teg commented Apr 22, 2023

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:

  • First Godot 4.0 port.
  • Add Image Property.
  • Add preprocessor
  • Add postprocessor.
  • Refactor JSONConfigFile's parse method for it to receive the schema.
  • Add static method parse_path.
  • Create documentation.
  • Create a demo project.
  • Add CI, unit testing & linting.

@98teg 98teg force-pushed the godot-4.0 branch 8 times, most recently from 215e7ee to 1f8cad9 Compare April 22, 2023 12:42
@98teg 98teg force-pushed the godot-4.0 branch 13 times, most recently from 444f50f to 6e0bf9f Compare May 28, 2023 07:29
@98teg 98teg force-pushed the godot-4.0 branch 2 times, most recently from ca23b78 to a911803 Compare June 10, 2023 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant