OpenNaja / cobra-tools

A suite of GUI tools for extracting and modifying OVL and OVS archives, as well as editing the associated in-house file formats. Also includes a model plugin for Blender. For downloads, guides, and FAQs visit:
https://opennaja.github.io/cobra-tools/
GNU General Public License v3.0
98 stars 28 forks source link

More changes to codegen, description of generated code and new validation interface. #248

Closed Candoran2 closed 2 years ago

Candoran2 commented 2 years ago

Overview of changes:

  1. Parent classes specified in source files are now taken into account with codegen.
  2. Added readme to the codegen folder to describe the format/design of the generated code.
  3. Enums and bitfields will now write any int-convertible class.
  4. Arrays without a shape attribute are assumed to be single-dimensional and checked on length.
  5. Addition of the validate_instance class method to all base classes.

Detailed overview

  1. Analysis of the code to find the class definition happens through ast if the python version supports it, otherwise through regex. The specified or implied parent class from the codegen is added only if it isn't already in the existing parents, and it is the last parent (if you don't it to be, add it in the correct position in source).
  2. Self-explanatory, see the readme for the full contents. I thought it might be useful, especially should codegen become its own repository. The shared interface proposal on my wiki was getting outdated anyways.
  3. This change is mostly in case you accidentally assign an int instead of an enum/bitfield to a field without realising it. It could be restricted in future to only ints if necessary.
  4. Mostly tolerance in case the dtype has its own custom array writing function that returns a list or list-of-lists, or at least accepts those for writing, because we don't pass the actual shape parameter to the writing function.
  5. This was useful to find places where the correct parameters weren't being assigned which didn't lead to errors upon writing, but did not write correct files. Can be called before writing to prevent this and find wrongly assigned fields.