From c296e38732c1594437dd1d37d1d747a436a88c48 Mon Sep 17 00:00:00 2001 From: MollTheCoder Date: Sat, 14 Jan 2023 18:20:39 -0500 Subject: [PATCH 1/2] Create libpacman.js --- mods/libpacman.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 mods/libpacman.js diff --git a/mods/libpacman.js b/mods/libpacman.js new file mode 100644 index 00000000..d1326d5f --- /dev/null +++ b/mods/libpacman.js @@ -0,0 +1,52 @@ +/* + * Requires that certain mods are installed for the callback to proceed. + * @param {array} mods - The mods your mod depends on. + * @param {function} callback - The callback to run when the dependencies are met. + */ +function requireMods(mods, cal) { + if (__checkMods(mods)) { + cal(); + } + else { + __installMods(mods); + window.location.reload(); + } +} + +/* + * Fetches the name of any mods that are missing + * @param {array} mods - The mods your mod depends on. + * @returns {array} An array of missing mods. + */ +function __getMissingMods(mods) { + let missing = []; + for (let i = 0; i < mods.length; i++) { + if (enabledMods.includes(mods[i])) { + continue; + } + missing.push(mods[i]); + } + return missing; +} + +/* + * Checks if any mods are missing. + * @param {array} mods - The mods your mod depends on. + * @returns {boolean} True if any mods are missing. + */ +function __checkMods(mods) { + return __getMissingMods(mods).length === 0; +} + +function __installMods(mods) { + __getMissingMods(mods).forEach(mod => __installMod(mod)); +} + +function __installMod(mod) { + let mods = JSON.parse(window.localStorage.getItem("enabledMods") || "[]"); + mods.push(mod); + window.localStorage.setItem("enabledMods", JSON.stringify(mods)); +} + +// Ensure it's available in the global scope +window.requireMods = requireMods; From 6059ae66faeb83ca684807838fbc00178da3d8e6 Mon Sep 17 00:00:00 2001 From: MollTheCoder Date: Sat, 14 Jan 2023 18:30:06 -0500 Subject: [PATCH 2/2] Final touches --- mods/{libpacman.js => libpacman-v1.js} | 4 ++++ 1 file changed, 4 insertions(+) rename mods/{libpacman.js => libpacman-v1.js} (85%) diff --git a/mods/libpacman.js b/mods/libpacman-v1.js similarity index 85% rename from mods/libpacman.js rename to mods/libpacman-v1.js index d1326d5f..60e4068a 100644 --- a/mods/libpacman.js +++ b/mods/libpacman-v1.js @@ -1,3 +1,6 @@ +/* Helps make managing many dependencies easier */ +// Version 1.0.0 + /* * Requires that certain mods are installed for the callback to proceed. * @param {array} mods - The mods your mod depends on. @@ -5,6 +8,7 @@ */ function requireMods(mods, cal) { if (__checkMods(mods)) { + // The whole callback system remains from a feature that was nerfed soon before release. It will either be removed or taken advantage of in future versions. cal(); } else {