mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-11 09:11:50 +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:
parent
412221c4b8
commit
c4e9d417b3
@ -1,7 +1,7 @@
|
|||||||
import { AnimationFrame } from "./core/animation_frame";
|
import { AnimationFrame } from "./core/animation_frame";
|
||||||
import { BackgroundResourcesLoader } from "./core/background_resources_loader";
|
import { BackgroundResourcesLoader } from "./core/background_resources_loader";
|
||||||
import { GameState } from "./core/game_state";
|
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 { InputDistributor } from "./core/input_distributor";
|
||||||
import { Loader } from "./core/loader";
|
import { Loader } from "./core/loader";
|
||||||
import { createLogger } from "./core/logging";
|
import { createLogger } from "./core/logging";
|
||||||
@ -41,10 +41,8 @@ export class Application {
|
|||||||
async boot() {
|
async boot() {
|
||||||
console.log("Booting ...");
|
console.log("Booting ...");
|
||||||
|
|
||||||
assert(!GLOBAL_APP, "Tried to construct application twice");
|
|
||||||
logger.log("Creating application, platform =", getPlatformName());
|
logger.log("Creating application, platform =", getPlatformName());
|
||||||
setGlobalApp(this);
|
setGlobalApp(this);
|
||||||
MODS.app = this;
|
|
||||||
|
|
||||||
// MODS
|
// MODS
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ export let GLOBAL_APP = null;
|
|||||||
* @param {Application} app
|
* @param {Application} app
|
||||||
*/
|
*/
|
||||||
export function setGlobalApp(app) {
|
export function setGlobalApp(app) {
|
||||||
assert(!GLOBAL_APP, "Create application twice!");
|
assert(!GLOBAL_APP, "Tried to set GLOBAL_APP twice");
|
||||||
GLOBAL_APP = app;
|
GLOBAL_APP = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,3 @@
|
|||||||
/* typehints:start */
|
|
||||||
import { Application } from "../application";
|
|
||||||
/* typehints:end */
|
|
||||||
import { FsError } from "@/platform/fs_error";
|
import { FsError } from "@/platform/fs_error";
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
@ -9,6 +6,7 @@ import { Mod } from "./mod";
|
|||||||
import { ModInterface } from "./mod_interface";
|
import { ModInterface } from "./mod_interface";
|
||||||
import { MOD_SIGNALS } from "./mod_signals";
|
import { MOD_SIGNALS } from "./mod_signals";
|
||||||
|
|
||||||
|
import { GLOBAL_APP } from "@/core/globals";
|
||||||
import semverSatisifies from "semver/functions/satisfies";
|
import semverSatisifies from "semver/functions/satisfies";
|
||||||
import semverValidRange from "semver/ranges/valid";
|
import semverValidRange from "semver/ranges/valid";
|
||||||
|
|
||||||
@ -32,11 +30,6 @@ export class ModLoader {
|
|||||||
constructor() {
|
constructor() {
|
||||||
LOG.log("modloader created");
|
LOG.log("modloader created");
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {Application}
|
|
||||||
*/
|
|
||||||
this.app = undefined;
|
|
||||||
|
|
||||||
/** @type {Mod[]} */
|
/** @type {Mod[]} */
|
||||||
this.mods = [];
|
this.mods = [];
|
||||||
|
|
||||||
@ -50,8 +43,8 @@ export class ModLoader {
|
|||||||
this.signals = MOD_SIGNALS;
|
this.signals = MOD_SIGNALS;
|
||||||
}
|
}
|
||||||
|
|
||||||
linkApp(app) {
|
get app() {
|
||||||
this.app = app;
|
return GLOBAL_APP;
|
||||||
}
|
}
|
||||||
|
|
||||||
anyModsActive() {
|
anyModsActive() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user