forked from tobspr-games/shapez.io
-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildings_have_cost.js
89 lines (79 loc) · 8.4 KB
/
buildings_have_cost.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
// @ts-nocheck
const METADATA = {
website: "https://tobspr.io",
author: "tobspr",
name: "Mod Example: Patch Methods",
version: "1",
id: "patch-methods",
description: "Shows how to patch existing methods to change the game by making the belts cost shapes",
minimumGameVersion: ">=1.5.0",
};
class Mod extends shapez.Mod {
init() {
// Define our currency
const CURRENCY = "CyCyCyCy:--------:CuCuCuCu";
// Make sure the currency is always pinned
this.modInterface.runAfterMethod(shapez.HUDPinnedShapes, "rerenderFull", function () {
this.internalPinShape({
key: CURRENCY,
canUnpin: false,
className: "currency",
});
});
// Style it
this.modInterface.registerCss(`
#ingame_HUD_PinnedShapes .shape.currency::after {
content: " ";
position: absolute;
display: inline-block;
width: $scaled(8px);
height: $scaled(8px);
top: $scaled(4px);
left: $scaled(-7px);
background: url('${RESOURCES["currency.png"]}') center center / contain no-repeat;
}
.currencyIcon {
display: inline-block;
vertical-align: middle;
background: url('${RESOURCES["currency.png"]}') center center / contain no-repeat;
}
.currencyIcon.small {
width: $scaled(11px);
height: $scaled(11px);
}
`);
// Make the player start with some currency
this.modInterface.runAfterMethod(shapez.GameCore, "initNewGame", function () {
this.root.hubGoals.storedShapes[CURRENCY] = 100;
});
// Make belts have a cost
this.modInterface.replaceMethod(shapez.MetaBeltBuilding, "getAdditionalStatistics", function (
$original,
[root, variant]
) {
const oldStats = $original(root, variant);
oldStats.push(["Cost", "1 x <span class='currencyIcon small'></span>"]);
return oldStats;
});
// Only allow placing an entity when there is enough currency
this.modInterface.replaceMethod(shapez.GameLogic, "checkCanPlaceEntity", function (
$original,
[entity, options]
) {
const storedCurrency = this.root.hubGoals.storedShapes[CURRENCY] || 0;
return storedCurrency > 0 && $original(entity, options);
});
// Take shapes when placing a building
this.modInterface.replaceMethod(shapez.GameLogic, "tryPlaceBuilding", function ($original, args) {
const result = $original(...args);
if (result && result.components.Belt) {
this.root.hubGoals.storedShapes[CURRENCY]--;
}
return result;
});
}
}
const RESOURCES = {
"currency.png":
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAAIAAAACAAF+ftPjAAAFwWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNy4xLWMwMDAgNzkuZGFiYWNiYiwgMjAyMS8wNC8xNC0wMDozOTo0NCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iIHhtbG5zOnBob3Rvc2hvcD0iaHR0cDovL25zLmFkb2JlLmNvbS9waG90b3Nob3AvMS4wLyIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0RXZ0PSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VFdmVudCMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYm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