mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-14 02:31:51 +00:00
Make shapez exports global
This commit is contained in:
parent
2d3219373f
commit
e12ed11c3e
4
src/js/globals.d.ts
vendored
4
src/js/globals.d.ts
vendored
@ -22,6 +22,8 @@ declare const G_IS_RELEASE: boolean;
|
|||||||
declare const G_CHINA_VERSION: boolean;
|
declare const G_CHINA_VERSION: boolean;
|
||||||
declare const G_WEGAME_VERSION: boolean;
|
declare const G_WEGAME_VERSION: boolean;
|
||||||
|
|
||||||
|
declare const shapez: any;
|
||||||
|
|
||||||
// Polyfills
|
// Polyfills
|
||||||
declare interface String {
|
declare interface String {
|
||||||
replaceAll(search: string, replacement: string): string;
|
replaceAll(search: string, replacement: string): string;
|
||||||
@ -95,6 +97,8 @@ declare interface Window {
|
|||||||
registerMod: any;
|
registerMod: any;
|
||||||
anyModLoaded: any;
|
anyModLoaded: any;
|
||||||
|
|
||||||
|
shapez: any;
|
||||||
|
|
||||||
webkitRequestAnimationFrame();
|
webkitRequestAnimationFrame();
|
||||||
|
|
||||||
assert(condition: boolean, failureMessage: string);
|
assert(condition: boolean, failureMessage: string);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
registerMod(shapez => {
|
registerMod(() => {
|
||||||
class DemoModComponent extends shapez.Component {
|
class DemoModComponent extends shapez.Component {
|
||||||
static getId() {
|
static getId() {
|
||||||
return "DemoMod";
|
return "DemoMod";
|
||||||
|
|||||||
@ -41,9 +41,41 @@ export class ModLoader {
|
|||||||
return this.mods.length > 0;
|
return this.mods.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exposeExports() {
|
||||||
|
if (G_IS_DEV || G_IS_STANDALONE) {
|
||||||
|
let exports = {};
|
||||||
|
const modules = require.context("../", true, /\.js$/);
|
||||||
|
|
||||||
|
Array.from(modules.keys()).forEach(key => {
|
||||||
|
// @ts-ignore
|
||||||
|
const module = modules(key);
|
||||||
|
for (const member in module) {
|
||||||
|
if (member === "default") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (exports[member]) {
|
||||||
|
throw new Error("Duplicate export of " + member);
|
||||||
|
}
|
||||||
|
Object.defineProperty(exports, member, {
|
||||||
|
get() {
|
||||||
|
return module[member];
|
||||||
|
},
|
||||||
|
set(v) {
|
||||||
|
module[member] = v;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.shapez = exports;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async initMods() {
|
async initMods() {
|
||||||
LOG.log("hook:init");
|
LOG.log("hook:init");
|
||||||
|
|
||||||
|
this.exposeExports();
|
||||||
|
|
||||||
if (G_IS_STANDALONE || G_IS_DEV) {
|
if (G_IS_STANDALONE || G_IS_DEV) {
|
||||||
try {
|
try {
|
||||||
let mods = [];
|
let mods = [];
|
||||||
@ -71,36 +103,9 @@ export class ModLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let exports = {};
|
|
||||||
|
|
||||||
if (G_IS_DEV || G_IS_STANDALONE) {
|
|
||||||
const modules = require.context("../", true, /\.js$/);
|
|
||||||
|
|
||||||
Array.from(modules.keys()).forEach(key => {
|
|
||||||
// @ts-ignore
|
|
||||||
const module = modules(key);
|
|
||||||
for (const member in module) {
|
|
||||||
if (member === "default") {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (exports[member]) {
|
|
||||||
throw new Error("Duplicate export of " + member);
|
|
||||||
}
|
|
||||||
Object.defineProperty(exports, member, {
|
|
||||||
get() {
|
|
||||||
return module[member];
|
|
||||||
},
|
|
||||||
set(v) {
|
|
||||||
module[member] = v;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
this.modLoadQueue.forEach(modClass => {
|
this.modLoadQueue.forEach(modClass => {
|
||||||
const mod = new (modClass(exports))(this.app, this);
|
const mod = new (modClass())(this.app, this);
|
||||||
mod.init();
|
mod.init();
|
||||||
this.mods.push(mod);
|
this.mods.push(mod);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user