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 26 forks source link

Codegen+Bitfield: Adding bool detection to `get_mask` #336

Closed reddraconi closed 1 year ago

reddraconi commented 1 year ago

As discovered in https://github.com/niftools/blender_niftools_addon/issues/580, when boolean values are generated for keys, they're not capitalized. This little patch should, hopefully, fix that.

Admittedly, this code generation code is way above my ability.

I made the changes in my local branch, installed the requirements.txt, and attempted to build with no discernible issues. I then ran codegen.py and didn't seen any suspicious output, so I hope this did the trick!

Candoran2 commented 1 year ago

Rather than checking whether the type is a basic, you should probably check whether the type is in self.parser.basics.booleans - since only booleans can have true/false as their default values.

reddraconi commented 1 year ago

I'm probably confused, but when I ran codegen.py in debug mode to see what the contents of self.parser.basics.booleans was, it appears to be empty.

image

It also appears that cobra-tools/source/formats/base/base.xml file doesn't have an entry for booleans. Am I crazy?

Steps to reproduce:

  1. Open cobra-tools folder in VSCode (or whatever you like)
  2. Set a breakpoint in cobra-tools/codegen/Bitfield.py on line 82
  3. Run cobra-tools/codegen.py in debug mode
  4. Observe in-memory data structures, digging down into the self object that's currently in focus.
  5. Compare to screenshot and notice that the 'self.parser.basics.booleans' has a length of 0.

This was all because I was trying to figure out if I needed the .lower() function in the square brackets or something else to make sure I triggered on an object in self.parser.basics.booleans.

Candoran2 commented 1 year ago

You're right in that base.xml doesn't have any booleans (boolean="true" in the xml struct). Nif.xml does have booleans, however.

reddraconi commented 1 year ago

Updated commit to add boolean type to base.xml so that checking for boolean values in the BitFields won't cause bad things to happen when self.parser.basics.booleans isn't populated.