don-tnowe / godot-inspector-extender

Using just comments, add specialized inspectors for your Godot 4 scripts.
MIT License
97 stars 8 forks source link

Rework how `show_if` controls other attributes and variables #6

Closed EthanGrahn closed 10 months ago

EthanGrahn commented 10 months ago

This turned out to be a larger rework than I had thought.

Overview

The @@show_if attribute is now a PanelContainer. All custom attributes and the property itself will be assigned as children to the PanelContainer. When the expression is true, the container will hide itself which also hides the children. The choice to use PanelContainer is so that it will automatically scale itself to fit all child elements.

@@show_if works as a "delayed attribute" meaning it will wait until the next property is being parsed to be initialized. This allows the previous property, and any supplemental attributes, to be loaded into the tree for access.

Resolves #5

attributes.cfg

To reduce the size of the main plugin script and improve maintainability/readability, I moved the attribute_scenes map information into a config file. The section names in the config file match the attributes available for use. This config file is parsed in the main plugin script and constructs the attributes_scenes map dynamically. Although it's basic right now, this could be extended to allow customizing settings per attribute.

Tables

This change is not necessary for this fix, it was an early refactor when I thought adjustments to the tables would be needed. I split table.gd into separate table scripts that all inherit from a base table. This avoids the large if statements in the original script and allows checking types if necessary. (e.g. if node is MultiArrayTableAttribute)

I'm open to making any changes, just let me know!

EthanGrahn commented 10 months ago

Noting a potential issue that may need another PR - If show_if is on the last variables, I expect it to fail because it won't be able to initialize during the next variable.

don-tnowe commented 10 months ago

Wow, this... seems to have been a lot of work.

However:

I will consider the implemented refactorings, and would appreciate a pull with only changes to address #5!