-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
486 lines (446 loc) · 19.7 KB
/
index.html
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<!doctype html>
<html>
<head>
<title>Live RogueTech War Map</title>
<meta charset="utf-8" />
<script src="https://cdn.rawgit.com/konvajs/konva/2.2.2/konva.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
background-color: #000000;
}
#menu {
width: 20%;
float: left;
background-color: #000020;
color: white;
display: inline-block;
font-family: sans-serif;
display: inline-block;
}
#menu-interior {
min-height: 100%;
max-height: 100%;
height: 100%;
overflow: auto;
margin: 5px 20px;
}
#menu h2 {
clear: both;
font-size: 100%;
}
#menu p {
font-size: 50%;
}
#menu ul {
font-size: 60%;
padding-left: 10px;
}
ul#useful-links {
padding: 0 0 10px;
}
#useful-links li {
display: inline-block;
float: left;
margin-right: 5px;
}
#useful-links a {
color: yellowgreen;
}
#container {
width: 80%;
float: right;
overflow: hidden;
}
</style>
</head>
<body>
<div id="menu">
<div id="menu-interior">
<ul id="useful-links">
<li><a href="https://www.nexusmods.com/battletech/mods/79">Nexus</a></li>
<li><a href="https://discord.gg/RKFXP9G">Discord Help</a></li>
<li><a href="https://roguetech.gamepedia.com">Wiki</a></li>
<li><a href="https://www.nexusmods.com/Core/Libs/Common/Widgets/PayPalPopUp?user=6191338">Donate</a></li>
</ul>
<h2 id="factions-header">Factions</h2>
<p>click toggles. S+click toggles all others.</p>
<ul id="factions-list"></ul>
<h2 id="active-header">Active Commanders</h2>
<ul id="active-list"></ul>
<h2 id="contested-header">Contested 1h</h2>
<ul id="contested-list"></ul>
</div>
</div>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;
var stage = new Konva.Stage({
container: 'container',
width: width,
height: height,
draggable: true
});
var bgLayer = new Konva.Layer();
var imageObj = new Image();
var backgroundImage = new Konva.Image();
imageObj.onload = function() {
backgroundImage = new Konva.Image({
x: -14000,
y: -19250,
width: 28000,
height: 28000,
image: imageObj,
opacity: 0.2
});
bgLayer.add(backgroundImage);
bgLayer.draw();
};
imageObj.src = 'https://i.imgur.com/edbWS4P.jpg';
stage.add(bgLayer);
// "Loading" lavel
var statusLayer = new Konva.Layer();
// create label
var stLabel = new Konva.Label({
x: 100,
y: 100,
draggable: true
});
// add text to the label
stLabel.add(new Konva.Text({
text: 'Connecting to Comstar...',
fontSize: 50,
fontFamily: 'Calibri',
lineHeight: 1.2,
padding: 10,
fill: 'gray'
}));
statusLayer.add(stLabel);
statusLayer.draw();
stage.add(statusLayer);
var tooltipLayer = new Konva.Layer();
var tooltip = new Konva.Label({
opacity: 0.75,
visible: false,
listening: false
});
tooltip.add(new Konva.Tag({
fill: 'white',
pointerDirection: 'down',
pointerWidth: 10,
pointerHeight: 10,
lineJoin: 'round',
shadowColor: 'gray',
shadowBlur: 10,
shadowOffset: 10,
shadowOpacity: 0.2
}));
tooltip.add(new Konva.Text({
text: '',
fontFamily: 'Calibri',
fontSize: 18,
padding: 5,
fill: 'black'
}));
tooltipLayer.add(tooltip);
stage.on('mouseover mousemove dragmove', function(evt) {
var node = evt.target;
if (node && node.nodeType == "Shape" && node != backgroundImage) {
// update tooltip
var scale = stage.scaleX();
var mousePointTo = {
x: stage.getPointerPosition().x / scale - stage.x() / scale,
y: stage.getPointerPosition().y / scale - stage.y() / scale,
};
tooltip.position({
x : mousePointTo.x,
y : mousePointTo.y - 5
});
var newText = node.getId();
window.lastnode = node;
var controllingFactions = node.getAttrs().factions;
if (!controllingFactions.length) {
console.log('no controlling factions for state ${i}:${state[i].name}');
}
for (var i = 0; i < controllingFactions.length; i++) {
var faction = controllingFactions[i];
newText = newText + `\n${wFactions[faction.faction].name}: ${faction.percentage}%`;
}
tooltip.children[1].setText(newText);
tooltip.show();
tooltipLayer.batchDraw();
}
});
stage.on('mouseout', function(evt) {
tooltip.hide();
tooltipLayer.draw();
});
var factionLayers = {};
const SpecialSystems = ["Terra", "Solaris", "Galatea", "Luthien", "New Avalon", "Sian", "Atreus (FWL)", "Rasalhague", "St. Ives", "Oberon", "Taurus", "Canopus", "Alpheratz", "Circinus", "Alphard (MH)", "Lothario", "Coromodir", "Tharkad", "Asturias", "Far Reach", "Albion (Clan)", " Zara(Homer 2850 +)", "Tamaron", "Strato Domingo", "Shadow", "Arcadia (Clan)", "Dagda (Clan)", "Kirin", "Hector", "Ironhold", "Barcella", "Strana Mechty", "Huntress", "Lum", "Sheridan (Clan)", "New Kent", "Tiber (Clan)", "New Delphi", "Blackbone (Nyserta 3025+)", "Bremen (HL)", "Trondheim (JF)", "Tortuga Prime", "Gotterdammerung", "Thala"];
function addSystem (system, contested, layer) {
var special = SpecialSystems.includes(system.name);
var hoverNode = new Konva.Circle({
x: system.x,
y: system.y,
radius: special ? 8 : 5,
id: system.name,
factions: system.factions,
fill: "black",
opacity: 0
});
layer.add(hoverNode);
if (contested) {
var contestedNode = new Konva.Circle({
x: system.x,
y: system.y,
radius: special ? 8 : 4,
fill: "rgba(255,0,0, 0.45)",
id: system.name,
factions: system.factions
});
layer.add(contestedNode);
} else {
var bloomNode = new Konva.Circle({
x: system.x,
y: system.y,
radius: special ? 6 : 3,
fillRadialGradientStartPoint: 0,
fillRadialGradientStartRadius: 0,
fillRadialGradientEndPoint: 0,
fillRadialGradientEndRadius: special ? 5.5 : 2.5,
fillRadialGradientColorStops: [1, 'rgba(0,0,0,0)', 0.5, system.color],
id: system.name,
factions: system.factions
});
layer.add(bloomNode);
}
var node = new Konva.Circle({
x: system.x,
y: system.y,
radius: special ? 3 : 1,
fill: system.color,
id: system.name,
factions: system.factions
});
layer.add(node);
}
const EndPoints = {
"State": "http://roguetech.org:8001/warServices/StarMap/",
"Mission": "http://roguetech.org:8001/warServices/Mission/Results/?MinutesBack=60&MaxResults=300"
};
const ActiveLastHourEndpoint = "http://roguetech.org:8001/warServices/Users/Active/?MinutesBack=60";
const ActiveLastDayEndpoint = "http://roguetech.org:8001/warServices/Users/Active/?MinutesBack=1440";
const ContestedColor = [255, 0, 0];
function getSystems () {
return fetch("systems.json").then(response => response.json());
};
function getFactions () {
return fetch("factions.json").then(response => response.json()).then(json => normalizeFactions(json));
};
function normalizeFactions (factionSet) {
for (var factionId in factionSet) {
factionSet[factionId].controlCount = 0;
}
return factionSet;
}
function getCurrentState () {
return fetch(EndPoints["State"]).then(response => response.json()).then(json => json["systems"]);
}
function getMissionResults () {
return fetch(EndPoints["Mission"]).then(response => response.json());
}
function getActiveLastHour () {
return fetch(ActiveLastHourEndpoint).then(response => response.json());
}
function getActiveLastDay () {
return fetch(ActiveLastDayEndpoint).then(response => response.json());
}
function determineFactionColor (state, factions)
{
var factionId = state.controlList[0].faction;
var color = factions[factionId].color;
color = [color[0]*255, color[1]*255, color[2]*255];
return `rgb(${color[0]},${color[1]},${color[2]})`;
}
function drawContestedSystemNames (contestedSystems) {
var header = document.getElementById("contested-header");
header.appendChild(document.createTextNode(` (${contestedSystems.length})`));
var container = document.getElementById("contested-list");
contestedSystems.sort((a,b) => b.active - a.active);
for (var i = 0; i < contestedSystems.length; i++) {
var li = document.createElement("li");
var text = document.createTextNode(`${contestedSystems[i].name} - ${contestedSystems[i].active} active commander${contestedSystems[i].active != 1 ? 's' : ''}`);
li.appendChild(text);
container.appendChild(li);
}
};
function drawActiveCounts (activeCounts) {
var container = document.getElementById("active-list");
for (var i = 0; i < activeCounts.length; i++) {
var count = activeCounts[i];
var li = document.createElement("li");
var text = document.createTextNode(`Last ${count.timespan}: ${count.count}`);
li.appendChild(text);
container.appendChild(li);
}
}
var exclusiveVisible = true;
function drawFactionGlossary (factions) {
var sorted = [];
for(var f in factions) {
if (f == "1") continue; // we handle abandoned faction below
if (f == "17") continue; // we handle the planetary govt below
if (f == "9999") continue; // we handled the "FIX-ME" faction below
sorted.push({id: f, c: factions[f].controlCount});
}
var factionToggler = function(event) {
if (event.shiftKey) {
// hide everything except currently clicked faction
for (layer in factionLayers) {
if (this == layer) continue;
if (exclusiveVisible) {
factionLayers[layer].hide();
} else {
factionLayers[layer].show();
}
}
exclusiveVisible = !exclusiveVisible
} else {
// hide just currently clicked faction
factionLayers[this].isVisible() ? factionLayers[this].hide() : factionLayers[this].show();
}
};
sorted.sort((a,b) => b.c - a.c);
sorted.push({id: "17", c: factions["17"].controlCount}); // put planetary govt near the bottom of the list
sorted.push({id: "1", c: factions["1"].controlCount}); // put abandoned at the bottom of the list
if (factions["9999"].controlCount > 0)
sorted.push({id: "9999", c: factions["9999"].controlCount}); // conditionally add FIX-ME to very bottom if they exist
var container = document.getElementById("factions-list");
for (var i = 0; i < sorted.length; i++) {
var fId = sorted[i].id;
var li = document.createElement("li");
var factionColor = factions[fId].color;
li.style.color = `rgb(${factionColor[0] * 255}, ${factionColor[1] * 255}, ${factionColor[2] * 255})`
var text = document.createTextNode(factions[fId].name);
var span = document.createElement("span");
span.style.color = "white";
var count = document.createTextNode(` (${sorted[i].c})`);
span.appendChild(count);
li.appendChild(text);
li.appendChild(span);
container.appendChild(li);
li.addEventListener(
"click",
factionToggler.bind(fId),
false
);
}
};
function getSetupData () {
return Promise.all([getSystems(), getFactions(), getCurrentState(), getMissionResults(), getActiveLastHour(), getActiveLastDay()]);
};
var wSystems, wFactions, wState, wMissionResults;
getSetupData()
.then(([systems, factions, state, missionResults, activeLastHour, activeLastDay]) => {
wSystems = systems;
wFactions = factions;
wState = state;
wMissionResults = missionResults;
var contestedSystems = [];
var systemsWithActivity = missionResults.map(x => x.system);
var layer;
var contestedLayer = new Konva.Layer();
for(var i = 0; i < state.length; i++) {
var j = systems.findIndex(x => x.name === state[i].name);
if (j === -1) {
console.log(`couldn't find match for state ${i}:${state[i].name}`);
}
if (state[i] === undefined) {
state[i] = {
activePlayers: 0,
name: systems[j],
controlList: [{ faction: 9999, percentage: 100 }]
}
}
state[i].controlList.sort((a,b) => b.percentage - a.percentage);
var contestingFactions = state[i].controlList.filter(x => x.percentage > 0);
var contested =
contestingFactions.length > 1 &&
systemsWithActivity.includes(systems[j].name);
var controllingFaction;
if (contestingFactions.length == 0) { contestingFactions = [state[i].controlList[0]]; } // deal with abandoned: 0
controllingFaction = contestingFactions[0].faction;
if (factions[controllingFaction] == undefined)
console.log(`faction missing: ${controllingFaction}`);
factions[controllingFaction].controlCount++;
var color = determineFactionColor(state[i], factions);
var drawableSystem = { x: parseInt(systems[j].x), y: parseInt(-systems[j].y), color: color, name: systems[j].name, factions: contestingFactions };
if (contested) {
layer = contestedLayer;
} else {
if (!factionLayers[controllingFaction]) {
factionLayers[controllingFaction] = new Konva.Layer();
}
layer = factionLayers[controllingFaction];
}
addSystem(drawableSystem, contested, layer);
if (contested) {
contestedSystems.push({name: systems[j].name, active: state[i].activePlayers})
}
}
for (var factionId in factionLayers) {
stage.add(factionLayers[factionId]);
}
stage.add(contestedLayer);
drawFactionGlossary(factions);
drawActiveCounts(
[
{"timespan": "Day", "count": activeLastDay},
{"timespan": "Hour", "count": activeLastHour}
]);
drawContestedSystemNames(contestedSystems);
stage.position({x: 600, y: 400});
stage.add(tooltipLayer);
stage.batchDraw();
statusLayer.visible(false);
statusLayer.draw();
var scaleBy = 1.25;
var prevTime = new Date().getTime();
var timedScale = function (e) {
if (!stage.getPointerPosition()) {
return;
}
e.preventDefault();
var curTime = new Date().getTime();
if(typeof prevTime !== 'undefined'){
var timeDiff = curTime - prevTime;
if (timeDiff > 100) {
var oldScale = stage.scaleX();
var mousePointTo = {
x: stage.getPointerPosition().x / oldScale - stage.x() / oldScale,
y: stage.getPointerPosition().y / oldScale - stage.y() / oldScale,
};
var newScale = e.deltaY > 0 ? oldScale / scaleBy : oldScale * scaleBy;
stage.scale({ x: newScale, y: newScale });
var newPos = {
x: -(mousePointTo.x - stage.getPointerPosition().x / newScale) * newScale,
y: -(mousePointTo.y - stage.getPointerPosition().y / newScale) * newScale
};
stage.position(newPos);
stage.batchDraw();
}
}
prevTime = curTime;
}
window.addEventListener("wheel", timedScale);
}).catch((err) => {
console.log(err);
upLabelText = stLabel.getText()
upLabelText.setAttr("text", "Unable to connect to server. Try again later.");
statusLayer.draw();
});
</script>
</body>
</html>