jumpy icon indicating copy to clipboard operation
jumpy copied to clipboard

Add Asset Validation Workflow

Open orhun opened this issue 2 years ago • 3 comments

More schemas should be added for validating the JSON files in assets/ directory.

Schemas can be added by doing one of the following:

  • Add the corresponding schema for a JSON file, such as file.schema.json
  • Add a common schema file named schema.json in a directory and it is used for validating all of the JSON files in that directory.

Schema files should be in JSON Draft-07 format and they can be generated or written by hand. (see this site for an example)

After adding a new schema, scripts/validate_json.sh can be used for validation. (ajv-cli is needed)

Additional context

  • #187
  • #232

orhun avatar Nov 08 '21 15:11 orhun

I will create schemas for all the item stuff once I finish the current sprint and then finish off the API by implementing the environment items (sproingers etc)

olefasting avatar Nov 09 '21 07:11 olefasting

I am currently looking into a few solutions for automatic generation of json schemas from Rust types.

Writing the schemas by hand for items, turned out to be a more complicated affair than I had envisioned, due to how I use enum trickery to allow for generic typing, among other things, for example allowing either a value or an array of a type, for effects and the like. There will also be a lot of repetition, due to the fact that we have to repeat all the components in all the schemas of types that put them to use. If I can't find an adequate solution to automate this reliably, I am tempted to exempt the items from the schema workflow, as I fear it will cause more problems than it will solve, if we manually have to maintain the various schemas for the different variants of Item (Weapon, Equipped and Environment, and so on).

There really aren't that many things that are required for an implementation of an Item, any ways, You have a lot of options, but the only things that are hard requirements, are id, type, sprite, collider_size, animation and effects, in the case of a Weapon, and it will not be possible to run the game if you omit them or provide invalid data (so, most such errors will be caught in testing).

I really like the idea of having the validation workflow, though, as it will ease the job of code reviewing submissions and lower the bar of participation, as well as put a valuable framework in place, for less experienced people, once we have a system for loading data-oriented mods in place (soon). Also, if I fail to find a viable solution, worst case, I can implement a cli tool that can use serde to validate item data, with relative ease.

I will also continue to create schemas for other types, like Map and all the various resource index files.

olefasting avatar Nov 15 '21 12:11 olefasting

While we've switched to YAML and a lot of things are probably going to change, the schemars crate does generate JSON schema documents from serde structs, so that's something to try out if we end up needing JSON schema's again.

zicklag avatar Nov 23 '22 02:11 zicklag