-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbenchwarmer.ts
108 lines (105 loc) · 2.93 KB
/
benchwarmer.ts
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
import { version, author, license as licence } from "./package.json";
import { Add, findAddition } from "./add";
import { Settings } from "./settings";
import { Dropdown, Checkbox, Button, Document } from "./ui";
const name = "Benchwarmer";
function main() {
const additions = context.getAllObjects("footpath_addition");
const settings = new Settings(additions);
ui.registerMenuItem(name, () => {
const window = ui.openWindow({
title: name,
id: 1,
classification: name,
width: 300,
height: 160,
widgets: Document(
...Dropdown(
"Bench:",
settings.benches,
settings.selections.bench,
(index: number) => {
settings.bench = index;
},
),
...Dropdown(
"Bin:",
settings.bins,
settings.selections.bin,
(index: number) => {
settings.bin = index;
},
),
...Dropdown(
"Queue TV:",
settings.queuetvs,
settings.selections.queuetv,
(index: number) => {
settings.queuetv = index;
},
),
Checkbox(
"Build bins on all sloped footpaths",
settings.buildBinsOnAllSlopedPaths,
(checked: boolean) => {
settings.buildBinsOnAllSlopedPaths = checked;
},
),
Checkbox(
"Preserve other additions (e.g. lamps)",
settings.preserveOtherAdditions,
(checked: boolean) => {
settings.preserveOtherAdditions = checked;
},
),
Checkbox(
"Add benches and bins as paths are placed",
settings.asYouGo,
(checked: boolean) => {
settings.asYouGo = checked;
},
),
Button("Build on All Paths", () => {
if (settings.configured) {
try {
Add(settings);
} catch (e) {
ui.showError("Error Building Benches/Bins", (e as Error).message);
}
}
window.close();
}),
),
});
});
context.subscribe("action.execute", ({ action, args, isClientOnly }) => {
if (action === "footpathplace" && settings.asYouGo && !isClientOnly) {
const { x, y, z, slope, constructFlags } = args as FootpathPlaceArgs;
let addition = settings.bin;
if (constructFlags === 1) {
addition = settings.queuetv;
} else {
addition = slope
? settings.bin
: findAddition(settings.bench, settings.bin, x / 32, y / 32);
}
context.executeAction(
"footpathadditionplace",
{ x, y, z, object: addition },
({ errorTitle, errorMessage }) => {
if (errorMessage) throw new Error(`${errorTitle}: ${errorMessage}`);
},
);
}
});
}
registerPlugin({
name,
version,
licence,
authors: [author],
type: "local",
main,
minApiVersion: 68,
targetApiVersion: 77,
});