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

Variable Substitution: Options for enabling substution in command strings & for applying {fmt}-style number formatting #3220

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

florianessl
Copy link
Member

This PR enables two new features:

  • Variable substitution in interpreter command strings (default CommandCodeInserter is used -> \v, \n, \t)
  • Number formatting using {fmt}
    just write the format specification after a ':'
    the parser will ignore anything that is not valid fmt syntax (also decimal types & 'precision' are not supported)

These two features require setting new liblcfs fields which are specified as follows:

System,easyrpg_var_substitution_in_commands,f,Boolean,0xDC,False,0,0,Enables substitution of '\v' '\n' '\a' inside string parameters of interpreter commands
System,easyrpg_var_substitution_formatting,f,Boolean,0xDD,False,0,0,Enables '{fmt}'-style format specifiers for usage inside variable substitution

Example: Graphics customization

Consider you want to dynamically change an actor graphic or faceset depending on some settings.

With this branch you can just use any pre-existing command like this:

com.string: "Actor\v[123:02d]"

... which evaluates to "Actor01.png", "Actor02.png", ..., "Actor[xx].png" depending on the value of Variable '123'

Copy link
Member

@Ghabry Ghabry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supporting string substitution for the event string arg sounds a bit insane xD. But it could be useful (and faster than always doing a round trip through a String Variable).

I think I cannot accept this without additional unit tests to verify that the fmt-style args work properly.


Minor: Bit unfortunate that this requires always copying com.string even when the evaluation is disabled. I wonder if this can be prevented 🤔

src/game_interpreter.cpp Outdated Show resolved Hide resolved
src/game_interpreter.cpp Outdated Show resolved Hide resolved
@florianessl
Copy link
Member Author

Oh, haven't thought about the reference not working there. Stupid me.
I'l look into how I can improve this without any unnecessary copying, and unit-tests for the formatting were definitely on my mind, I'm just working on several branches right now and am constantly shifting my focus :D

I'm working on an extensive test suite for my three main branches, which hopefully will cover all sorts of use cases:
"ScopesVars", "MapInitTrigger" & this one. So, no need to go over any of those while this is still a work-in-progress (also, I'm on holiday for two weeks, so it will take some time.)

@carstene1ns carstene1ns added the Awaiting Rebase Pull requests with conflicting files due to former merge label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Rebase Pull requests with conflicting files due to former merge
Development

Successfully merging this pull request may close these issues.

3 participants