mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-14 02:31:51 +00:00
Allow overriding existing methods
This commit is contained in:
parent
1bd569f89c
commit
93f269d62d
36
mod_examples/modify_existing_building.js
Normal file
36
mod_examples/modify_existing_building.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* This shows how to modify an existing building
|
||||||
|
*/
|
||||||
|
registerMod(() => {
|
||||||
|
return class ModImpl extends shapez.Mod {
|
||||||
|
constructor(app, modLoader) {
|
||||||
|
super(
|
||||||
|
app,
|
||||||
|
{
|
||||||
|
website: "https://tobspr.io",
|
||||||
|
author: "tobspr",
|
||||||
|
name: "Mod Example: Modify existing building",
|
||||||
|
version: "1",
|
||||||
|
id: "modify-existing-building",
|
||||||
|
description: "Shows how to modify an existing building",
|
||||||
|
},
|
||||||
|
modLoader
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
// Make Rotator always unlocked
|
||||||
|
this.modInterface.replaceMethod(shapez.MetaRotaterBuilding, "getIsUnlocked", function () {
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add some custom stats to the info panel when selecting the building
|
||||||
|
this.modInterface.replaceMethod(shapez.MetaRotaterBuilding, "getAdditionalStatistics", function (
|
||||||
|
root,
|
||||||
|
variant
|
||||||
|
) {
|
||||||
|
return [["Awesomeness", 5]];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
@ -22,31 +22,34 @@ import { ItemProducerComponent } from "./components/item_producer";
|
|||||||
import { GoalAcceptorComponent } from "./components/goal_acceptor";
|
import { GoalAcceptorComponent } from "./components/goal_acceptor";
|
||||||
|
|
||||||
export function initComponentRegistry() {
|
export function initComponentRegistry() {
|
||||||
gComponentRegistry.register(StaticMapEntityComponent);
|
const components = [
|
||||||
gComponentRegistry.register(BeltComponent);
|
StaticMapEntityComponent,
|
||||||
gComponentRegistry.register(ItemEjectorComponent);
|
BeltComponent,
|
||||||
gComponentRegistry.register(ItemAcceptorComponent);
|
ItemEjectorComponent,
|
||||||
gComponentRegistry.register(MinerComponent);
|
ItemAcceptorComponent,
|
||||||
gComponentRegistry.register(ItemProcessorComponent);
|
MinerComponent,
|
||||||
gComponentRegistry.register(UndergroundBeltComponent);
|
ItemProcessorComponent,
|
||||||
gComponentRegistry.register(HubComponent);
|
UndergroundBeltComponent,
|
||||||
gComponentRegistry.register(StorageComponent);
|
HubComponent,
|
||||||
gComponentRegistry.register(WiredPinsComponent);
|
StorageComponent,
|
||||||
gComponentRegistry.register(BeltUnderlaysComponent);
|
WiredPinsComponent,
|
||||||
gComponentRegistry.register(WireComponent);
|
BeltUnderlaysComponent,
|
||||||
gComponentRegistry.register(ConstantSignalComponent);
|
WireComponent,
|
||||||
gComponentRegistry.register(LogicGateComponent);
|
ConstantSignalComponent,
|
||||||
gComponentRegistry.register(LeverComponent);
|
LogicGateComponent,
|
||||||
gComponentRegistry.register(WireTunnelComponent);
|
LeverComponent,
|
||||||
gComponentRegistry.register(DisplayComponent);
|
WireTunnelComponent,
|
||||||
gComponentRegistry.register(BeltReaderComponent);
|
DisplayComponent,
|
||||||
gComponentRegistry.register(FilterComponent);
|
BeltReaderComponent,
|
||||||
gComponentRegistry.register(ItemProducerComponent);
|
FilterComponent,
|
||||||
gComponentRegistry.register(GoalAcceptorComponent);
|
ItemProducerComponent,
|
||||||
|
GoalAcceptorComponent,
|
||||||
|
];
|
||||||
|
components.forEach(component => gComponentRegistry.register(component));
|
||||||
|
|
||||||
// IMPORTANT ^^^^^ UPDATE ENTITY COMPONENT STORAGE AFTERWARDS
|
// IMPORTANT ^^^^^ UPDATE ENTITY COMPONENT STORAGE AFTERWARDS
|
||||||
|
|
||||||
// Sanity check - If this is thrown, you (=me, lol) forgot to add a new component here
|
// Sanity check - If this is thrown, you forgot to add a new component here
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@ -21,37 +21,6 @@ if (window.coreThreadLoadedCb) {
|
|||||||
window.coreThreadLoadedCb();
|
window.coreThreadLoadedCb();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logrocket
|
|
||||||
// if (!G_IS_DEV && !G_IS_STANDALONE) {
|
|
||||||
// const monthlyUsers = 300; // thousand
|
|
||||||
// const logrocketLimit = 10; // thousand
|
|
||||||
// const percentageOfUsers = logrocketLimit / monthlyUsers;
|
|
||||||
|
|
||||||
// if (Math.random() <= percentageOfUsers) {
|
|
||||||
// logger.log("Analyzing this session with logrocket");
|
|
||||||
// const logrocket = require("logrocket");
|
|
||||||
// logrocket.init("p1x9zh/shapezio");
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// logrocket.getSessionURL(function (sessionURL) {
|
|
||||||
// logger.log("Connected lockrocket to GA");
|
|
||||||
// // @ts-ignore
|
|
||||||
// try {
|
|
||||||
// window.ga("send", {
|
|
||||||
// hitType: "event",
|
|
||||||
// eventCategory: "LogRocket",
|
|
||||||
// eventAction: sessionURL,
|
|
||||||
// });
|
|
||||||
// } catch (ex) {
|
|
||||||
// logger.warn("Logrocket connection to analytics failed:", ex);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// } catch (ex) {
|
|
||||||
// logger.warn("Logrocket connection to analytics failed:", ex);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`%cshapez.io ️%c\n© 2022 tobspr Games\nCommit %c${G_BUILD_COMMIT_HASH}%c on %c${new Date(
|
`%cshapez.io ️%c\n© 2022 tobspr Games\nCommit %c${G_BUILD_COMMIT_HASH}%c on %c${new Date(
|
||||||
G_BUILD_TIME
|
G_BUILD_TIME
|
||||||
|
|||||||
@ -355,4 +355,11 @@ export class ModInterface {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Patches a method on a given object
|
||||||
|
*/
|
||||||
|
replaceMethod(classHandle, methodName, override) {
|
||||||
|
classHandle.prototype[methodName] = override;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user