1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-09 16:21:51 +00:00

Re-use global app variable in ModLoader

The linkApp method is removed as it was unused. A getter is used to
ensure best development experience. It can be further improved by adding
a guard for cases where GLOBAL_APP is not set yet.
This commit is contained in:
Даниїл Григор'єв 2025-04-08 03:02:52 +03:00
parent 412221c4b8
commit c4e9d417b3
No known key found for this signature in database
GPG Key ID: B890DF16341D8C1D
3 changed files with 5 additions and 14 deletions

View File

@ -1,7 +1,7 @@
import { AnimationFrame } from "./core/animation_frame";
import { BackgroundResourcesLoader } from "./core/background_resources_loader";
import { GameState } from "./core/game_state";
import { GLOBAL_APP, setGlobalApp } from "./core/globals";
import { setGlobalApp } from "./core/globals";
import { InputDistributor } from "./core/input_distributor";
import { Loader } from "./core/loader";
import { createLogger } from "./core/logging";
@ -41,10 +41,8 @@ export class Application {
async boot() {
console.log("Booting ...");
assert(!GLOBAL_APP, "Tried to construct application twice");
logger.log("Creating application, platform =", getPlatformName());
setGlobalApp(this);
MODS.app = this;
// MODS

View File

@ -12,7 +12,7 @@ export let GLOBAL_APP = null;
* @param {Application} app
*/
export function setGlobalApp(app) {
assert(!GLOBAL_APP, "Create application twice!");
assert(!GLOBAL_APP, "Tried to set GLOBAL_APP twice");
GLOBAL_APP = app;
}

View File

@ -1,6 +1,3 @@
/* typehints:start */
import { Application } from "../application";
/* typehints:end */
import { FsError } from "@/platform/fs_error";
import { globalConfig } from "../core/config";
import { createLogger } from "../core/logging";
@ -9,6 +6,7 @@ import { Mod } from "./mod";
import { ModInterface } from "./mod_interface";
import { MOD_SIGNALS } from "./mod_signals";
import { GLOBAL_APP } from "@/core/globals";
import semverSatisifies from "semver/functions/satisfies";
import semverValidRange from "semver/ranges/valid";
@ -32,11 +30,6 @@ export class ModLoader {
constructor() {
LOG.log("modloader created");
/**
* @type {Application}
*/
this.app = undefined;
/** @type {Mod[]} */
this.mods = [];
@ -50,8 +43,8 @@ export class ModLoader {
this.signals = MOD_SIGNALS;
}
linkApp(app) {
this.app = app;
get app() {
return GLOBAL_APP;
}
anyModsActive() {