-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
2092 lines (1654 loc) · 58.9 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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<title>Joric's Stalker</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta name="mobile-web-app-capable" content="yes">
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512'%3E%3Cpath d='M464 256A208 208 0 1 0 48 256a208 208 0 1 0 416 0zM0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zm306.7 69.1L162.4 380.6c-19.4 7.5-38.5-11.6-31-31l55.5-144.3c3.3-8.5 9.9-15.1 18.4-18.4l144.3-55.5c19.4-7.5 38.5 11.6 31 31L325.1 306.7c-3.2 8.5-9.9 15.1-18.4 18.4zM288 256a32 32 0 1 0 -64 0 32 32 0 1 0 64 0z'/%3E%3C/svg%3E" />
<meta property="og:image" content="https://joric.github.io/stalker/images/thumbnail.jpg" />
<meta property="og:site_name" content="Joric" />
<meta property="og:type" content="object" />
<meta property="og:title" content="Joric's Stalker" />
<meta property="og:description" content="Interactive Map" />
<link rel="stylesheet" href="css/main.css" />
<link href="js/lib/font-awesome/css/all.min.css" rel="stylesheet">
<link href="js/lib/maptalks-gl/maptalks.css" rel="stylesheet">
<script type="text/javascript" src="js/lib/maptalks-gl/maptalks-gl.js"></script>
<script type="text/javascript" src="js/lib/fuse/fuse.js"></script>
</head>
<body>
<div id="rank-selector">
<select>
</select>
</div>
<div id="language-selector">
<select>
</select>
</div>
<div tabindex=0 id="map"></div>
<div class="search-container">
<div class="search-box">
<input tabindex=1 type="text">
<span class="search-icon search-submit" title="Search">🔍︎</span>
<span class="search-icon search-cancel" title="Cancel">×</span>
</div>
<div class="dropdown-container scrollbar">
<ul class="dropdown"></ul>
</div>
</div>
<div id="map-tooltip" class="arrow-left"></div>
<template id="popup-template">
<div id="popup" class="popup">
<div class="popup-content-wrapper">
<div class="popup-content">
<div id="popup-title">Popup Title</div>
<div id="popup-subtitle">Popup Subtitle</div>
<div id="popup-note">Popup Note</div>
<div id="popup-subnote" class="collapsed">Popup Subnote</div>
<div id="popup-data" class="collapsed"></div>
<div id="popup-data-toggle" data-toggle="collapse" data-target="popup-data"><hr/></div>
<div class="popup-controls">
<input id="popup-found" type="checkbox">
<label id="popup-found-label" for="popup-found" title="Toggle found">Found</label>
<a class="popup-link" id="popup-wiki-link" href="#" target="_blank" title="Fallout London Wiki"><i class="fa fa-brands fa-wikipedia-w"></i></a>
<a class="popup-link" id="popup-map-link" href="#" target="_blank" title="Copy Map Link to Clipboard"><i class="fa fa-link"></i></a>
<a class="popup-link" id="popup-form-id-link" href="#" target="_blank" title="Copy Marker SID to Clipboard"><i class="fa fa-hashtag"></i></a>
<a class="popup-link" id="popup-marker-id-link" href="#" target="_blank" title="Copy Marker Location to Clipboard"><i class="fa fa-location-crosshairs"></i></a>
</div>
</div>
</div>
<div class="popup-tip-container"><div class="popup-tip"></div></div>
<a id="popup-close" class="popup-close-button">×</a>
</div>
</template>
<div id="alert" class="closed">Copied To Clipboard</div>
<script>
let maxZoom = 19;
let enableAltitude = false;
let heightFactor = 1.0;
let iconSize = 48;
let startPitch = 0;
let startZoom = 2;
let defaultPitch = 45;
let autoAltitude = true;
let textSize = 18;
let labelGroups = ['regions'];//, 'locations'];
let zoomGroups = {
'polygons':[-99,99], 'regions':[-99,2],
'hubs': [2,99], 'bases': [2,99],
'circles':[2,6], 'locations': [2,99],
'actors': [3,99], 'lines':[3,99],
'stashes':[4,99],
'items':[5,99], 'enemies':[6,99], 'anomalies':[6,99],
'misc':[7,99],
'helpers': [8,99],
};
let foundOpacity = 0.25;
let arrowStyle = [2,3];
let scaleZ = 0.1; // postprocess coordinates beacuse enableAltitude and heightFactor doesn't seem to work at all
//weird shit's happening. lines seem to be flat rectangles so they dissapear at certain camera angles
let enableTeleportLines = true;
let enableHeightLines = false;
let enableActorLines = true;
let enableItemLines = true;
let lineWidth = 2;
let lineColor = '#fff';
let tooltipShowTimer = null;
let tooltipHideTimer = null;
let tooltipHideDelay = 1;
let tooltipShowDelay = 1;
let groupLayer = null;
let map = null;
let types = {};
let icons = {};
let lang = {};
let markers = {};
let regions = {};
let actors_lookup = {};
let items_lookup = {};
let mapParam = {};
let markersData = null;
let regionsData = null;
let tileset_base = location.protocol === 'file:' ? '../stalker2_tileset' : 'https://joric.github.io/stalker2_tileset';
let localDataName = 'joricsStalkerMapsGL';
let localData = JSON.parse(localStorage.getItem(localDataName))||{};
let mapId = 's2hoc';
let searchInput = null;
let dropdownContainer = null;
let localImages = {};
let firstRun = false;
const capitalize = s => s[0].toUpperCase()+s.slice(1);
const cmpAlphaNum = (a,b) => a[0].localeCompare(b[0], 'en', { numeric: true });
function scaleCoordinate(c) {
return scaleZ < 1.0 ? {x: c.x, y:c.y, z:c.z*scaleZ} : c;
}
function scaleCoordinateArray(c) {
return scaleZ < 1.0 ? [ c[0], c[1], c[2]*scaleZ] : c;
}
class CustomTooltip extends maptalks.ui.ToolTip {
constructor(options) {
super(options);
}
/*
buildOn() {
// Create a DOM element for the tooltip
const tooltip = document.createElement('div');
tooltip.className = 'custom-tooltip';
tooltip.innerHTML = this.options.content;
return tooltip;
}
getOffset() {
// Adjust the offset of the tooltip relative to the marker
return new maptalks.Point(0,0);
}
*/
}
function loadMap() {
if (!localData[mapId]) {
localData[mapId] = { language: 'en', activeItems: {'bases':true, 'hubs': true, 'locations': true, 'stashes': true, 'regions': true, 'items': true, 'enemies': true, 'circles': true, 'polygons': true} };
}
if (!localData[mapId].markedItems) {
localData[mapId].markedItems = {};
}
settings = localData[mapId];
settings.baseLayer = settings.baseLayer || 'PDA';
settings.language = settings.language || 'en';
settings.searchText = settings.searchText || '';
settings.rank = settings.rank || 'Master';
searchInput = document.querySelector('.search-box input');
searchInput.value = settings.searchText || '';
dropdownContainer = document.querySelector(".dropdown-container");
//console.log('current zoom:', settings.zoom);
let scrollWheelZoom = true; // maptalks uses fractional zoom by default
//let scrollWheelZoom = false;
let w = h = 812900;
let center = [w/2, h/2];
let [left,top,right,bottom] = [0, 0, w, h];
let tileSize = 512;
if (!settings.center) {
[settings.zoom, settings.pitch, settings.bearing, settings.center] = [startZoom, startPitch, 0, center];
}
map = new maptalks.Map('map', {
heightFactor: heightFactor,
zoom: settings.zoom,
pitch: settings.pitch,
bearing: settings.bearing,
center: settings.center,
maxPitch: 80,
maxZoom: maxZoom,
scrollWheelZoom: scrollWheelZoom,
spatialReference : {
projection : 'identity',
fullExtent : { top: top, left: left, bottom: bottom, right: right }, // mandatory to hide 404
resolutions: Array.from({length: maxZoom + 1},(_,i) => w / tileSize / (1<<i)), // mandatory zoom levels
},
baseLayer: new maptalks.GroupTileLayer('Base TileLayer', [
new maptalks.TileLayer('PDA', {
maxAvailableZoom: 7,
urlTemplate: `${tileset_base}/tiles/{z}/{x}/{y}.jpg`,
repeatWorld: false,
tileSize: 512,
visible: settings.baseLayer == 'PDA',
}),
new maptalks.TileLayer('GlobalMap', {
maxAvailableZoom: 5,
urlTemplate: `${tileset_base}/extras/wb/{z}/{x}/{y}.jpg`,
repeatWorld: false,
tileSize: 512,
visible: settings.baseLayer == 'GlobalMap',
}),
new maptalks.TileLayer('LDScheme', {
maxAvailableZoom: 3,
urlTemplate: `${tileset_base}/extras/ld/{z}/{x}/{y}.png`,
repeatWorld: false,
tileSize: 512,
visible: settings.baseLayer == 'LDScheme',
}),
]),
zoomControl: {
//position : 'bottom-right',
//position : 'top-right',
position : {bottom: 70, right: 20},
zoomLevel : false,
},
//seamlessZoom: true,
doubleClickZoom: false,
//maxExtent: extent,
/*
// overview is broken, due to a flat projection I guess
overviewControl: {
position: 'bottom-left',
size: [240,135],
level: 10,
symbol: {
'lineColor': '#fff', // Border color
'lineWidth': 1.5, // Border width
'polygonFill': '#fff', // Fill color
'polygonOpacity': 0.0, // Fill opacity
'lineOpacity': 0.5,
},
},
*/
attribution: {
//position: {top: -50},
},
});
// Function to handle zooming
function handleZoom(event) {
event.preventDefault(); // Prevent the default scroll behavior
const currentZoom = map.getZoom();
const zoomStep = 1; // Define the zoom step
if (event.deltaY < 0) {
// Scroll up, zoom in
map.setZoom(currentZoom + zoomStep);
} else {
// Scroll down, zoom out
map.setZoom(currentZoom - zoomStep);
}
}
// Add event listener for mouse wheel
if (!scrollWheelZoom) map.getContainer().addEventListener('wheel', handleZoom);
map.on('viewchange', e=> {
settings.center = [e.new.center[0],e.new.center[1]];
settings.bearing = e.new.bearing;
settings.pitch = e.new.pitch;
settings.zoom = e.new.zoom;
if (enableAltitude && autoAltitude) {
groupLayer.setOptions({enableAltitude: map.getPitch()!=0});
}
//console.log('zoom', settings.zoom);
saveSettings();
});
let gap = w/2;
let extent = new maptalks.Extent(left-gap, top-gap, right+gap, bottom+gap);
map.setMaxExtent(extent);
new maptalks.TileLayer('Stalker1', {
maxAvailableZoom: 3,
urlTemplate: `${tileset_base}/extras/s1/{z}/{x}/{y}.png`,
repeatWorld: false,
tileSize: 512,
visible : false,
}).addTo(map);
groupLayer = new maptalks.GroupGLLayer('Features',[], {
enableAltitude: enableAltitude,
sortByDistanceToCamera: true,
forceRenderOnMoving: true,
forceRenderOnRotating: true,
}).addTo(map);
setTimeout(function() {
if (enableAltitude && autoAltitude) {
groupLayer.setOptions({enableAltitude: map.getPitch()!=0});
}
},500);
document.querySelector('.search-cancel').onmousedown = (event) => {
//event.preventDefault(); document.activeElement === searchInput && searchInput.focus(); // messes up mobile
clearFilter();
saveSettings();
updateView();
};
document.querySelector('.search-submit').onmousedown = (event) => {
event.preventDefault(); document.activeElement === searchInput && searchInput.focus();
updateSearch(searchInput.value||'', false);
};
map.on('mousedown touchstart', function(e) {
document.getElementById('map').focus(); // needs tabindex on the map element
dropdownContainer.style.display = "none";
});
map.on('moving', hideTooltip);
map.on('zooming', e=>{
hideTooltip();
updateView();
});
map.on('zoomend', e=>{
updateView();
});
map.on('setbaselayer', e=> {
let layers = map.getBaseLayer().getLayers();
for (layer of layers) {
if (layer.isVisible()) {
settings.baseLayer = layer.getId();
}
}
saveSettings();
});
}
function addLine(marker, target, c) {
let pt = target ? target.getCoordinates() : scaleCoordinate( {x: c[0], y: c[1], z: c[2]} );
let line = new maptalks.LineString([marker.getCoordinates(), pt],{arrowStyle:arrowStyle, symbol:{lineColor: lineColor, lineWidth: lineWidth}});
line.feature = marker.feature;
return line;
}
function addLines(markers) {
let geometry = [];
for (m of markers) {
let marker = m.marker;
let o = marker.feature.properties;
if (enableTeleportLines && o.target) {
geometry.push( addLine(marker, null, m.marker.feature.properties.target) );
}
if (enableHeightLines) {
let c = m.marker.getCoordinates();
geometry.push( addLine(marker, null, [c.x,c.y,0] ) );
}
if (enableActorLines) {
let target = actors_lookup[o.uaid];
if (target) {
geometry.push( addLine(marker, target) );
}
}
if (enableItemLines) {
let group = items_lookup[o.name];
if (group && o.name != 'Vodka') {
for (target of group) {
// the big issue here is that target may be invisible, needs fixing lines vs zoom levels
// limit line length here
let a = marker.getCoordinates();
let b = target.getCoordinates();
let dist = Math.sqrt(Math.pow(a.x-b.x,2)+Math.pow(a.y-b.y,2)+Math.pow(a.z-b.z,2));
if (dist < 50000) geometry.push( addLine(marker, target) );
}
}
}
}
let layerId = 'Lines'
let visible = settings.activeItems[layerId.toLowerCase()] == true;
let layer = new maptalks.LineStringLayer(layerId, geometry, { visible: visible, sceneConfig: { depthFunc: '<='} });
addHandler(layer);
layer.addTo(groupLayer);
}
function addCircles(markers) {
let geometry = [];
const defaultSymbol = {
'lineColor': '#fff', // Border color
'lineWidth': 2.5, // Border width
'polygonFill': '#fff', // Fill color
'polygonOpacity': 0.1, // Fill opacity
'lineOpacity': 0.85,
};
for (m of markers) {
let o = m.marker.feature.properties;
if (o.radius) {
let color = o.type.includes('Hub') ? '#e8a514' : '#fff';
//let numberOfShellPoints = Math.min(60, ~~(o.radius / 200));
var circle = new maptalks.Circle(m.marker.getCoordinates(), o.radius, {
symbol: {...defaultSymbol, lineColor: color, polygonFill: color},
properties: {
//numberOfShellPoints: numberOfShellPoints,
},
});
geometry.push(circle);
circle.feature = m.marker.feature;
}
}
let layerId = 'Circles'
let visible = settings.activeItems[layerId.toLowerCase()] == true;
let layer = new maptalks.PolygonLayer(layerId, geometry, { visible: visible });
addHandler(layer);
layer.addTo(groupLayer);
}
function addMarkers(data) {
console.timeEnd('markers');
console.log('Total markers:', data.length);
markersData = data;
addLines(data);
addRegions(regions);
addCircles(data);
// join markers by group name
let collection = {};
for (m of data) {
if (!collection[m.group]) collection[m.group] = [];
collection[m.group].push(m.marker);
}
let weights = {'regions': 1100, 'hubs': 1000, 'bases': 900, 'locations': 750, 'stashes': 500, 'items': 250, 'anomalies': -900, 'misc': -1000 };
let groups = Object.keys(collection);
groups = groups.sort( (a,b)=> (weights[b]||0)-(weights[a]||0) || cmpAlphaNum(a,b))
//console.log('sorted groups', groups);
for (const group of groups) {
let layerName = capitalize(group);
let geometries = collection[group];
let visible = settings.activeItems[group] == true;
layer = new maptalks.PointLayer(layerName, geometries, {
enableAltitude: enableAltitude,
sortByDistanceToCamera: true,
forceRenderOnMoving: true,
forceRenderOnRotating: true,
visible: visible,
sceneConfig: { depthFunc: '<='},
}).addTo(groupLayer);
//console.log('created layer', group, 'visible', settings.activeItems[group], geometries.length, 'markers');
addHandler(layer);
}
let LayerSwitcher = new maptalks.control.LayerSwitcher({
position : 'bottom-left',
baseTitle : 'Base Layers',
overlayTitle : 'Overlays',
containerClass : 'maptalks-layer-switcher',
}).addTo(map);
let name = mapParam.markerName;
if (name) {
mapParam = {};
settings.searchText = name;
}
updateSearch(settings.searchText);
}
function findLocation(id) {
for (m of markersData) {
let marker = m.marker;
let o = marker.feature.properties;
if (id == o.sid) {
return marker;
}
}
}
function jumpToLocation(name) {
let marker = findLocation(name);
if (marker) {
//map.setView({center: marker.getCoordinates(), zoom:8, pitch:0, bearing:0}); // don't change zoom maybe
map.setView({center: marker.getCoordinates()}); // don't change zoom maybe
marker.show();
popupOnClick({target: marker});
marker.openInfoWindow();
}
}
// doesn't work in safari
function loadMarkersIdle(data) {
const features = data.features;
let currentIndex = 0;
let result = [];
function processBatch(deadline) {
batch = [];
while (deadline.timeRemaining() > 0 && currentIndex < features.length) {
let marker = addMarker(features[currentIndex]);
if (marker) {
batch.push(marker);
}
currentIndex++;
}
//console.log(`Processed ${currentIndex}/${features.length} markers`);
if (currentIndex < features.length) {
result.push(...batch);
requestIdleCallback(processBatch); // Schedule the next batch during idle time
} else {
result.push(...batch);
addMarkers(result);
}
}
requestIdleCallback(processBatch, { timeout: 1000 });
}
function loadMarkersBatched(data) {
const features = data.features;
const batchSize = 5000;
let currentIndex = 0;
let result = [];
function processBatch() {
const batch = [];
const endIndex = Math.min(currentIndex + batchSize, features.length);
for (; currentIndex < endIndex; currentIndex++) {
let marker = addMarker(features[currentIndex]);
if (marker) {
batch.push(marker);
}
}
result.push(...batch);
if (currentIndex < features.length) {
setTimeout(processBatch, 0); // Allow time for browser events
} else {
addMarkers(result);
}
}
setTimeout(processBatch, 0); // Start processing asynchronously
}
function loadMarkersSimple(data) {
let result = []
for (const feature of data.features) {
let marker = addMarker(feature);
if (marker) result.push(marker);
}
addMarkers(result);
}
function loadMarkers(data) {
markers = data;
console.time('markers');
loadMarkersBatched(data);
//loadMarkersSimple(data);
}
function addHandler(layer) {
const originalShow = layer.show;
const originalHide = layer.hide;
// Override the show method
layer.show = function () {
// Call the original show method
originalShow.call(this);
// Fire a custom 'visibilitychange' event
this.fire('visibilitychange', { visible: true });
};
// Override the hide method
layer.hide = function () {
// Call the original hide method
originalHide.call(this);
// Fire a custom 'visibilitychange' event
this.fire('visibilitychange', { visible: false });
};
// Listen for the custom 'visibilitychange' event
layer.on('visibilitychange', function (e) {
let group = e.target.getId().toLowerCase();
let show = e.visible;
if (show) {
settings.activeItems[group] = true;
} else {
delete settings.activeItems[group];
}
//console.log(settings);
saveSettings();
});
}
function clearSelection() {
if (window.getSelection) {
// Modern browsers
const selection = window.getSelection();
if (selection.removeAllRanges) {
selection.removeAllRanges();
} else if (selection.collapseToEnd) {
// For older WebKit browsers
selection.collapseToEnd();
}
} else if (document.selection) {
// Older versions of Internet Explorer
document.selection.empty();
}
}
function translate_item(name, description=false) {
let postfix = description ? 'description': 'name';
name = (name||'').replace('Antirad','AntiRad');
let title = lang[`sid_items_${name}_${postfix}`] || lang[`sid_questItemprototypes_${name}_${postfix}`];
if (!title) {
let proto = markers.prototypes[name];
if (proto) {
let lsid = proto.lsid;
if (lsid) {
title = lang[`sid_upgrades_${lsid}_${postfix}`] || lang[`sid_questItemprototypes_${lsid}_${postfix}`];
}
}
}
return title || name;
}
function setClass(e, set, c) { set ? e.classList.add(c) : e.classList.remove(c);}
function toggleClass(e, c) { if (e.classList.contains(c)) { e.classList.remove(c); return false; } else { e.classList.add(c); return true; }}
function toggleNav(e) { let input = document.querySelector('#search-input'); toggleClass(e.parentElement, 'closed') ? input.blur() : input.focus();}
function toggleVisibility(a) { [].forEach.call(a, function(e) { toggleClass(document.querySelector(e), 'collapsed'); }) }
const cmpNum = (a,b)=> b[1]!=a[1] ? (b[1]-a[1]) : a[0].localeCompare(b[0]);
function copyToClipboard(text) {
let input = document.body.appendChild(document.createElement("input"));
input.value = text;
input.focus();
input.select();
document.execCommand('copy');
input.parentNode.removeChild(input);
document.getElementById('alert').classList.remove('closed');
setTimeout(function(e){ document.getElementById('alert').classList.add('closed') },1500);
}
function canonical(id) {
return id ? id.slice(2) : '';
}
function getBaseURL() {
return window.location.href.replace(/#.*$/,'');
}
function getMapURL(id) {
return getBaseURL() + '#' + encodeURIComponent(id);
}
function getWikiURL(title) {
if (title.startsWith('«') && title.endsWith('«')) title = title.slice(1,-1);
//title = title.split(' ').map(capitalize).join(' ')
return wikiPrefix + (settings.language=='en' ? '': settings.language+'/') + 'wiki/' + encodeURIComponent(title);
}
function wikify(o) {
let location_id = o.title;
return location_id.replace(/[^A-Za-z0-9\s]/g, '').trim().replace(/\s+/g, '_');
}
let wikiPrefix = 'https://stalker.fandom.com/';
let copyLink = e=>{ copyToClipboard(e.target.href); return false; };
function renderPhoto(o) {
if (!o.material) {};
let lookup = {
'MI_pos_photos_01_a_01': 1,
'MI_pos_photos_01_a_02': 1,
'MI_pos_photos_01_b_01': 2,
'MI_pos_photos_01_b_02': 2,
};
let t = lookup[o.material];
if (!t) return {};
let i = o.image_index || 0;
let iw = ih = 4096;
let cw = 14;
let ch = 10;
let cx = ~~(i%cw);
let cy = ~~(i/cw);
let w = ~~(iw/cw);
let h = ~~(ih/ch);
let x = Math.round(iw * cx / cw);
let y = Math.round(ih * cy / ch);
let idx = (t-1) * cw * ch + i + 1;
let title = lang[`sid_misc_QIO_Photo`] + ' ' + idx;
let rotated = [24,31,41,46,55,77,82,115,117,132,149,155,158,160,163,177,185,186,196,198,204,215,222,225,233,236,255].includes(idx);
let d = `width:${w}px;height:${h}px;`;
let r = 'transform:translate(-50%,-50%);';
if (rotated) {
r = `transform:translate(-50%,-50%) rotate(-90deg);transform-origin:center;`;
d = `width:${h}px;height:${w}px;`;
}
return {
title: title,
photo: `<div style="${d}"><div style="top:50%;left:50%;position:relative;${r}width:${w}px;height:${h}px;background-image:url(images/photos/T_pos_photos_0${t}_D.jpg);background-position:-${x}px -${y}px"></div></div>`,
}
}
function renderItem(feature, extended=false, verbose=false) {
let o = feature.properties;
let prop = getIconProp(o);
let title = lang[o.title];
let desc = lang[o.description];
if (o.type=='ESpawnType::Item') {
title = title || translate_item(o.name, false);
desc = desc || translate_item(o.name, true);
}
// sid_character_eger_0 is really sid_npc_name_eger_0
title = title || lang[o.title] || lang[o.title && o.title.replace('character','npc_name')] || lang[prop.title] || prop.title || o.name;
desc = desc || lang[o.description] || lang [prop.description] || '';
let group = prop.group || 'misc';
let category = lang[prop.category] || prop.category || group;
let location = '';
if (o.lsid) {
title = lang[`sid_questItemprototypes_${o.lsid}_name`];
description = lang[`sid_questItemprototypes_${o.lsid}_description`];
}
if (o.clue) {
title = lang[`sid_stashes_${o.clue}_name`];
description = lang[`sid_stashes_${o.clue}_description`];
}
let info = {
title: title || category || o.type,
category: category,
group: group,
location: location,
description: desc,
prop: prop,
};
info = {...info, ...renderPhoto(o) };
if (!extended) return info; // region markers need title
if (!feature.geometry) return info;
let c = feature.geometry.coordinates;
//let teleport = `${c[0]} ${c[1]} ${c[2]}`;
//let location = `XTeleportTo ${teleport}`
let currentRegion = getRegionName({x: c[0], y:c[1], z:c[2]}, regionsData);
info.location = lang[`sid_locations_region_${currentRegion}_name`];
if (o.references) {
for (const name of o.references) {
if (name.includes('SetQuestGiver')) {
const quest = name.split('_SetQuestGiver')[0].replace('_P','');
let title = lang[`sid_journal_${quest}_Name`];
if (title) {
info.quest = title;
}
}
}
}
if (o.faction) {
let faction = lang[`sid_misc_answer_faction_${o.faction}`] || lang[`sid_misc_faction_${o.faction.toLowerCase()}`] || o.faction;
if (faction) {
info.category = info.category + ' / ' + faction;
}
}
// add items
if (o.items) {
let items = [];
for (const name of o.items) {
items.push(translate_item(name));
}
info.items = items;
}
// we need to group rank-prefixed spawns by rank
// e.g. 3612452147E4E0C44DED9B84F755461F has two Newbie entries
let current_rank = settings.rank;
let diff = 'Normal';
let matching_rank = null;
let rank_score = { 'Newbie': 1, 'Experienced': 2, 'Veteran': 3, 'Master': 4 };
function getGeneratorItems(gen_name, rank, diff) {
let items = [];
if (!markers.generators[gen_name]) {
gen_name = markers.prototypes[gen_name] && markers.prototypes[gen_name].proto;
}
let generators = markers.generators[gen_name]||[];
//console.log(gen_name, generators);
// pre-filter ranks
let best_rank = null;
for (const generator of generators) {
if (generator.rank && rank_score[current_rank] >= rank_score[generator.rank.split('::').pop()]) best_rank = generator.rank;
}
for (const generator of generators) {
if (generator.rank && best_rank && generator.rank!=best_rank) continue;
for (const group of (generator.groups || [])) {
// calculate count of items in pack
let total = 0;
for (const [name, props] of Object.entries(group.items||{})) {
if (group.category!='SubItemGenerator') {
total ++;
}
}
let random_choice = ~~(Math.random()*total);
let count = 0;
for (const [name, props] of Object.entries(group.items||{})) {
if (group.category=='SubItemGenerator') {
items.push(...getGeneratorItems(name, rank, diff));
} else {
// add one random item for now
if (count==random_choice) {
items.push({name: name, generator: gen_name, category: group.category, props: props });
}
count ++;
}
}
}
}
//console.log(items);
return items;
}
if (o.spawns) {
let items = [];
// ranked spawns are structured the way we only have one matching rank
for (name of o.spawns) {
if (name.includes(':')) {
[rank, name] = name.split(':');
if (rank_score[current_rank]>=rank_score[rank]) matching_rank = rank;
}
}
for (name of o.spawns) {
let rank = null;
if (name.includes(':')) {
[rank, name] = name.split(':');
if (rank!= matching_rank) continue;
}
items.push(...getGeneratorItems(name, rank || current_rank, diff));
}
info.groups = items;
}
// add upgrade thingy, if any
if (info.groups) {
for (prop of info.groups) {
let name = prop.name;
let proto = markers.prototypes[name];
if (proto) {
let lsid = proto.lsid;
let title = lang[`sid_upgrades_${lsid}_name`];
let desc = lang[`sid_upgrades_${lsid}_description`];
if (title) {
let items = [];
for (item of (proto.compatible||{})) {
let s = lang[`sid_items_${item}_name`];
if (s) items.push(s);
}
let items_str = items.join(', ');
info.upgrade = `<b>${title}</b><div class="small padded">${items_str}</div>`;
}
if (desc) {
info.upgrade = (info.upgrade||'') + `${desc}`;
}
}
}
}
// add PDA description
if (o.proto && o.proto.startsWith('QuestItem_Note') ) {
let note = lang[`sid_questItemprototypes_${o.name}_description`];
if (note && note != desc) {
info.note = note;
}
}
if (isLocked(o)) info.title = lang['sid_misc_hint_cantopen'];
return info;
}