-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.js
382 lines (355 loc) · 8.13 KB
/
main.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
"use strict";
const alert = require("./modules/alert");
const electron = require("electron");
const ipcMain = require("electron").ipcMain;
const path = require("path");
const windows = require("./modules/windows");
let about_message = `Chlorine: Replay viewer for Halite 2\n` +
`--\n` +
`Electron ${process.versions.electron}\n` +
`Node ${process.versions.node}\n` +
`V8 ${process.versions.v8}`
// -------------------------------------------------------
electron.app.on("ready", () => {
windows.new("renderer", {
title: "Chlorine", show: true, width: 1200, height: 800, resizable: true, page: path.join(__dirname, "chlorine_renderer.html")
});
windows.new("info", {
title: "Info", show: false, width: 400, height: 800, resizable: true, page: path.join(__dirname, "chlorine_info.html")
});
windows.new("events", {
title: "Events", show: false, width: 400, height: 800, resizable: true, page: path.join(__dirname, "chlorine_info.html")
});
electron.Menu.setApplicationMenu(make_main_menu());
});
electron.app.on("window-all-closed", () => {
electron.app.quit();
});
// -------------------------------------------------------
ipcMain.on("renderer_ready", () => {
// Load a file via command line with -o filename.
let filename = "";
for (let i = 0; i < process.argv.length - 1; i++) {
if (process.argv[i] === "-o") {
filename = process.argv[i + 1];
}
}
if (filename !== "") {
windows.send("renderer", "open", filename);
}
/*
else if (process.argv.length === 2) { // Or, if exactly 1 arg, assume it's a filename. Only good for standalone release.
windows.send("renderer", "open", process.argv[1]);
}
*/
});
ipcMain.on("relay", (event, msg) => {
windows.send(msg.receiver, msg.channel, msg.content); // Messages from one browser window to another...
});
// -------------------------------------------------------
function make_main_menu() {
const template = [
{
label: "File",
submenu: [
{
label: "About...",
click: () => {
alert(about_message);
}
},
{
role: "toggledevtools"
},
{
type: "separator"
},
{
label: "Open...",
accelerator: "CommandOrControl+O",
click: () => {
let files = electron.dialog.showOpenDialog();
if (files && files.length > 0) {
windows.send("renderer", "open", files[0]);
}
}
},
{
type: "separator"
},
{
label: "Save decompressed JSON...",
accelerator: "CommandOrControl+S",
click: () => {
let outfilename = electron.dialog.showSaveDialog();
if (outfilename) {
windows.send("renderer", "save", outfilename);
}
}
},
{
label: "Save current entities...",
click: () => {
let outfilename = electron.dialog.showSaveDialog();
if (outfilename) {
windows.send("renderer", "save_frame", outfilename);
}
}
},
{
label: "Save current moves...",
click: () => {
let outfilename = electron.dialog.showSaveDialog();
if (outfilename) {
windows.send("renderer", "save_moves", outfilename);
}
}
},
{
type: "separator"
},
{
accelerator: "CommandOrControl+Q",
role: "quit"
},
]
},
{
label: "Navigation",
submenu: [
{
label: "Forward",
accelerator: "Right",
click: () => {
windows.send("renderer", "forward", 1);
}
},
{
label: "Back",
accelerator: "Left",
click: () => {
windows.send("renderer", "forward", -1);
}
},
{
type: "separator"
},
{
label: "Move to Start",
accelerator: "Home",
click: () => {
windows.send("renderer", "forward", -99999);
}
},
{
label: "Move to End",
accelerator: "End",
click: () => {
windows.send("renderer", "forward", 99999);
}
},
{
type: "separator"
},
{
label: "Go To Next Event",
accelerator: "Enter",
click: () => {
windows.send("renderer", "go_to_next_event", null);
}
},
]
},
{
label: "View",
submenu: [
{
label: "Reset Zoom / Scroll",
accelerator: "F1",
click: () => {
windows.send("renderer", "reset_zoom", null);
}
},
{
type: "separator"
},
{
label: "Weapon Ranges",
click: () => {
windows.send("renderer", "toggle", "weapon_ranges");
},
type: "checkbox",
checked: false,
},
{
label: "Tactical Ranges (13)",
submenu: [
{
label: "Pink",
accelerator: "1",
click: () => {
windows.send("renderer", "toggle", "tactical_ranges_0");
},
type: "checkbox",
checked: false,
},
{
label: "Blue",
accelerator: "2",
click: () => {
windows.send("renderer", "toggle", "tactical_ranges_1");
},
type: "checkbox",
checked: false,
},
{
label: "Yellow",
accelerator: "3",
click: () => {
windows.send("renderer", "toggle", "tactical_ranges_2");
},
type: "checkbox",
checked: false,
},
{
label: "Green",
accelerator: "4",
click: () => {
windows.send("renderer", "toggle", "tactical_ranges_3");
},
type: "checkbox",
checked: false,
},
]
},
{
label: "Docking Ranges",
click: () => {
windows.send("renderer", "toggle", "docking_ranges");
},
type: "checkbox",
checked: false,
},
{
type: "separator"
},
{
label: "Planets",
click: () => {
windows.send("renderer", "toggle", "show_planets");
},
type: "checkbox",
checked: true,
},
{
type: "separator"
},
{
label: "Tails",
accelerator: "T",
click: () => {
windows.send("renderer", "toggle", "tails");
},
type: "checkbox",
checked: true,
},
{
label: "Pointers",
accelerator: "P",
click: () => {
windows.send("renderer", "toggle", "pointers");
},
type: "checkbox",
checked: false,
},
{
label: "Deaths",
click: () => {
windows.send("renderer", "toggle", "deaths");
},
type: "checkbox",
checked: true,
},
{
type: "separator"
},
{
label: "Selection Crosshair",
click: () => {
windows.send("renderer", "toggle", "crosshair");
},
type: "checkbox",
checked: true,
},
{
label: "High Precision Coordinates",
click: () => {
windows.send("renderer", "toggle", "precise");
},
type: "checkbox",
checked: false,
},
{
type: "separator"
},
{
label: "Angle Message Interpretation", // Consider angles >= 360 as encoding a number...
click: () => {
windows.send("renderer", "toggle", "angle_messages");
},
type: "checkbox",
checked: true,
},
{
label: "About Angle Messages...",
click: () => {
about_angle_messages();
}
},
]
},
{
label: "Windows",
submenu: [
{
label: "Renderer",
click: () => {
windows.show("renderer");
}
},
{
label: "Info",
click: () => {
windows.show("info");
}
},
{
label: "Events",
click: () => {
windows.show("events");
}
},
]
},
];
return electron.Menu.buildFromTemplate(template);
}
function about_angle_messages() {
let s = `
Want your ships to write messages directly into the game replay? \
Of course you do! Introducing Chlorine's patented Angle Message \
system! Exploit the redundancy inherent in angles to send messages \
to yourself!
How it works:
A Halite angle is an unsigned int16. There are just over 180 ways \
of sending the same angle. Chlorine can interpret ship movements \
with angles over 359 as messages, where each message is a number \
in the range 0..180.
To encode:
def new_angle_with_message(angle, message):
return ((message + 1) * 360) + angle
Then use the new angle when sending the ship's thrust to the server. \
Chlorine can show the message in the ship info. You can also edit \
messages.json to display text rather than numbers.`;
alert(s);
}