1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-14 02:31: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 // Add it to the regular toolbar
this.signals.hudElementInitialized.add(element => { this.modInterface.addNewBuildingToToolbar({
if (element.constructor.name === "HUDBuildingsToolbar") { toolbar: "regular",
element.primaryBuildings.push(MetaDemoModBuilding); location: "primary",
} metaClass: MetaDemoModBuilding,
}); });
} }
}; };

View File

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

View File

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

View File

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