YetAnotherConfigLib

YetAnotherConfigLib

13M Downloads

`OptionImpl.BuilderImpl#instant` prevents saving

LucunJi opened this issue ยท 1 comments

commented
  • Mod version: 3.5.0+1.21-fabric

How to reproduce

As the title says, it simply prevents saving in all cases.

Analysis

Case 1: the common scenario

  1. After OptionImpl#requestSet: binding().getValue() and pendingValue differs; also calls OptionImpl#triggerListeners
  2. After OptionImpl#applyValue: binding().getValue() and pendingValue becomes the same
  3. After YACLScreen#onOptionChanged: pendingChanges is false

Now the configs won't be the saved since the pendingChanges is false. BROKEN.

Case 2: intentionally swap step 2 and 3, it won't be fixed

  1. After OptionImpl#requestSet: binding().getValue() and pendingValue differs; also calls OptionImpl#triggerListeners
  2. After YACLScreen#onOptionChanged: pendingChanges is true
  3. After OptionImpl#applyValue: binding().getValue() and pendingValue becomes the same

It looks fine, but what if we are pressing the Reset button, and the last option hasn't been changed?

  1. After OptionImpl#requestSet: binding().getValue() and pendingValue are still the same
  2. After YACLScreen#onOptionChanged: pendingChanges is false
  3. After OptionImpl#applyValue: binding().getValue() and pendingValue are still the same

Now the configs won't be the saved since the pendingChanges is false. BROKEN.

How to fix it

Keep track of the initial value, use a "dirty" flag, etc.

commented

A potential patch is proposed here (I used mixins in my project)