forked from tobspr-games/shapez.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_building_flipper.js
130 lines (110 loc) · 11.5 KB
/
add_building_flipper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// @ts-nocheck
const METADATA = {
website: "https://tobspr.io",
author: "tobspr",
name: "Mod Example: Add a flipper building",
version: "1",
id: "add-building-extended",
description:
"Shows how to add a new building with logic, in this case it flips/mirrors shapez from top to down",
minimumGameVersion: ">=1.5.0",
};
// Declare a new type of item processor
shapez.enumItemProcessorTypes.flipper = "flipper";
// For now, flipper always has the same speed
shapez.MOD_ITEM_PROCESSOR_SPEEDS.flipper = () => 10;
// Declare a handler for the processor so we define the "flip" operation
shapez.MOD_ITEM_PROCESSOR_HANDLERS.flipper = function (payload) {
const shapeDefinition = payload.items.get(0).definition;
// Flip bottom with top on a new, cloned item (NEVER modify the incoming item!)
const newLayers = shapeDefinition.getClonedLayers();
newLayers.forEach(layer => {
const tr = layer[shapez.TOP_RIGHT];
const br = layer[shapez.BOTTOM_RIGHT];
const bl = layer[shapez.BOTTOM_LEFT];
const tl = layer[shapez.TOP_LEFT];
layer[shapez.BOTTOM_LEFT] = tl;
layer[shapez.BOTTOM_RIGHT] = tr;
layer[shapez.TOP_LEFT] = bl;
layer[shapez.TOP_RIGHT] = br;
});
const newDefinition = new shapez.ShapeDefinition({ layers: newLayers });
payload.outItems.push({
item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(newDefinition),
});
};
// Create the building
class MetaModFlipperBuilding extends shapez.ModMetaBuilding {
constructor() {
super("modFlipperBuilding");
}
static getAllVariantCombinations() {
return [
{
name: "Flipper",
description: "Flipps/Mirrors shapez from top to bottom",
variant: shapez.defaultBuildingVariant,
regularImageBase64: RESOURCES["flipper.png"],
blueprintImageBase64: RESOURCES["flipper.png"],
tutorialImageBase64: RESOURCES["flipper.png"],
},
];
}
getSilhouetteColor() {
return "red";
}
getAdditionalStatistics(root) {
const speed = root.hubGoals.getProcessorBaseSpeed(shapez.enumItemProcessorTypes.flipper);
return [[shapez.T.ingame.buildingPlacement.infoTexts.speed, shapez.formatItemsPerSecond(speed)]];
}
getIsUnlocked(root) {
return true;
}
setupEntityComponents(entity) {
// Accept shapes from the bottom
entity.addComponent(
new shapez.ItemAcceptorComponent({
slots: [
{
pos: new shapez.Vector(0, 0),
direction: shapez.enumDirection.bottom,
filter: "shape",
},
],
})
);
// Process those shapes with tye processor type "flipper" (which we added above)
entity.addComponent(
new shapez.ItemProcessorComponent({
inputsPerCharge: 1,
processorType: shapez.enumItemProcessorTypes.flipper,
})
);
// Eject the result to the top
entity.addComponent(
new shapez.ItemEjectorComponent({
slots: [{ pos: new shapez.Vector(0, 0), direction: shapez.enumDirection.top }],
})
);
}
}
class Mod extends shapez.Mod {
init() {
// Register the new building
this.modInterface.registerNewBuilding({
metaClass: MetaModFlipperBuilding,
buildingIconBase64: RESOURCES["flipper.png"],
});
// Add it to the regular toolbar
this.modInterface.addNewBuildingToToolbar({
toolbar: "regular",
location: "primary",
metaClass: MetaModFlipperBuilding,
});
}
}
////////////////////////////////////////////////////////////////////////
const RESOURCES = {
"flipper.png":
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+ID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