isXander / YetAnotherConfigLib

YetAnotherConfigLib (yacl) is just that. A builder-based configuration library for Minecraft.
GNU Lesser General Public License v3.0
96 stars 37 forks source link

Values visually reset to original values after saving. #48

Closed Giggitybyte closed 1 year ago

Giggitybyte commented 1 year ago

Setting a value then saving it will cause all values to revert to their original state when the screen was first opened. Closing then reopening the screen will read the updated value.

https://user-images.githubusercontent.com/19187704/208584816-dbf99a98-10a0-4767-b48a-98c5c2bcc4db.mp4

MC 1.19.3 YACL 2.1.1

isXander commented 1 year ago

You have most likely implemented the binding wrong. YACL explicitly resets the pending value upon applying options. Could you send your binding code?

Giggitybyte commented 1 year ago

My full implementation is here.

isXander commented 1 year ago

Have you considered using YACL's config API rather than your own? It may fix your issues.

Giggitybyte commented 1 year ago

Wasn't aware of it, but I want to stick with what I made. I don't understand how that'd affect anything anyways; the source of the config value should not cause issues like this.

isXander commented 1 year ago

When you click 'Apply Value', two things happen:

  1. The values stored in the options are passed to your binding setter
  2. The stored value in the options is set to the binding getter

The problem lies in step number 2. Your config doesn't seem to update instantly and the binding getter is still the old value.

Giggitybyte commented 1 year ago

My config does update instantly as you can see in my video above.

It is stored in memory as a JsonObject (from gson) which is essentially just a hashmap; those values are updated as soon as YACL invokes my lambda. YACL also calls the method which saves my config and writes the updated values which were in memory. The screen created by YACL simply resets to the original value that it had when it was first opened no matter how many times you change the value and reapply it.

I see the changes to my config in memory through my debugger, and I see the changes written to my JSON file. This problem is not on my end.

Giggitybyte commented 1 year ago

Frustrated over this issue I decided to debug this further and understand why the binding was always returning the old value when I clearly see it set the new value, and I couldn't for the life of me figure out where the hell it was getting that value from. On a whim, I decided to swap out the method reference that I've been providing for each binding getter with a lambda; it now works exactly as intended.

My question is: why? That was the only thing I changed in the whole setup. Why does this make a difference?

isXander commented 1 year ago

No idea.

Giggitybyte commented 1 year ago

Might want to add a note in the documentation about this.

isXander commented 1 year ago

I added a warning log to let developers know something is going wrong in the aforementioned step 2.