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

Rework special node button dictionary #607

Closed
CelticMinstrel opened this issue Feb 15, 2025 · 13 comments
Closed

Rework special node button dictionary #607

CelticMinstrel opened this issue Feb 15, 2025 · 13 comments
Assignees
Labels
question scenedit Affects the scenario editor work Non coding related task

Comments

@CelticMinstrel
Copy link
Member

The special node button_dict (in special.cpp) encodes what sort of button should be placed on each special node field and what kind of picker should appear when that button is pressed. It's encoded as 2-dimensional arrays with each ASCII character having a different meaning. It's quite compact and works just fine, but actually editing it to fix issues or add a new type is rather painstaking.

I'm trying to think of a better way to do it that's easier to edit while not being overly verbose. This is in service of eventually adding several new picker types (including some dynamic pickers), as well as a "simple toggle" case which replaces the entire field with an LED.

Ultimately what it needs to do is to populate a node_properties_t struct for each possible special node type. Directly declaring the array of node_properties_t would probably be possible but feels like it would be overly verbose.

@CelticMinstrel CelticMinstrel added question scenedit Affects the scenario editor work Non coding related task labels Feb 15, 2025
@CelticMinstrel CelticMinstrel self-assigned this Feb 15, 2025
@NQNStudios
Copy link
Collaborator

Oh dear... Somehow I'd never seen this before now.

static const char*const button_dict[7][11] = {

My gut reaction is that I hate it.

@NQNStudios
Copy link
Collaborator

What if the information was encoded as XML, which was written by a WYSIWYG editor showing what the edit special node dialog would look like when the node's definition was parsed?

@CelticMinstrel
Copy link
Member Author

That sounds like extreme overkill for something that's only going to be edited by developers… it's not the most terrible of ideas, but I don't think I like it.

CelticMinstrel added a commit that referenced this issue Feb 16, 2025
Basically what that means is that the magic characters are only parsed at startup – the scenario editor code doesn't need to understand them, instead using an enum.

This is part of the work for #607
@CelticMinstrel
Copy link
Member Author

I got started on trying to clean this up. The above commit defines the structure of how the information should be in memory, while retaining the magic characters during loading.

Any comments are welcome.

@NQNStudios
Copy link
Collaborator

NQNStudios commented Feb 18, 2025

I was baffled recently by trying to parse through this area of code the other day:

3bd4adc#diff-176a6d3d8f719743296a0862725f49ddc4706bde78837e720bec1ab78b9c6200L880

And I can say that it is a lot more readable with enums than with magic characters as the case labels.

@CelticMinstrel
Copy link
Member Author

Does it seem like the above WIP commit might be going in the right direction? (Pay the closest attention to the newly-added file.)

@NQNStudios
Copy link
Collaborator

Seems like you accidentally deleted the weight field from item.hpp?

But I really like the way it's going, with the builder pattern. It's much more readable to see which node has which properties.

(The only thing about the builder pattern is, it's only readable if you recognize it & know how it works. When I first saw spells.cpp I was super confused about what it was representing. So, we should make sure to have comments explaining well what the file is doing and how to add new nodes.)

CelticMinstrel added a commit that referenced this issue Feb 20, 2025
@CelticMinstrel
Copy link
Member Author

Considering various ways of formatting this. The above commit shows "compact" style in specials-general and specials-oneshot, but "verbose" style in specials-affect.

Beyond the difference shown there, there are a few other options:

  • I could make .finish() be implicit if I didn't use auto on the declarations (they'd need to be declared as node_property_t).
  • I could also avoid auto but still keep .finish().
  • Even if not using the "verbose" style, I'd probably break up the longest ones into multiple lines, but not one field per line.

There's no need to respond to this, but if you have any thoughts on the matter at all, feel free to let me know.

@NQNStudios
Copy link
Collaborator

I don't think I mind the verbose style. I do think finish() should be implicit.

@CelticMinstrel
Copy link
Member Author

I think that completes the rework of the button dictionary? It looks like the pickers are working correctly still.

@NQNStudios
Copy link
Collaborator

It can't really break the game, can it? Just the editor?

@CelticMinstrel
Copy link
Member Author

It can actually break the game, since this structure is also used by the function that parses special nodes from a file.

CelticMinstrel added a commit that referenced this issue Feb 23, 2025
Basically what that means is that the magic characters are only parsed at startup – the scenario editor code doesn't need to understand them, instead using an enum.

This is part of the work for #607
CelticMinstrel added a commit that referenced this issue Feb 28, 2025
Basically what that means is that the magic characters are only parsed at startup – the scenario editor code doesn't need to understand them, instead using an enum.

This is part of the work for #607
CelticMinstrel added a commit that referenced this issue Mar 2, 2025
Basically what that means is that the magic characters are only parsed at startup – the scenario editor code doesn't need to understand them, instead using an enum.

This is part of the work for #607
CelticMinstrel added a commit that referenced this issue Mar 3, 2025
Basically what that means is that the magic characters are only parsed at startup – the scenario editor code doesn't need to understand them, instead using an enum.

This is part of the work for #607
@CelticMinstrel
Copy link
Member Author

This is closed by #655 / 4174ccd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question scenedit Affects the scenario editor work Non coding related task
Projects
None yet
Development

No branches or pull requests

2 participants