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

Minor modloader adjustments

This commit is contained in:
tobspr 2022-01-16 17:35:21 +01:00
parent 8ad1c1bf9d
commit 9717463500

View File

@ -84,13 +84,6 @@ export class ModLoader {
this.exposeExports();
window.$shapez_registerMod = (modClass, meta) => {
this.modLoadQueue.push({
modClass,
meta,
});
};
if (G_IS_STANDALONE || G_IS_DEV) {
try {
let mods = [];
@ -115,18 +108,42 @@ export class ModLoader {
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 => {
modCode += `
if (typeof Mod !== 'undefined') {
if (typeof METADATA !== 'object') {
throw new Error("No METADATA variable found");
}
window.$shapez_registerMod(Mod, METADATA);
}
`;
try {
modCode += "\n;window.$shapez_registerMod(Mod, METADATA);";
const func = new Function(modCode);
func();
} catch (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) {
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);
} catch (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 = [];
delete window.$shapez_registerMod;
}
}