diff --git a/js/003-data/gameVariableData.js b/js/003-data/gameVariableData.js index eb73d75d03353fa4a9719c904ca072a0c8b0a256..541af5e3460e4df92223019a98d5933b50800bdc 100644 --- a/js/003-data/gameVariableData.js +++ b/js/003-data/gameVariableData.js @@ -164,6 +164,7 @@ App.Data.defaultGameStateVariables = { useTabs: 0, verboseDescriptions: 0, verticalizeArcologyLinks: 0, + theme: 0, weightAffectsAssets: 1, curativeSideEffects: 1, disableTiredness: 1, diff --git a/src/data/onLoad.js b/src/data/onLoad.js new file mode 100644 index 0000000000000000000000000000000000000000..349c62cad99c864af3de06bcd6c5b18927c90eb3 --- /dev/null +++ b/src/data/onLoad.js @@ -0,0 +1,10 @@ +/** + * + * @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/gui/theming.js b/src/gui/theming.js index 706d870670d1cd985d12afe51305b677c3cbb430..ac274203c91faaa2fae39e7ccfda123e353874bb 100644 --- a/src/gui/theming.js +++ b/src/gui/theming.js @@ -1,13 +1,14 @@ App.UI.Theme = (function() { - // NOTE: Due to browser limitations it is not possible to retrieve the path of selected files. We therefor expect - // all files to be located in the same directory as the HTML file. Selected files from somewhere else will simply - // not be loaded. + // NOTE: Due to browser limitations it is not possible to retrieve the path of selected files, only the filename. + // We therefore expect all files to be located in the same directory as the HTML file. Selected files from somewhere + // else will simply not be loaded or if a file in the correct place has the same name, it will be loaded instead. let currentThemeElement = null; let devTheme = null; return { selector: selector, - devTheme: reloadDevTheme + devTheme: reloadDevTheme, + onLoad: onLoad }; /** @@ -36,6 +37,8 @@ App.UI.Theme = (function() { * @param {string} filename or filepath relative to the HTML file. */ function load(filename) { + V.theme = filename; + currentThemeElement = document.createElement("link"); currentThemeElement.setAttribute("rel", "stylesheet"); currentThemeElement.setAttribute("type", "text/css"); @@ -48,6 +51,7 @@ App.UI.Theme = (function() { if (currentThemeElement !== null) { document.head.removeChild(currentThemeElement); currentThemeElement = null; + V.theme = 0; } } @@ -70,4 +74,13 @@ App.UI.Theme = (function() { document.head.appendChild(devTheme); } } + + /** + * @param {object} V + */ + function onLoad(V) { + if (V.theme !== 0) { + load(V.theme); + } + } })();