1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Changed some modloading

This commit is contained in:
DJ1TJOO 2021-05-11 14:57:50 +02:00
parent 433ffd3388
commit f2c3b0e18c
3 changed files with 28 additions and 38 deletions

View File

@ -102,15 +102,20 @@ window.onload = async () => {
} else if (!G_IS_DEV) {
user = JSON.parse(localStorage.getItem("user"));
instance = JSON.parse(localStorage.getItem("instance"));
// instance = {
// mods: [{
// url: "http://mods.thomasbrants.nl/static/mods/b89404ac-7cbc-45bf-81b7-7d4d8108faf0/1.0.0.js",
// id: "b89404ac-7cbc-45bf-81b7-7d4d8108faf0",
// config: {},
// settings: {},
// }, ],
// };
}
// else {
// instance = {
// mods: [
// {
// url:
// "http://mods.thomasbrants.nl/static/mods/a18121cf-fc7c-4f23-906d-b7ab0512bbc8/1.0.0.js",
// id: "a18121cf-fc7c-4f23-906d-b7ab0512bbc8",
// config: {},
// settings: {},
// },
// ],
// };
// }
var modMgr = new ModManager(user, instance);
addVanillaBuildingsToAPI();
addVanillaComponentsToAPI();
@ -124,7 +129,8 @@ window.onload = async () => {
if (mod.split(".").pop() !== "js") continue;
modMgr.addMod(mod, true);
}
} else if (modMgr.modPack) await modMgr.addModPackMods();
}
if (modMgr.modPack) await modMgr.addModPackMods();
modMgr.loadMods();
initDrawUtils();
@ -133,12 +139,9 @@ window.onload = async () => {
initMetaBuildingRegistry();
initGameSpeedRegistry();
let app = null;
function bootApp() {
logger.log("Page Loaded");
app = new Application();
app.boot();
new Application().boot();
}
bootApp();
};

View File

@ -789,6 +789,9 @@ export class ShapezAPI {
PreloadState,
MobileWarningState,
//Hub goals
HubGoals,
//Systems
ItemAcceptorSystem,
BeltSystem,
@ -870,14 +873,11 @@ export class ShapezAPI {
buildings: {},
components: {},
hudParts: {},
//Must be array because of update order
systems: [],
systems: [], //Must be array because of update order
items: {},
gamemodes: {},
gamespeed: {},
//List of layer names
layers: [],
hub_goals: HubGoals,
layers: [], //List of layer names
};
this.toolbars = {
@ -986,8 +986,8 @@ export class ShapezAPI {
*/
registerIcon(id, iconDataURL) {
var css = ``;
var style = undefined;
if (!(style = document.getElementById("mod-loader-icons"))) {
var style = document.getElementById("mod-loader-icons");
if (!style) {
var head = document.head || document.getElementsByTagName("head")[0];
style = document.createElement("style");
style.id = "mod-loader-icons";
@ -1008,19 +1008,4 @@ export class ShapezAPI {
this.registerIcon("building_icons/" + id, iconDataURL);
this.KEYMAPPINGS.buildings[id] = { keyCode: this.KEYMAPPINGS.key(key), id: id };
}
/**
* Tracks clicks on a element (e.g. button). Useful because you should both support
* touch and mouse events.
* @param {HTMLElement} element
* @param {function} clickHandler
*/
trackClicks(element, clickHandler) {
const clickDetector = new ClickDetector(element, {
consumeEvents: true,
preventDefault: true,
});
clickDetector.click.add(clickHandler);
this.clickDetectors.push(clickDetector);
}
}

View File

@ -166,9 +166,11 @@ export class ModManager {
let promise = Promise.resolve(null);
for (let i = 0; i < this.modPack.mods.length; i++) {
promise = promise.then(() => {
return this.addMod(this.modPack.mods[i].url);
});
if (this.modPack.mods[i].url) {
promise = promise.then(() => {
return this.addMod(this.modPack.mods[i].url);
});
}
}
return promise;
}