1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-13 18:21:51 +00:00

Add more examples and more features

This commit is contained in:
tobspr 2022-01-16 16:13:57 +01:00
parent 93f269d62d
commit 43348a8931
5 changed files with 143 additions and 8 deletions

File diff suppressed because one or more lines are too long

View File

@ -30,7 +30,7 @@ import { HUDPuzzlePlaySettings } from "../hud/parts/puzzle_play_settings";
import { MetaBlockBuilding } from "../buildings/block";
import { MetaBuilding } from "../meta_building";
import { gMetaBuildingRegistry } from "../../core/global_registries";
import { HUDPuzzleNextPuzzle } from "../hud/parts/HUDPuzzleNextPuzzle";
import { HUDPuzzleNextPuzzle } from "../hud/parts/next_puzzle";
const logger = createLogger("puzzle-play");
const copy = require("clipboard-copy");

View File

@ -36,6 +36,10 @@ export class ModInterface {
}
registerCss(cssString) {
// Preprocess css
cssString = cssString.replace(/\$scaled\(([^\)]*)\)/gim, (substr, expression) => {
return "calc((" + expression + ") * var(--ui-scale))";
});
const element = document.createElement("style");
element.textContent = cssString;
document.head.appendChild(element);
@ -360,6 +364,26 @@ export class ModInterface {
* Patches a method on a given object
*/
replaceMethod(classHandle, methodName, override) {
classHandle.prototype[methodName] = override;
const oldMethod = classHandle.prototype[methodName];
classHandle.prototype[methodName] = function () {
return override.call(this, oldMethod.bind(this), arguments);
};
}
runBeforeMethod(classHandle, methodName, executeBefore) {
const oldHandle = classHandle.prototype[methodName];
classHandle.prototype[methodName] = function () {
executeBefore.apply(this, arguments);
return oldHandle.apply(this, arguments);
};
}
runAfterMethod(classHandle, methodName, executeAfter) {
const oldHandle = classHandle.prototype[methodName];
classHandle.prototype[methodName] = function () {
const returnValue = oldHandle.apply(this, arguments);
executeAfter.apply(this, arguments);
return returnValue;
};
}
}

View File

@ -84,12 +84,21 @@ export class ModLoader {
mods = await ipcRenderer.invoke("get-mods");
}
if (G_IS_DEV && globalConfig.debug.externalModUrl) {
const mod = await (
await fetch(globalConfig.debug.externalModUrl, {
method: "GET",
})
).text();
mods.push(mod);
const response = await fetch(globalConfig.debug.externalModUrl, {
method: "GET",
});
if (response.status !== 200) {
throw new Error(
"Failed to load " +
globalConfig.debug.externalModUrl +
": " +
response.status +
" " +
response.statusText
);
}
mods.push(await response.text());
}
mods.forEach(modCode => {