forked from tobspr-games/shapez.io
-
Notifications
You must be signed in to change notification settings - Fork 2
/
custom_drawing.js
63 lines (54 loc) · 2.12 KB
/
custom_drawing.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
// @ts-nocheck
const METADATA = {
website: "https://tobspr.io",
author: "tobspr",
name: "Mod Example: custom drawing",
version: "1",
id: "base",
description: "Displays an indicator on every item processing building when its working",
minimumGameVersion: ">=1.5.0",
// You can specify this parameter if savegames will still work
// after your mod has been uninstalled
doesNotAffectSavegame: true,
};
class ItemProcessorStatusGameSystem extends shapez.GameSystem {
drawChunk(parameters, chunk) {
const contents = chunk.containedEntitiesByLayer.regular;
for (let i = 0; i < contents.length; ++i) {
const entity = contents[i];
const processorComp = entity.components.ItemProcessor;
if (!processorComp) {
continue;
}
const staticComp = entity.components.StaticMapEntity;
const context = parameters.context;
const center = staticComp.getTileSpaceBounds().getCenter().toWorldSpace();
// Culling for better performance
if (parameters.visibleRect.containsCircle(center.x, center.y, 40)) {
// Circle
context.fillStyle = processorComp.ongoingCharges.length === 0 ? "#aaa" : "#53cf47";
context.strokeStyle = "#000";
context.lineWidth = 1;
context.beginCircle(center.x + 5, center.y + 5, 4);
context.fill();
context.stroke();
}
}
}
}
class Mod extends shapez.Mod {
init() {
// Register our game system
this.modInterface.registerGameSystem({
id: "item_processor_status",
systemClass: ItemProcessorStatusGameSystem,
// Specify at which point the update method will be called,
// in this case directly before the belt system. You can use
// before: "end" to make it the last system
before: "belt",
// Specify where our drawChunk method should be called, check out
// map_chunk_view
drawHooks: ["staticAfter"],
});
}
}