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

Expose all exported members automatically to mods

This commit is contained in:
tobspr 2022-01-14 07:51:48 +01:00
parent bc5eff84f6
commit a6b024be25
2 changed files with 32 additions and 7 deletions

View File

@ -2,8 +2,8 @@
import { Entity } from "../game/entity";
/* typehints:end */
export default function ({ Mod, MetaBuilding }) {
class MetaDemoModBuilding extends MetaBuilding {
export default function (shapez) {
class MetaDemoModBuilding extends shapez.MetaBuilding {
constructor() {
super("demoModBuilding");
}
@ -19,7 +19,7 @@ export default function ({ Mod, MetaBuilding }) {
setupEntityComponents(entity) {}
}
return class ModImpl extends Mod {
return class ModImpl extends shapez.Mod {
constructor(app, modLoader) {
super(
app,

View File

@ -31,12 +31,37 @@ export class ModLoader {
initMods() {
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.modLoadQueue.forEach(modClass => {
const mod = new (modClass({
Mod,
MetaBuilding,
}))(this.app, this);
const mod = new (modClass(exports))(this.app, this);
mod.init();
this.mods.push(mod);
});