Skip to content

Commit 23a9e7f

Browse files
Merge pull request #4881 from Lasercar/fix-preferences-not-saving-due-to-enums-AGAIN
[BIGFIX] Fix Options not loading from Save Data
2 parents 8f2a8c8 + 3a1b573 commit 23a9e7f

3 files changed

Lines changed: 42 additions & 13 deletions

File tree

source/Main.hx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,6 @@ class Main extends Sprite
6262

6363
function init(?event:Event):Void
6464
{
65-
#if web
66-
// set this variable (which is a function) from the lime version at lime/_internal/backend/html5/HTML5Application.hx
67-
// The framerate cap will more thoroughly initialize via Preferences in InitState.hx
68-
funkin.Preferences.lockedFramerateFunction = untyped js.Syntax.code("window.requestAnimationFrame");
69-
#end
70-
71-
WindowUtil.setVSyncMode(funkin.Preferences.vsyncMode);
72-
7365
if (hasEventListener(Event.ADDED_TO_STAGE))
7466
{
7567
removeEventListener(Event.ADDED_TO_STAGE, init);
@@ -107,6 +99,17 @@ class Main extends Sprite
10799

108100
// George recommends binding the save before FlxGame is created.
109101
Save.load();
102+
103+
// Don't call anything from the preferences until the save is loaded!
104+
#if web
105+
// set this variable (which is a function) from the lime version at lime/_internal/backend/html5/HTML5Application.hx
106+
// The framerate cap will more thoroughly initialize via Preferences in InitState.hx
107+
funkin.Preferences.lockedFramerateFunction = untyped js.Syntax.code("window.requestAnimationFrame");
108+
#end
109+
110+
WindowUtil.setVSyncMode(funkin.Preferences.vsyncMode);
111+
112+
110113
var game:FlxGame = new FlxGame(gameWidth, gameHeight, initialState, Preferences.framerate, Preferences.framerate, skipSplash, startFullscreen);
111114

112115
// FlxG.game._customSoundTray wants just the class, it calls new from

source/funkin/Preferences.hx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,41 @@ class Preferences
185185

186186
static function get_vsyncMode():lime.ui.WindowVSyncMode
187187
{
188-
return Save?.instance?.options?.vsyncMode ?? lime.ui.WindowVSyncMode.OFF;
188+
var value = Save?.instance?.options?.vsyncMode ?? "Off";
189+
190+
return switch (value)
191+
{
192+
case "Off":
193+
lime.ui.WindowVSyncMode.OFF;
194+
case "On":
195+
lime.ui.WindowVSyncMode.ON;
196+
case "Adaptive":
197+
lime.ui.WindowVSyncMode.ADAPTIVE;
198+
default:
199+
lime.ui.WindowVSyncMode.OFF;
200+
};
189201
}
190202

191203
static function set_vsyncMode(value:lime.ui.WindowVSyncMode):lime.ui.WindowVSyncMode
192204
{
205+
var string;
206+
207+
switch (value)
208+
{
209+
case lime.ui.WindowVSyncMode.OFF:
210+
string = "Off";
211+
case lime.ui.WindowVSyncMode.ON:
212+
string = "On";
213+
case lime.ui.WindowVSyncMode.ADAPTIVE:
214+
string = "Adaptive";
215+
default:
216+
string = "Off";
217+
};
218+
193219
WindowUtil.setVSyncMode(value);
194220

195221
var save:Save = Save.instance;
196-
save.options.vsyncMode = value;
222+
save.options.vsyncMode = string;
197223
save.flush();
198224
return value;
199225
}

source/funkin/save/Save.hx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class Save
115115
zoomCamera: true,
116116
debugDisplay: false,
117117
autoPause: true,
118-
vsyncMode: lime.ui.WindowVSyncMode.OFF,
118+
vsyncMode: 'Off',
119119
strumlineBackgroundOpacity: 0,
120120
autoFullscreen: false,
121121
inputOffset: 0,
@@ -1401,9 +1401,9 @@ typedef SaveDataOptions =
14011401

14021402
/**
14031403
* If enabled, the game will utilize VSync (or adaptive VSync) on startup.
1404-
* @default `OFF`
1404+
* @default `Off`
14051405
*/
1406-
var vsyncMode:lime.ui.WindowVSyncMode;
1406+
var vsyncMode:String;
14071407

14081408
/**
14091409
* If >0, the game will display a semi-opaque background under the notes.

0 commit comments

Comments
 (0)