diff --git a/src/js/application.js b/src/js/application.js index 71115f54..b61eb923 100644 --- a/src/js/application.js +++ b/src/js/application.js @@ -54,21 +54,21 @@ export class Application { this.unloaded = false; + // Platform stuff + this.storage = new Storage(this); + this.platformWrapper = new PlatformWrapperImplElectron(this); + // Global stuff - this.settings = new ApplicationSettings(this); + this.settings = new ApplicationSettings(this, this.storage); this.ticker = new AnimationFrame(); this.stateMgr = new StateManager(this); - this.savegameMgr = new SavegameManager(this); + // NOTE: SavegameManager uses the passed storage, but savegames always + // use Application#storage + this.savegameMgr = new SavegameManager(this, this.storage); this.inputMgr = new InputDistributor(this); this.backgroundResourceLoader = new BackgroundResourcesLoader(this); this.clientApi = new ClientAPI(this); - // Platform dependent stuff - - this.storage = new Storage(this); - - this.platformWrapper = new PlatformWrapperImplElectron(this); - this.sound = new Sound(this); // Track if the window is focused (only relevant for browser) diff --git a/src/js/core/read_write_proxy.js b/src/js/core/read_write_proxy.js index 949eb802..a7f03d52 100644 --- a/src/js/core/read_write_proxy.js +++ b/src/js/core/read_write_proxy.js @@ -1,5 +1,5 @@ /* typehints:start */ -import { Application } from "../application"; +import { Storage } from "@/platform/storage"; /* typehints:end */ import { FsError } from "@/platform/fs_error"; @@ -18,9 +18,9 @@ const salt = globalConfig.info.file; // Helper which only writes / reads if verify() works. Also performs migration export class ReadWriteProxy { - constructor(app, filename) { - /** @type {Application} */ - this.app = app; + constructor(storage, filename) { + /** @type {Storage} */ + this.storage = storage; this.filename = filename; @@ -143,7 +143,7 @@ export class ReadWriteProxy { return asyncCompressor .compressObjectAsync(this.currentData) .then(compressed => { - return this.app.storage.writeFileAsync(this.filename, compressed); + return this.storage.writeFileAsync(this.filename, compressed); }) .then(() => { logger.log("📄 Wrote", this.filename); @@ -158,7 +158,7 @@ export class ReadWriteProxy { readAsync() { // Start read request return ( - this.app.storage + this.storage .readFileAsync(this.filename) // Check for errors during read @@ -297,7 +297,7 @@ export class ReadWriteProxy { * @returns {Promise} */ deleteAsync() { - return this.app.storage.deleteFileAsync(this.filename); + return this.storage.deleteFileAsync(this.filename); } // Internal diff --git a/src/js/profile/application_settings.js b/src/js/profile/application_settings.js index b454c163..22133d00 100644 --- a/src/js/profile/application_settings.js +++ b/src/js/profile/application_settings.js @@ -2,13 +2,13 @@ import { Application } from "../application"; /* typehints:end */ -import { ReadWriteProxy } from "../core/read_write_proxy"; -import { BoolSetting, EnumSetting, RangeSetting, BaseSetting } from "./setting_types"; -import { createLogger } from "../core/logging"; import { ExplainedResult } from "../core/explained_result"; +import { createLogger } from "../core/logging"; +import { ReadWriteProxy } from "../core/read_write_proxy"; import { THEMES, applyGameTheme } from "../game/theme"; -import { T } from "../translations"; import { LANGUAGES } from "../languages"; +import { T } from "../translations"; +import { BaseSetting, BoolSetting, EnumSetting, RangeSetting } from "./setting_types"; const logger = createLogger("application_settings"); @@ -330,8 +330,11 @@ class SettingsStorage { } export class ApplicationSettings extends ReadWriteProxy { - constructor(app) { - super(app, "app_settings.bin"); + constructor(app, storage) { + super(storage, "app_settings.bin"); + + /** @type {Application} */ + this.app = app; this.settingHandles = initializeSettings(); } diff --git a/src/js/savegame/savegame.js b/src/js/savegame/savegame.js index d93c5997..b4054553 100644 --- a/src/js/savegame/savegame.js +++ b/src/js/savegame/savegame.js @@ -36,7 +36,11 @@ export class Savegame extends ReadWriteProxy { * @param {SavegameMetadata} param0.metaDataRef Handle to the meta data */ constructor(app, { internalId, metaDataRef }) { - super(app, "savegame-" + internalId + ".bin"); + super(app.storage, "savegame-" + internalId + ".bin"); + + /** @type {Application} */ + this.app = app; + this.internalId = internalId; this.metaDataRef = metaDataRef; diff --git a/src/js/savegame/savegame_manager.js b/src/js/savegame/savegame_manager.js index b70bd851..6ad3b98a 100644 --- a/src/js/savegame/savegame_manager.js +++ b/src/js/savegame/savegame_manager.js @@ -1,3 +1,7 @@ +/* typehints:start */ +import { Application } from "@/application"; +/* typehints:end */ + import { globalConfig } from "../core/config"; import { ExplainedResult } from "../core/explained_result"; import { createLogger } from "../core/logging"; @@ -17,8 +21,11 @@ export const enumLocalSavegameStatus = { }; export class SavegameManager extends ReadWriteProxy { - constructor(app) { - super(app, "savegames.bin"); + constructor(app, storage) { + super(storage, "savegames.bin"); + + /** @type {Application} */ + this.app = app; this.currentData = this.getDefaultData(); }