Merge pull request #67 from eaglerforge/main

v2.7.3: mod config metadata
This commit is contained in:
ZXMushroom63 2025-03-16 16:24:50 +08:00 committed by GitHub
commit 7c333cc20c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 8 deletions

View File

@ -10,4 +10,8 @@ Methods:
- Sets the description of the mod. Character limit of 160.
- `ModAPI.meta.icon(iconURL: String)`
- Sets the icon of the mod.
- It can be extremely low res, it will not appear blurry.
- It can be extremely low res, it will not appear blurry.
- `ModAPI.meta.version(versionCode: String)`
- Sets the version of the mod. Appended after the title.
- `ModAPI.meta.config(configFn: Function)`
- Once the client is fully loaded, creates a button in the mod manager GUI that runs the specified function when pressed.

View File

@ -1,4 +1,4 @@
globalThis.ModAPIVersion = "v2.7.2";
globalThis.ModAPIVersion = "v2.7.3";
globalThis.doEaglerforge = true;
document.querySelector("title").innerText = `EaglerForge Injector ${ModAPIVersion}`;
document.querySelector("h1").innerText = `EaglerForge Injector ${ModAPIVersion}`;

View File

@ -248,15 +248,28 @@ globalThis.modapi_guikit = "(" + (() => {
spacer.classList.add("nothing");
var controls = document.createElement("td");
var button = document.createElement("button");
button.innerText = "Delete";
button.style.height = "3rem";
button.addEventListener("click", async () => {
var deleteBtn = document.createElement("button");
deleteBtn.innerText = "Delete";
deleteBtn.style.height = "3rem";
deleteBtn.addEventListener("click", async () => {
await removeMod(i);
window.modapi_displayModGui();
});
button.classList.add("button");
controls.appendChild(button);
deleteBtn.classList.add("button");
controls.appendChild(deleteBtn);
if (typeof ModAPI.meta._configMap[hash] === "function") {
var configBtn = document.createElement("button");
configBtn.innerText = "Config";
configBtn.style.height = "3rem";
configBtn.style.marginLeft = "1rem";
configBtn.addEventListener("click", async () => {
ModAPI.meta._configMap[hash]();
});
configBtn.classList.add("button");
controls.appendChild(configBtn);
}
tr.appendChild(mod);
tr.appendChild(spacer);
tr.appendChild(controls);

View File

@ -22,6 +22,7 @@ globalThis.modapi_postinit = "(" + (() => {
ModAPI.meta = {};
ModAPI.meta._titleMap = {};
ModAPI.meta._descriptionMap = {};
ModAPI.meta._configMap = {};
ModAPI.meta._developerMap = {};
ModAPI.meta._iconMap = {};
ModAPI.meta._versionMap = {};
@ -78,6 +79,9 @@ globalThis.modapi_postinit = "(" + (() => {
" - Made the mod gui open before the client starts");
function limitSize(x, n) {
if (!x) {
return "";
}
if (x.length > n) {
return x.substring(0, n) + "…";
} else {
@ -161,6 +165,18 @@ globalThis.modapi_postinit = "(" + (() => {
}
ModAPI.meta._descriptionMap[document.currentScript.getAttribute("data-hash")] = limitSize(desc, 160);
}
ModAPI.meta.config = function (conf) {
if (typeof conf !== "function") {
return console.log("[ModAPIMeta] Config value was not a function");
}
if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") {
return console.log("[ModAPIMeta] Cannot set meta for non-mod script.");
}
if (!document.currentScript.hasAttribute("data-hash")) {
return console.log("[ModAPIMeta] Script does not have a hashcode.");
}
ModAPI.meta._configMap[document.currentScript.getAttribute("data-hash")] = conf;
}
ModAPI.meta.version = function (ver) {
if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") {
return console.log("[ModAPIMeta] Cannot set meta for non-mod script.");