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 { 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");
|
||||
|
||||
@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user