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) { } else if (!G_IS_DEV) {
user = JSON.parse(localStorage.getItem("user")); user = JSON.parse(localStorage.getItem("user"));
instance = JSON.parse(localStorage.getItem("instance")); 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); var modMgr = new ModManager(user, instance);
addVanillaBuildingsToAPI(); addVanillaBuildingsToAPI();
addVanillaComponentsToAPI(); addVanillaComponentsToAPI();
@ -124,7 +129,8 @@ window.onload = async () => {
if (mod.split(".").pop() !== "js") continue; if (mod.split(".").pop() !== "js") continue;
modMgr.addMod(mod, true); modMgr.addMod(mod, true);
} }
} else if (modMgr.modPack) await modMgr.addModPackMods(); }
if (modMgr.modPack) await modMgr.addModPackMods();
modMgr.loadMods(); modMgr.loadMods();
initDrawUtils(); initDrawUtils();
@ -133,12 +139,9 @@ window.onload = async () => {
initMetaBuildingRegistry(); initMetaBuildingRegistry();
initGameSpeedRegistry(); initGameSpeedRegistry();
let app = null;
function bootApp() { function bootApp() {
logger.log("Page Loaded"); logger.log("Page Loaded");
app = new Application(); new Application().boot();
app.boot();
} }
bootApp(); bootApp();
}; };

View File

@ -789,6 +789,9 @@ export class ShapezAPI {
PreloadState, PreloadState,
MobileWarningState, MobileWarningState,
//Hub goals
HubGoals,
//Systems //Systems
ItemAcceptorSystem, ItemAcceptorSystem,
BeltSystem, BeltSystem,
@ -870,14 +873,11 @@ export class ShapezAPI {
buildings: {}, buildings: {},
components: {}, components: {},
hudParts: {}, hudParts: {},
//Must be array because of update order systems: [], //Must be array because of update order
systems: [],
items: {}, items: {},
gamemodes: {}, gamemodes: {},
gamespeed: {}, gamespeed: {},
//List of layer names layers: [], //List of layer names
layers: [],
hub_goals: HubGoals,
}; };
this.toolbars = { this.toolbars = {
@ -986,8 +986,8 @@ export class ShapezAPI {
*/ */
registerIcon(id, iconDataURL) { registerIcon(id, iconDataURL) {
var css = ``; var css = ``;
var style = undefined; var style = document.getElementById("mod-loader-icons");
if (!(style = document.getElementById("mod-loader-icons"))) { if (!style) {
var head = document.head || document.getElementsByTagName("head")[0]; var head = document.head || document.getElementsByTagName("head")[0];
style = document.createElement("style"); style = document.createElement("style");
style.id = "mod-loader-icons"; style.id = "mod-loader-icons";
@ -1008,19 +1008,4 @@ export class ShapezAPI {
this.registerIcon("building_icons/" + id, iconDataURL); this.registerIcon("building_icons/" + id, iconDataURL);
this.KEYMAPPINGS.buildings[id] = { keyCode: this.KEYMAPPINGS.key(key), id: id }; 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); let promise = Promise.resolve(null);
for (let i = 0; i < this.modPack.mods.length; i++) { for (let i = 0; i < this.modPack.mods.length; i++) {
promise = promise.then(() => { if (this.modPack.mods[i].url) {
return this.addMod(this.modPack.mods[i].url); promise = promise.then(() => {
}); return this.addMod(this.modPack.mods[i].url);
});
}
} }
return promise; return promise;
} }