diff --git a/src/data/backwardsCompatibility/backwardsCompatibility.js b/src/data/backwardsCompatibility/backwardsCompatibility.js index 6d870b3f7e9c33321f3528ee3f531fb460ba69d9..3eb0251be825d75d3e08964f423acf58b7abff69 100644 --- a/src/data/backwardsCompatibility/backwardsCompatibility.js +++ b/src/data/backwardsCompatibility/backwardsCompatibility.js @@ -105,6 +105,7 @@ App.Update.backwardsCompatibility = function() { div.append(`Cleaning up... `); jQuery('#backwardsCompatibility').append(div); App.Update.cleanUp(div); + App.UI.SlaveSummary.settingsChanged(); } catch (error) { div = document.createElement('p'); div.className = "red"; @@ -113,7 +114,6 @@ App.Update.backwardsCompatibility = function() { State.restore(); throw (error); // rethrow the exception to Sugarcube so we get a fancy stack trace } - return; }; App.Update.globalVariables = function(node) { diff --git a/src/data/onLoad.js b/src/data/onLoad.js deleted file mode 100644 index 349c62cad99c864af3de06bcd6c5b18927c90eb3..0000000000000000000000000000000000000000 --- a/src/data/onLoad.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * - * @param {object} save - */ -Config.saves.onLoad = function(save) { - // get the old State.variables for easier access. - const V = save.state.history[0].variables; - - App.UI.Theme.onLoad(V); -}; diff --git a/src/js/eventHandlers.js b/src/js/eventHandlers.js index 4099ad52566ebc2354161abf905e45bb84717516..4e3a7fc73e4e128f3d3566970828a0492aa020ef 100644 --- a/src/js/eventHandlers.js +++ b/src/js/eventHandlers.js @@ -3,6 +3,18 @@ App.EventHandlers = function() { * @param {SugarCubeLib.SaveObject} save */ function onLoad(save) { + const v = save.state.history[0].variables; + if (v.releaseID > App.Version.release) { + console.error("Save game version problem. Loaded : " + v.releaseID + ", above expected:" + App.Version.release); // eslint-disable-line no-console + throw new Error("The save you're attempting to load was created with the game version newer than one you are running. Please download the latest game version."); + } + // updating settings only for the same releaseID, otherwise user will run + // backwards compatibility and we update settings from there + if (v.releaseID === App.Version.release) { + App.UI.SlaveSummary.settingsChanged(v); + } + + App.UI.Theme.onLoad(v); } /** @@ -15,6 +27,7 @@ App.EventHandlers = function() { } function optionsChanged() { + App.UI.SlaveSummary.settingsChanged(); } return { diff --git a/src/js/slaveSummaryWidgets.js b/src/js/slaveSummaryWidgets.js index 567cbff12cbf566eab50a4fb7d241a4fc85d9c52..8e9a75273c48d521b8a49ea63f21053c8065b5e0 100644 --- a/src/js/slaveSummaryWidgets.js +++ b/src/js/slaveSummaryWidgets.js @@ -879,6 +879,12 @@ App.UI.SlaveSummary = function() { } } + function settingsChanged(newState) { + const newStateIsOK = newState && newState.hasOwnProperty("UI") && newState.UI.hasOwnProperty("slaveSummary"); + const settingsObj = newStateIsOK ? newState.UI.slaveSummary : V.UI.slaveSummary; + initDelegates(settingsObj); + } + /** * @param {App.Entity.SlaveState} slave * @returns {DocumentFragment} @@ -886,8 +892,6 @@ App.UI.SlaveSummary = function() { function render(slave) { /** @type {App.UI.SlaveSummary.AbbreviationState} */ const abbrSettings = V.UI.slaveSummary.abbreviation; - initDelegates(); // temporary - const helpers = App.UI.SlaveSummaryImpl.helpers; const res = document.createDocumentFragment(); @@ -984,7 +988,7 @@ App.UI.SlaveSummary = function() { return { makeNewState: makeNewState, - initDelegates: initDelegates, + settingsChanged: settingsChanged, empty: function() { }, render: render, displayOptionsFragment: displayOptionsFragment diff --git a/src/zz1-last/setupEventHandlers.js b/src/zz1-last/setupEventHandlers.js index 9a41b2959c9a850010c0079626bf5252ab8ae5ee..190756ccced5b1ba246a99d25876336893d5d9dc 100644 --- a/src/zz1-last/setupEventHandlers.js +++ b/src/zz1-last/setupEventHandlers.js @@ -5,3 +5,7 @@ Config.saves.onSave = App.EventHandlers.onSave; $(document).on(':storyready', function(ev) { App.EventHandlers.storyReady(); }); + +$(document).one(':passagestart', function() { + App.EventHandlers.optionsChanged(); +});