raphaelgoulart / ya_inputdisplay

Yet another input display for Clone Hero / YARG
16 stars 3 forks source link

Add IPS toggle which was way more complicated than I would like to admit #23

Closed SkyJumper409x closed 2 months ago

SkyJumper409x commented 2 months ago

So this is more than it needed to be but uh: I added a config value called show_ips in the Settings Section. I didn't like having lots of duplicate code for ButtonHamburger.gd and IPS.gd, so I renamed ButtonHamburger.gd to HideableUI.gd so it can be reused.

If a node has the HideableUI script, it must have a metadata bool called show_on_hover, which indicates if the UI element should be visible on hover (This is enabled for the Hamburger Button, but disabled for the IPS Label)

The IPS.gd-specific code was moved into Singleton.gd pretty simply. However, the litttle bit of hamburger-specific code in ButtonHamburger.gd was not easy to split. (I considered rewriting parts of the program in C# to use Interfaces for inheriting multiple scripts, but that felt a little overkill :3.) The code is in ConfigHandler now. I tried putting it in Singleton, but that did not work, as Singleton would try to access config values before ConfigHandler could assign them.

I also disabled IPS calculation if the IPS Label not visible, this came with its own quirk though. Even if save_config_and_exit() is running, Singleton._process(_delta) is still called every frame. The ConfigHandler.current_config.free() call in save_config_and_exit() will cause errors if an attempt is made to access ConfigHandler.current_config after it is free()'d to avoid this, Singleton.exiting is set to true when save_config_and_exit() is called, and ConfigHandler.current_config.show_ips will not be accessed by Singleton._process(_delta) if Singleton.exiting is true.

SkyJumper409x commented 2 months ago

Also, this closes #21

SkyJumper409x commented 2 months ago

I also disabled IPS calculation if the IPS Label not visible, this came with its own quirk though. Even if save_config_and_exit() is running, Singleton._process(_delta) is still called every frame. The ConfigHandler.current_config.free() call in save_config_and_exit() will cause errors if an attempt is made to access ConfigHandler.current_config after it is free()'d to avoid this, Singleton.exiting is set to true when save_config_and_exit() is called, and ConfigHandler.current_config.show_ips will not be accessed by Singleton._process(_delta) if Singleton.exiting is true.

I had this also happen in InputBar.gd. I searched all files for the regex func _process[\s\S\n]*?config[\s\S\n]*? to find other process methods accessing ConfigHandler.current_config and InputBar.gd seemed to be the only other script where that is the case. (Unrelated to IPS)