From 0141df1abf736c406f32c3034ba4a9b1e9c86161 Mon Sep 17 00:00:00 2001 From: Bagel03 <70449196+Bagel03@users.noreply.github.com> Date: Tue, 18 Jan 2022 11:12:23 -0500 Subject: [PATCH] Allow external URL to load more than one mod Instead of loading the text returned from the remote server, load a JSON object with a `mods` field, containing strings of all the mods. This lets us work on more than one mod at a time or without separate repos. This will break tooling such as `create-shapezio-mod` though. --- src/js/mods/modloader.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/js/mods/modloader.js b/src/js/mods/modloader.js index fa90b8a6..57a732d3 100644 --- a/src/js/mods/modloader.js +++ b/src/js/mods/modloader.js @@ -116,8 +116,24 @@ export class ModLoader { response.statusText ); } + + let json; + try { + json = await response.json(); + } catch (e) { + throw new Error( + "Failed to parse JSON object from " + + globalConfig.debug.externalModUrl + + ": " + + e + ); + } + + if(json.mods === undefined) { + throw new Error("Failed to load " + globalConfig.debug.externalModUrl + ": No 'mods' field in json object"); + } - mods.push(await response.text()); + mods = mods.concat(json.mods); } window.$shapez_registerMod = (modClass, meta) => {