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:
parent
bc5eff84f6
commit
a6b024be25
@ -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,
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user