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:
parent
93f269d62d
commit
43348a8931
102
mod_examples/buildings_have_cost.js
Normal file
102
mod_examples/buildings_have_cost.js
Normal file
File diff suppressed because one or more lines are too long
@ -30,7 +30,7 @@ import { HUDPuzzlePlaySettings } from "../hud/parts/puzzle_play_settings";
|
|||||||
import { MetaBlockBuilding } from "../buildings/block";
|
import { MetaBlockBuilding } from "../buildings/block";
|
||||||
import { MetaBuilding } from "../meta_building";
|
import { MetaBuilding } from "../meta_building";
|
||||||
import { gMetaBuildingRegistry } from "../../core/global_registries";
|
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 logger = createLogger("puzzle-play");
|
||||||
const copy = require("clipboard-copy");
|
const copy = require("clipboard-copy");
|
||||||
|
|||||||
@ -36,6 +36,10 @@ export class ModInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerCss(cssString) {
|
registerCss(cssString) {
|
||||||
|
// Preprocess css
|
||||||
|
cssString = cssString.replace(/\$scaled\(([^\)]*)\)/gim, (substr, expression) => {
|
||||||
|
return "calc((" + expression + ") * var(--ui-scale))";
|
||||||
|
});
|
||||||
const element = document.createElement("style");
|
const element = document.createElement("style");
|
||||||
element.textContent = cssString;
|
element.textContent = cssString;
|
||||||
document.head.appendChild(element);
|
document.head.appendChild(element);
|
||||||
@ -360,6 +364,26 @@ export class ModInterface {
|
|||||||
* Patches a method on a given object
|
* Patches a method on a given object
|
||||||
*/
|
*/
|
||||||
replaceMethod(classHandle, methodName, override) {
|
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;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,12 +84,21 @@ export class ModLoader {
|
|||||||
mods = await ipcRenderer.invoke("get-mods");
|
mods = await ipcRenderer.invoke("get-mods");
|
||||||
}
|
}
|
||||||
if (G_IS_DEV && globalConfig.debug.externalModUrl) {
|
if (G_IS_DEV && globalConfig.debug.externalModUrl) {
|
||||||
const mod = await (
|
const response = await fetch(globalConfig.debug.externalModUrl, {
|
||||||
await fetch(globalConfig.debug.externalModUrl, {
|
method: "GET",
|
||||||
method: "GET",
|
});
|
||||||
})
|
if (response.status !== 200) {
|
||||||
).text();
|
throw new Error(
|
||||||
mods.push(mod);
|
"Failed to load " +
|
||||||
|
globalConfig.debug.externalModUrl +
|
||||||
|
": " +
|
||||||
|
response.status +
|
||||||
|
" " +
|
||||||
|
response.statusText
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
mods.push(await response.text());
|
||||||
}
|
}
|
||||||
|
|
||||||
mods.forEach(modCode => {
|
mods.forEach(modCode => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user