/
HeightModifier.js
241 lines (225 loc) · 6.36 KB
/
HeightModifier.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// HeightModifier.js By Willby an OpenRCT2 Plugin
var showing = true;
var filter = 0;
var remove = false;
var downCoord = void 0;
var currentCoord = void 0;
var left, right, top, bottom;
var computer_close = false;
var area_selected = false;
var getting_selection = false;
function selectTheMap() { // Display Selection
var left = Math.min(downCoord.x, currentCoord.x);
var right = Math.max(downCoord.x, currentCoord.x);
var top = Math.min(downCoord.y, currentCoord.y);
var bottom = Math.max(downCoord.y, currentCoord.y);
ui.tileSelection.range = {
leftTop: { x: left, y: top },
rightBottom: { x: right, y: bottom }
};
}
function finishSelection() { // Safe the final section area
left = Math.floor(Math.min(downCoord.x, currentCoord.x) / 32);
right = Math.floor(Math.max(downCoord.x, currentCoord.x) / 32);
top = Math.floor(Math.min(downCoord.y, currentCoord.y) / 32);
bottom = Math.floor(Math.max(downCoord.y, currentCoord.y) / 32);
area_selected = true;
}
function affect_selection(moveUp) {
if (!currentPlayerHasPermissions())
{
ui.showError("Can't do this...", "Permission denied (Modify Tile)");
return;
}
for (var x = left; x <= right; x++) {
for (var y = top; y <= bottom; y++) {
var tile = map.getTile(x, y);
for (var i = 0; i < tile.numElements; i++) {
var element = tile.getElement(i);
if (filters[filter]=="all") {
affect_element(x, y, i, moveUp);
} else if (filters[filter]=="all_obj"&&element.type!="surface") {
affect_element(x, y, i, moveUp);
} else if (filters[filter]=="scenery"&&(element.type=="small_scenery"||element.type=="large_scenery"||element.type=="wall")) {
affect_element(x, y, i, moveUp);
} else {
if (element.type==filters[filter]) {
affect_element(x, y, i, moveUp);
}
}
}
}
}
}
function affect_element(x, y, index, moveUp)
{
context.executeAction("tilemodify", {
x: x * 32,
y: y * 32,
setting: 6,
value1: index,
value2: moveUp ? 1 : -1,
});
}
function currentPlayerHasPermissions()
{
if (network.mode == "none")
{
return true;
}
var playerGroup = network.getGroup(network.currentPlayer.group);
return playerGroup.permissions.indexOf("modify_tile") >= 0;
}
var filters = ["all_obj","track","footpath","scenery","small_scenery","large_scenery","wall","surface","all"];
function hm_window() {
widgets = []
var height = 0;
if (area_selected) {
widgets.push({
type: 'label',
name: 'label-description',
x: 3,
y: 20,
width: 300,
height: 60,
text: "Select an option below to affect"
});
widgets.push({
type: 'label',
name: 'label-description',
x: 3,
y: 30,
width: 300,
height: 60,
text: "the selected area."
});
widgets.push({
type: 'button',
name: "select-area-button",
x: 10,
y: 65,
width: 90,
height: 15,
text: "Move Up",
onClick: function onClick() {
affect_selection(true);
}
});
widgets.push({
type: 'button',
name: "select-area-button",
x: 120,
y: 65,
width: 90,
height: 15,
text: "Move Down",
onClick: function onClick() {
affect_selection(false);
}
});
height = 90;
} else {
widgets.push({
type: 'label',
name: 'label-description',
x: 3,
y: 20,
width: 300,
height: 60,
text: "Drag area to be selected."
});
height = 70;
}
widgets.push({
type: "dropdown",
x: 5,
y: 45,
width: 210,
height: 15,
name: "filter_dropdown",
text: "",
items: ["Everything except surface", "Ride tracks", "Footpaths", "Scenery only", "Scenery (small)", "Scenery (large)", "Walls", "Surface", "Everything"],
selectedIndex: filter,
onChange: function onChange(e) {
filter = e;
}
})
window = ui.openWindow({
classification: 'park',
title: "Height Modifier",
width: 220,
height: height,
x: 20,
y: 50,
colours: [22,22],
widgets: widgets,
onClose: function onClose() { // Stop selection tool when the window closes
window = null;
if (ui.tool && ui.tool.id == "height-modifier-tool" && computer_close == false) {
area_selected = false;
ui.tool.cancel();
}
computer_close = false;
}
});
}
function main() {
ui.registerMenuItem("Height Modifier", function() {
hm_window()
getting_selection = true;
ui.activateTool({ // Create tool for selecting area
id: "height-modifier-tool",
cursor: "cross_hair",
onStart: function onStart(e) {
ui.mainViewport.visibilityFlags |= 1 << 7;
},
onDown: function onDown(e) {
if (e.mapCoords.x === 0 && e.mapCoords.y === 0) {
return;
}
getting_selection = true;
downCoord = e.mapCoords;
currentCoord = e.mapCoords;
},
onMove: function onMove(e) {
if (e.mapCoords.x === 0 && e.mapCoords.y === 0) {
return;
}
if (e.isDown) {
if (getting_selection) {
currentCoord = e.mapCoords;
}
selectTheMap();
} else {
if (getting_selection) {
downCoord = e.mapCoords;
currentCoord = e.mapCoords;
}
selectTheMap();
}
},
onUp: function onUp(e) {
getting_selection = false;
finishSelection();
computer_close = true;
window.close();
hm_window()
},
onFinish: function onFinish() {
ui.mainViewport.visibilityFlags &= ~(1 << 7);
if (window != null) window.close();
}
});
});
}
registerPlugin({
name: 'Height Modifier',
version: '1.3.0',
licence: 'MIT',
authors: [
'Willby',
'sph',
'Katherine Norton (KatieZeldaKat)'],
type: 'remote',
main: main
});