mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-14 02:31:51 +00:00
Minor modloader adjustments
This commit is contained in:
parent
8ad1c1bf9d
commit
9717463500
@ -84,13 +84,6 @@ export class ModLoader {
|
|||||||
|
|
||||||
this.exposeExports();
|
this.exposeExports();
|
||||||
|
|
||||||
window.$shapez_registerMod = (modClass, meta) => {
|
|
||||||
this.modLoadQueue.push({
|
|
||||||
modClass,
|
|
||||||
meta,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
if (G_IS_STANDALONE || G_IS_DEV) {
|
if (G_IS_STANDALONE || G_IS_DEV) {
|
||||||
try {
|
try {
|
||||||
let mods = [];
|
let mods = [];
|
||||||
@ -115,18 +108,42 @@ export class ModLoader {
|
|||||||
mods.push(await response.text());
|
mods.push(await response.text());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.$shapez_registerMod = (modClass, meta) => {
|
||||||
|
if (this.modLoadQueue.some(entry => entry.meta.id === meta.id)) {
|
||||||
|
console.warn(
|
||||||
|
"Not registering mod",
|
||||||
|
meta,
|
||||||
|
"since a mod with the same id is already loaded"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.modLoadQueue.push({
|
||||||
|
modClass,
|
||||||
|
meta,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
mods.forEach(modCode => {
|
mods.forEach(modCode => {
|
||||||
|
modCode += `
|
||||||
|
if (typeof Mod !== 'undefined') {
|
||||||
|
if (typeof METADATA !== 'object') {
|
||||||
|
throw new Error("No METADATA variable found");
|
||||||
|
}
|
||||||
|
window.$shapez_registerMod(Mod, METADATA);
|
||||||
|
}
|
||||||
|
`;
|
||||||
try {
|
try {
|
||||||
modCode += "\n;window.$shapez_registerMod(Mod, METADATA);";
|
|
||||||
const func = new Function(modCode);
|
const func = new Function(modCode);
|
||||||
func();
|
func();
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(ex);
|
console.error(ex);
|
||||||
alert("Failed to parse mod (launch with --dev for more info): " + ex);
|
alert("Failed to parse mod (launch with --dev for more info): \n\n" + ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
delete window.$shapez_registerMod;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
alert("Failed to load mods (launch with --dev for more info): " + ex);
|
alert("Failed to load mods (launch with --dev for more info): \n\n" + ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,12 +155,10 @@ export class ModLoader {
|
|||||||
this.mods.push(mod);
|
this.mods.push(mod);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(ex);
|
console.error(ex);
|
||||||
alert("Failed to initialize mods (launch with --dev for more info): " + ex);
|
alert("Failed to initialize mods (launch with --dev for more info): \n\n" + ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.modLoadQueue = [];
|
this.modLoadQueue = [];
|
||||||
|
|
||||||
delete window.$shapez_registerMod;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user