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

Add interface to register new buildings

This commit is contained in:
tobspr 2022-01-16 10:39:54 +01:00
parent 22b619e8ab
commit e4b8071c2f
5 changed files with 29 additions and 14 deletions

View File

@ -56,10 +56,10 @@ registerMod(() => {
});
// Add it to the regular toolbar
this.signals.hudElementInitialized.add(element => {
if (element.constructor.name === "HUDBuildingsToolbar") {
element.primaryBuildings.push(MetaDemoModBuilding);
}
this.modInterface.addNewBuildingToToolbar({
toolbar: "regular",
location: "primary",
metaClass: MetaDemoModBuilding,
});
}
};

View File

@ -121,10 +121,10 @@ registerMod(() => {
});
// Add it to the regular toolbar
this.signals.hudElementInitialized.add(element => {
if (element.constructor.name === "HUDBuildingsToolbar") {
element.primaryBuildings.push(MetaModFlipperBuilding);
}
this.modInterface.addNewBuildingToToolbar({
toolbar: "regular",
location: "primary",
metaClass: MetaModFlipperBuilding,
});
}
};

View File

@ -188,11 +188,10 @@ registerMod(() => {
});
// Add it to the regular toolbar
this.signals.hudElementInitialized.add(element => {
if (element.constructor.name === "HUDBuildingsToolbar") {
// @ts-ignore
element.primaryBuildings.push(MetaDemoModBuilding);
}
this.modInterface.addNewBuildingToToolbar({
toolbar: "regular",
location: "primary",
metaClass: MetaDemoModBuilding,
});
// Register keybinding

View File

@ -19,7 +19,6 @@ registerMod(() => {
}
init() {
console.log("CUSTOM GAME THEME NOW");
this.modInterface.registerGameTheme({
id: "my-theme",
name: "My fancy theme",

View File

@ -344,4 +344,21 @@ export class ModInterface {
},
});
}
/**
* @param {object} param0
* @param {"regular"|"wires"} param0.toolbar
* @param {"primary"|"secondary"} param0.location
* @param {typeof MetaBuilding} param0.metaClass
*/
addNewBuildingToToolbar({ toolbar, location, metaClass }) {
const hudElementName = toolbar === "wires" ? "HUDWiresToolbar" : "HUDBuildingsToolbar";
const property = location === "secondary" ? "secondaryBuildings" : "primaryBuildings";
this.modLoader.signals.hudElementInitialized.add(element => {
if (element.constructor.name === hudElementName) {
element[property].push(metaClass);
}
});
}
}