mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-14 02:31:51 +00:00
Expose all exported members automatically to mods
This commit is contained in:
parent
bc5eff84f6
commit
a6b024be25
@ -2,8 +2,8 @@
|
|||||||
import { Entity } from "../game/entity";
|
import { Entity } from "../game/entity";
|
||||||
/* typehints:end */
|
/* typehints:end */
|
||||||
|
|
||||||
export default function ({ Mod, MetaBuilding }) {
|
export default function (shapez) {
|
||||||
class MetaDemoModBuilding extends MetaBuilding {
|
class MetaDemoModBuilding extends shapez.MetaBuilding {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("demoModBuilding");
|
super("demoModBuilding");
|
||||||
}
|
}
|
||||||
@ -19,7 +19,7 @@ export default function ({ Mod, MetaBuilding }) {
|
|||||||
setupEntityComponents(entity) {}
|
setupEntityComponents(entity) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
return class ModImpl extends Mod {
|
return class ModImpl extends shapez.Mod {
|
||||||
constructor(app, modLoader) {
|
constructor(app, modLoader) {
|
||||||
super(
|
super(
|
||||||
app,
|
app,
|
||||||
|
|||||||
@ -31,12 +31,37 @@ export class ModLoader {
|
|||||||
|
|
||||||
initMods() {
|
initMods() {
|
||||||
LOG.log("hook:init");
|
LOG.log("hook:init");
|
||||||
|
|
||||||
|
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]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
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({
|
const mod = new (modClass(exports))(this.app, this);
|
||||||
Mod,
|
|
||||||
MetaBuilding,
|
|
||||||
}))(this.app, this);
|
|
||||||
mod.init();
|
mod.init();
|
||||||
this.mods.push(mod);
|
this.mods.push(mod);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user