-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathksaVesselOps.js
1798 lines (1541 loc) · 86.5 KB
/
ksaVesselOps.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
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
// refactor complete
function loadVessel(vessel, givenUT) {
if (!givenUT) givenUT = currUT();
// can't continue if menu data hasn't loaded
if (!isMenuDataLoaded) return setTimeout(loadVessel, 50, vessel, givenUT);
// we can't let anyone jump to a UT later than the current UT
if (givenUT > currUT() && !getCookie("missionctrl")) givenUT = currUT();
// compose the the URL that will appear in the address bar when the history state is updated
var strURL = "http://www.kerbalspace.agency/TrackerDev1/tracker.asp?vessel=" + vessel;
// if the UTs don't match then we are being sent to another time and should add it to the URL
if (givenUT != currUT()) strURL += "&ut=" + givenUT;
// if this is the first page to load, replace the current history, otherwise update it
if (!history.state) history.replaceState({type: "vessel", id: vessel, UT: givenUT}, document.title, strURL);
else history.pushState({type: "vessel", id: vessel, UT: givenUT}, document.title, strURL);
// we changed the DB name for these vessels. Allow old links to still work
if (vessel.includes("ascensionmk1b1")) vessel = vessel.replace("mk1b1", "mk1");
// we need to make sure the current surface map is proper for this vessel
var strParentBody = getParentSystem(vessel);
if (strParentBody == "inactive") {
var soiList = ops.craftsMenu.find(o => o.db === vessel).soi.split("|");
// last element is always the inactive body ID so pop & check the next one
soiList.pop();
var lastSOI = soiList.pop();
strParentBody = ops.bodyCatalog.find(o => o.ID === parseInt(lastSOI.split(";")[1])).Body;
}
if (!ops.surface.Data || (ops.surface.Data && ops.surface.Data.Name != strParentBody.replace("-System", ""))) loadBody(strParentBody);
// select and show it in the menu
selectMenuItem(vessel);
// loading spinners - activate!
$("#infoBox").spin({ position: 'relative', top: '50%', left: '50%' });
$("#contentBox").spin({ position: 'relative', top: '50%', left: '50%' });
$("#dataLabel").html("Loading Data...");
// delete the current vessel data and put out the call for new vessel data
if (ops.currentVessel) {
ops.currentVessel.AscentData.length = 0;
ops.currentVessel.History.length = 0;
ops.currentVessel.LaunchTimes.length = 0;
ops.currentVessel.OrbitalHistory.length = 0;
ops.currentVessel = null;
}
loadDB("loadVesselData.asp?db=" + vessel + "&ut=" + givenUT, loadVesselAJAX);
// add vessel-specific buttons to the map
addMapResizeButton();
addMapViewButton();
// size down the map
lowerContent();
// close any popups
if (vesselPositionPopup && ops.surface.map) ops.surface.map.closePopup(vesselPositionPopup);
// we can't be switching vessels while loading any plot data so if it's in progress, kill it
if (ops.surface.layerControl && !ops.surface.layerControl.options.collapsed) {
isOrbitRenderTerminated = true;
ops.surface.layerControl._collapse();
ops.surface.layerControl.options.collapsed = true;
if (surfaceTracksDataLoad.obtTrackDataLoad) ops.surface.layerControl.removeLayer(surfaceTracksDataLoad.obtTrackDataLoad);
surfaceTracksDataLoad.obtTrackDataLoad = null;
clearSurfacePlots();
}
}
// parses data used to display information on parts for vessels
function loadPartsAJAX(xhttp) {
xhttp.responseText.split("^").forEach(function(item) { partsCatalog.push(rsToObj(item)); });
}
// parses data used to drive the live/replay ascent telemetry
function loadAscentAJAX(xhttp) {
ops.ascentData.telemetry.length = 0;
xhttp.responseText.split("|").forEach(function(item) { ops.ascentData.telemetry.push(rsToObj(item)); });
setupStreamingAscent();
}
// parses data that shows up for the vessel currently selected in the menu
function loadVesselAJAX(xhttp) {
// separate the main data segments
var data = xhttp.responseText.split("Typ3")[1].split("*");
// the vessel catalog data is first
var catalog = rsToObj(data[0]);
// any ascent data available?
var ascentData = [];
if (data[1] != "false") {
// only the start and end times of the ascent data are loaded initially
data[1].split("~").forEach(function(item) { ascentData.push(parseFloat(item)); });
}
// the various tables of the current record are next
var dataTables = data[2].split("^");
var craft = rsToObj(dataTables[0]);
var resources = rsToObj(dataTables[1]);
var crew = rsToObj(dataTables[2]);
var comms = rsToObj(dataTables[3]);
var obt = rsToObj(dataTables[4]);
var ports = rsToObj(dataTables[5]);
// parse and sort the histories and launch times
var history = [];
var launches = [];
var obtHist = [];
data[3].split("|").forEach(function(item) { history.push({UT: parseFloat(item.split("~")[0]), Title: item.split("~")[1]}); });
if (data[4].split("|") != "null") {
data[4].split("|").forEach(function(item) { launches.push({UT: parseFloat(item.split("~")[0]), LaunchTime: parseFloat(item.split("~")[1])}); });
}
if (data[5].split("|") != "null") {
data[5].split("|").forEach(function(item) { obtHist.push({UT: parseFloat(item.split("~")[0]), Period: parseFloat(item.split("~")[1])}); });
}
// store all the data
ops.currentVessel = { Catalog: catalog,
CraftData: craft,
Resources: resources,
Manifest: crew,
Comms: comms,
Ports: ports,
Orbit: obt,
History: history,
LaunchTimes: launches,
OrbitalHistory: obtHist,
AscentData: ascentData };
if (ops.currentVessel.Resources) ops.currentVessel.Resources.resIndex = 0;
// look for the closest recent event to this UT and see if it matches the current craft data to check if it is a past event
var histIndex;
for (histIndex = ops.currentVessel.History.length-1; histIndex >= 0; histIndex--) {
if (ops.currentVessel.History[histIndex].UT <= currUT()) break;
}
if (ops.currentVessel.CraftData.UT < ops.currentVessel.History[histIndex].UT) ops.currentVessel.CraftData.pastEvent = true;
// setup the content header sections
$("#contentHeader").html("<span id='patches'></span> <span id='title'></span> <span id='tags'></span>");
// update with the vessel name for this record
vesselTitleUpdate();
// tag loading
//$("#tags").spin({ scale: 0.35, position: 'relative', top: '10px', left: (((955/2) + (strVesselName.width('bold 32px arial')/2)) + 10) +'px' });
// update the twitter timeline only if the current one loaded isn't already the one we want to load
var thisTimeline = '';
if (ops.currentVessel.Catalog.Timeline) {
thisTimeline = ops.currentVessel.Catalog.Timeline.split(";")[1];
if (!thisTimeline) thisTimeline = ops.currentVessel.Catalog.Timeline;
}
if (thisTimeline != ops.twitterSource) vesselTimelineUpdate();
if (ops.currentVessel.Catalog.Patches) {
// program patch
$("#patches").append("<a target='_blank' href='" + ops.currentVessel.Catalog.Patches.split("|")[0].split(";")[2] + "'><img id='programPatch' class='tipped' data-tipped-options=\"position: 'bottom'\" style='height: 35px;' title=\"<center>Click to view the " + ops.currentVessel.Catalog.Patches.split("|")[0].split(";")[0] + " Program page</center><br /><img style='height: 500px;' src='" + ops.currentVessel.Catalog.Patches.split("|")[0].split(";")[1] + "'>\" src='" + ops.currentVessel.Catalog.Patches.split("|")[0].split(";")[1] + "'></a> ");
// vessel patch has a URL?
if (ops.currentVessel.Catalog.Patches.split("|")[1].split(";").length > 2) {
$("#patches").append("<a target='_blank' href='" + ops.currentVessel.Catalog.Patches.split("|")[1].split(";")[2] + "'><img id='vesselPatch' class='tipped' data-tipped-options=\"position: 'bottom'\" style='height: 35px; cursor: pointer;' title=\"<center>Click to view the " + ops.currentVessel.Catalog.Patches.split("|")[1].split(";")[0] + " vessel page</center><br /><img style='height: 500px;' src='" + ops.currentVessel.Catalog.Patches.split("|")[1].split(";")[1] + "'>\" src='" + ops.currentVessel.Catalog.Patches.split("|")[1].split(";")[1] + "'></a> ");
} else {
$("#patches").append("<img id='vesselPatch' class='tipped' data-tipped-options=\"position: 'bottom'\" style='height: 35px; cursor: help;' title=\"<img style='height: 500px;' src='" + ops.currentVessel.Catalog.Patches.split("|")[1].split(";")[1] + "'>\" src='" + ops.currentVessel.Catalog.Patches.split("|")[1].split(";")[1] + "'> ");
}
// mission patch?
if (ops.currentVessel.Catalog.Patches.split("|").length > 2) {
$("#patches").append("<img id='missionPatch' class='tipped' data-tipped-options=\"position: 'bottom'\" style='height: 35px; cursor: help;' title=\"<img style='height: 500px;' src='" + ops.currentVessel.Catalog.Patches.split("|")[2].split(";")[1] + "'><br /><center>Mission Payload</center>\" src='" + ops.currentVessel.Catalog.Patches.split("|")[2].split(";")[1] + "'> ");
}
}
// no orbit data or mission ended? Close the dialog in case it is open
if (!ops.currentVessel.Orbit || isMissionEnded()) $("#mapDialog").dialog("close");
// is there ascent data available right now?
if (ops.currentVessel.AscentData.length
&& !ops.currentVessel.CraftData.pastEvent // does not apply to past events
&& (ops.currentVessel.AscentData[0]-randomIntFromInterval(20,26) <= currUT() // time is 20-26s prior to start of ascent data
&& ops.currentVessel.AscentData[ops.currentVessel.AscentData.length-1] > currUT() // and time still remains in the ascent data
)) {
loadAscentData();
// dunno why this was called
// vesselInfoUpdate();
}
// just a normal update then
else {
// clear out the ascentID so any real-time updates stop
ascentEnd();
// display all the updateable data
vesselHistoryUpdate();
vesselInfoUpdate();
vesselMETUpdate();
vesselVelocityUpdate();
vesselPeUpdate();
vesselApUpdate();
vesselEccUpdate();
vesselIncUpdate();
vesselPeriodUpdate();
vesselCrewUpdate();
vesselResourcesUpdate();
vesselCommsUpdate();
vesselAddlInfoUpdate();
vesselRelatedUpdate();
vesselLastUpdate();
vesselContentUpdate();
// check if this is a launch event
if (ops.currentVessel.CraftData.CraftDescTitle.toLowerCase().includes("+0:00")
&& ops.currentVessel.CraftData.pastEvent // make sure it happened in the past
&& ops.currentVessel.AscentData.length // make sure there is ascent data
){
$("#dataField13").html("<center><span class='fauxLink' onclick='loadAscentData()'>Ascent Data Available - Click to View</span></center>");
$("#dataField13").fadeIn();
} else $("#dataField13").fadeOut();
// hide the rest of the fields that are unused for now
$("#dataField14").fadeOut();
$("#dataField15").fadeOut();
$("#dataField16").fadeOut();
}
// create the tooltips
// behavior of tooltips depends on the device
if (is_touch_device()) showOpt = 'click';
else showOpt = 'mouseenter';
Tipped.create('.tipped', { showOn: showOpt, hideOnClickOutside: is_touch_device(), detach: false, hideOn: { element: 'mouseleave'} });
Tipped.create('.tip-update', { showOn: showOpt, hideOnClickOutside: is_touch_device(), detach: false, hideOn: { element: 'mouseleave'} });
}
function vesselTimelineUpdate(update) {
// if there are multiple sources and this isn't an update then clear to just the main source
if ($("#twitterTimelineSelection").html().includes("|") && !update) swapTwitterSource();
// only check for an existing mission feed if this is an update call, otherwise it could alredy exist from another craft when only switching vessels
if (ops.currentVessel.Catalog.Timeline) {
// if this timeline is date stamped, don't show it unless we are past the date
if (ops.currentVessel.Catalog.Timeline.split(";").length > 1) {
if (currUT() > parseFloat(ops.currentVessel.Catalog.Timeline.split(";")[0])) {
if (!update || (update && !$("#twitterTimelineSelection").html().includes("Mission Feed"))) {
swapTwitterSource("Mission Feed", ops.currentVessel.Catalog.Timeline.split(";")[1]);
if (update) flashUpdate("#twitterTimelineSelection", "#77C6FF", "#FFF");
}
// not yet to the time, so setup an update call, but don't bother if this mission is over
} else if (!isMissionEnded()) {
ops.updatesList.push({ type: "object", id: ops.currentVessel.Catalog.DB, UT: parseFloat(ops.currentVessel.Catalog.Timeline.split(";")[0]) });
}
} else if (!update) swapTwitterSource("Mission Feed", ops.currentVessel.Catalog.Timeline);
}
}
function vesselTitleUpdate(update) {
if (update && $("#title").html() != ops.currentVessel.CraftData.CraftName) {
flashUpdate("#title", "#77C6FF", "#FFF");
$("#title").html(ops.currentVessel.CraftData.CraftName);
document.title = "KSA Operations Tracker" + " - " + ops.currentVessel.CraftData.CraftName + ": " + ops.currentVessel.CraftData.CraftDescTitle;
} else {
$("#title").html(ops.currentVessel.CraftData.CraftName);
document.title = "KSA Operations Tracker" + " - " + ops.currentVessel.CraftData.CraftName + ": " + ops.currentVessel.CraftData.CraftDescTitle;
}
}
// updates all the data in the Info Box
function vesselInfoUpdate(update) {
$("#infoBox").spin(false);
if (update && (!$("#infoImg").html().includes(getVesselImage()) || $("#infoTitle").html() != ops.currentVessel.CraftData.CraftDescTitle)) {
flashUpdate("#infoTitle", "#77C6FF", "#000");
}
// setup the basics
$("#infoImg").html("<img src='" + getVesselImage() + "'>");
$("#infoTitle").html(ops.currentVessel.CraftData.CraftDescTitle);
$("#infoTitle").attr("class", "infoTitle vessel");
$("#infoDialog").html(ops.currentVessel.CraftData.CraftDescContent.replace("thrid", "third"));
$("#infoDialog").html(ops.currentVessel.CraftData.CraftDescContent.replace("fist stage", "first stage"));
$("#infoDialog").dialog("option", "title", "Additional Information - " + ops.currentVessel.CraftData.CraftDescTitle);
$("#infoDialog").dialog("option", {width: 643, height: 400});
// is there a parts overlay?
if (getPartsHTML()) {
var partsImgHTML = '';
var imgMapData = getPartsHTML();
// create divs for every <area> tag
imgMapData.split("<area").forEach(function(item) {
if (item.includes('coords="')) {
var areaCenter = item.split('coords="')[1].split('"')[0].split(",");
partsImgHTML += "<div id='" + item.split('title="&')[1].split('"')[0] + "' ";
if (item.includes("amount")) partsImgHTML += "amount='" + item.split('amount="')[1].split('"')[0] + "' ";
partsImgHTML += "class='imgmap' style='top: " + (parseInt(areaCenter[1])-5) + "px; ";
partsImgHTML += "left: " + (parseInt(areaCenter[0])+$("#infoBox").position().left+$("#mainContent").position().left-5) + "px;";
partsImgHTML += "'></div>";
}
});
// extract the image name
partsImgHTML += "<img src='https://i.imgur.com/" + imgMapData.split("/")[3].split(".")[0] + ".png'/>";
$("#partsImg").html(partsImgHTML);
setTimeout(function() { if (!$('#infoBox').is(":hover")) $("#partsImg").fadeOut(1000); }, 1000);
assignPartInfo();
} else $("#partsImg").empty();
}
function vesselMETUpdate(update) {
// get the current launch time - defer to mission start time if it's available
var launchTime = checkLaunchTime();
if (ops.currentVessel.Catalog.MissionStartTime) launchTime = ops.currentVessel.Catalog.MissionStartTime;
if (update && (!$("#dataField0").html().includes(ops.currentVessel.CraftData.MissionStartTerm) || !$("#dataField0").html().includes(UTtoDateTime(launchTime)))) {
flashUpdate("#dataField0", "#77C6FF", "#FFF");
}
// we don't know the start time right now
var strHTML;
if (!launchTime) {
strHTML = "<b>" + ops.currentVessel.CraftData.MissionStartTerm + ":</b><span style='cursor:help' class='tip-update' data-tipped-options=\"inline: 'metTip', maxWidth: 300\"> <u>To Be Determined</u>";
// post the current launch time
} else {
strHTML = "<b>" + ops.currentVessel.CraftData.MissionStartTerm + ":</b><span style='cursor:help' class='tip-update' data-tipped-options=\"inline: 'metTip', maxWidth: 300\"> <u>" + UTtoDateTime(launchTime) + " UTC</u>";
}
$("#dataField0").fadeIn();
// decide what goes in the tooltip
var strTip = "";
// we don't know yet
if (!launchTime && !ops.currentVessel.CraftData.pastEvent) strTip = "launch time currently being assessed<br>";
else {
// if this is a past event and there was more than one launch time, find what time equals the current UT
// if it is in a state greater than the current one, that's the actual current launch time
if (ops.currentVessel.CraftData.pastEvent && ops.currentVessel.LaunchTimes.length > 1) {
for (i=ops.currentVessel.LaunchTimes.length-1; i>=0; i--) {
if (ops.currentVessel.LaunchTimes[i].UT <= currUT() && ops.currentVessel.LaunchTimes[i].UT > ops.currentVessel.CraftData.UT) {
if (ops.currentVessel.LaunchTimes[i].LaunchTime == ops.currentVessel.LaunchTimes[i].UT) {
strTip += "Launch has been scrubbed or put on hold<br>Actual Launch Time: To Be Determined<br>";
} else {
strTip += "Actual Launch Time: " + UTtoDateTime(ops.currentVessel.LaunchTimes[i].LaunchTime) + " UTC<br>";
}
launchTime = ops.currentVessel.LaunchTimes[i].LaunchTime
break;
}
}
}
// add further details based on mission status
// mission hasn't started yet
if (launchTime && currUT() < launchTime) {
strTip += "Time to Launch: <span data='" + launchTime + "' id='metCount'>" + formatTime(launchTime-currUT()) + "</span>";
// mission is ongoing
} else if (launchTime && !isMissionEnded()) {
strTip += "Mission Elapsed Time: <span data='" + launchTime + "' id='metCount'>" + formatTime(currUT()-launchTime) + "</span>";
// mission has ended
} else if (launchTime && isMissionEnded()) {
strTip += getMissionEndMsg() + "<br>Mission Total Elapsed Time: <span id='metCount'>" + formatTime(getMissionEndTime()-launchTime) + "</span>";
}
}
$("#dataField0").html(strHTML);
$("#metTip").html(strTip);
}
function vesselVelocityUpdate(update) {
if (ops.currentVessel.Orbit && ops.currentVessel.Orbit.AvgVelocity) {
var strTip = "<span id='avgVelUpdate'>Periapsis: " + numeral(ops.currentVessel.Orbit.VelocityPe).format('0.000') + "km/s<br>Apoapsis: " + numeral(ops.currentVessel.Orbit.VelocityAp).format('0.000') + "km/s</span>";
var strHTML = "<b><u><span style='cursor:help' class='tip-update' data-tipped-options=\"inline: 'avgVelTip'\">Average Velocity:</u></b> " + numeral((ops.currentVessel.Orbit.VelocityPe+ops.currentVessel.Orbit.VelocityAp)/2).format('0.000') + "km/s";
$("#dataField1").fadeIn();
if (update && (!ops.currentVessel.Orbit.velocityHTML || (ops.currentVessel.Orbit.velocityHTML && strHTML + strTip != ops.currentVessel.Orbit.velocityHTML))) {
flashUpdate("#dataField1", "#77C6FF", "#FFF");
}
$("#avgVelTip").html(strTip);
$("#dataField1").html(strHTML);
ops.currentVessel.Orbit.velocityHTML = strHTML + strTip;
} else $("#dataField1").fadeOut();
}
function vesselPeUpdate(update) {
if (ops.currentVessel.Orbit && ops.currentVessel.Orbit.Periapsis) {
var strHTML = "<b>Periapsis:</b> " + numeral(ops.currentVessel.Orbit.Periapsis).format('0,0.000') + "km";
$("#dataField2").fadeIn();
if (update && strHTML != $("#dataField2").html()) flashUpdate("#dataField2", "#77C6FF", "#FFF");
$("#dataField2").html(strHTML);
} else $("#dataField2").fadeOut();
}
function vesselApUpdate(update) {
if (ops.currentVessel.Orbit && ops.currentVessel.Orbit.Apoapsis) {
var strHTML = "<b>Apoapsis:</b> " + numeral(ops.currentVessel.Orbit.Apoapsis).format('0,0.000') + "km";
$("#dataField3").fadeIn();
if (update && strHTML != $("#dataField3").html()) flashUpdate("#dataField3", "#77C6FF", "#FFF");
$("#dataField3").html(strHTML);
} else $("#dataField3").fadeOut();
}
function vesselEccUpdate(update) {
if (ops.currentVessel.Orbit && ops.currentVessel.Orbit.Eccentricity) {
var strHTML = "<b>Eccentricity:</b> " + numeral(ops.currentVessel.Orbit.Eccentricity).format('0.000');
$("#dataField4").fadeIn();
if (update && strHTML != $("#dataField4").html()) flashUpdate("#dataField4", "#77C6FF", "#FFF");
$("#dataField4").html(strHTML);
} else $("#dataField4").fadeOut();
}
function vesselIncUpdate(update) {
if (ops.currentVessel.Orbit && ops.currentVessel.Orbit.Inclination) {
var strHTML = "<b>Inclination:</b> " + numeral(ops.currentVessel.Orbit.Inclination).format('0.000') + "°";
$("#dataField5").fadeIn();
$("#dataField5").html(strHTML);
// check the inclination against just the number in the HTML field
// <b>Inclination:</b> ###.###°
if (update && ops.currentVessel.Orbit.Inclination.toFixed(3) != parseFloat($("#dataField5").html().split(" ")[1].split("°")[0])) {
flashUpdate("#dataField5", "#77C6FF", "#FFF");
}
} else $("#dataField5").fadeOut();
}
function vesselPeriodUpdate(update) {
if (ops.currentVessel.Orbit && ops.currentVessel.Orbit.OrbitalPeriod) {
var strTip = formatTime(ops.currentVessel.Orbit.OrbitalPeriod);
var strHTML = "<b>Orbital Period:</b> <u><span style='cursor:help' class='tip-update' data-tipped-options=\"inline: 'periodTip'\">" + numeral(ops.currentVessel.Orbit.OrbitalPeriod).format('0,0.000') + "s</span></u>";
$("#dataField6").fadeIn();
// calculate the number of orbits
var numOrbits = 0;
for (obt=0; obt<ops.currentVessel.OrbitalHistory.length-1; obt++) {
// don't look past the current time
if (ops.currentVessel.OrbitalHistory[obt].UT > currUT()) break;
// get the amount of time spent between the two states, or this last/only state and the current time
// if the mission has ended then use that instead of the current time
var timeDiff;
var timeUntil;
if (isMissionEnded()) timeUntil = getMissionEndTime();
else timeUntil = currUT();
if (ops.currentVessel.OrbitalHistory[obt+1].UT > currUT()) timeDiff = timeUntil - ops.currentVessel.OrbitalHistory[obt].UT;
else timeDiff = ops.currentVessel.OrbitalHistory[obt+1].UT - ops.currentVessel.OrbitalHistory[obt].UT;
// add the orbits done during this time
numOrbits += timeDiff/ops.currentVessel.OrbitalHistory[obt].Period;
}
// if we haven't completed a single orbit yet, calculate based on the current time and orbital data
if (numOrbits > 0) strTip += "<br>Number of Orbits: " + numeral(numOrbits).format('0,0.00');
else strTip += "<br>Number of Orbits: " + numeral((currUT() - ops.currentVessel.Orbit.Eph)/ops.currentVessel.Orbit.OrbitalPeriod).format('0,0.00');
if (update && (!ops.currentVessel.Orbit.orbitalPeriodHTML || (ops.currentVessel.Orbit.orbitalPeriodHTML && strHTML + strTip != ops.currentVessel.Orbit.orbitalPeriodHTML))) {
flashUpdate("#dataField6", "#77C6FF", "#FFF");
}
$("#dataField6").html(strHTML);
$("#periodTip").html(strTip);
ops.currentVessel.Orbit.orbitalPeriodHTML = strHTML + strTip;
} else $("#dataField6").fadeOut();
}
function vesselCrewUpdate(update) {
if (ops.currentVessel.Manifest && !!ops.currentVessel.Manifest.Crew) {
var strHTML = "<b>Crew:</b> ";
ops.currentVessel.Manifest.Crew.split("|").forEach(function(item) {
// older tooltip contained more data that can now be gotten at the crew page
// strHTML += "<img class='tipped' title='" + item.split(";")[0] + "<br>Boarded on: " + UTtoDateTime(parseFloat(item.split(";")[2])).split("@")[0] + "<br>Mission Time: " + formatTime(currUT() - parseFloat(item.split(";")[2])).split(",")[0] + "' style='cursor: pointer' src='http://www.kerbalspace.agency/Tracker/favicon.ico'></a> ";
strHTML += "<img onclick=\"swapContent('crew', '" + item.split(';')[1] + "')\" class='tipped' title='" + item.split(";")[0] + "' style='cursor: pointer' src='http://www.kerbalspace.agency/Tracker/favicon.ico'></a> ";
});
$("#dataField7").fadeIn();
if (update && (!ops.currentVessel.Manifest.crewHTML || (ops.currentVessel.Manifest.crewHTML && strHTML != ops.currentVessel.Manifest.crewHTML))) {
flashUpdate("#dataField7", "#77C6FF", "#FFF");
}
$("#dataField7").html(strHTML);
ops.currentVessel.Manifest.crewHTML = strHTML;
} else $("#dataField7").fadeOut();
}
function vesselResourcesUpdate(update) {
if (ops.currentVessel.Resources) {
if (ops.currentVessel.Resources.NotNull) {
var strHTML = "<span class='tipped' style='cursor:help' title='Total Δv: ";
if (ops.currentVessel.Resources.DeltaV !== null) strHTML += numeral(ops.currentVessel.Resources.DeltaV).format('0.000') + "km/s";
else strHTML += "N/A";
strHTML += "<br>Total Mass: ";
if (ops.currentVessel.Resources.TotalMass !== null) strHTML += numeral(ops.currentVessel.Resources.TotalMass).format('0,0.000') + "t";
else strHTML += "N/A";
strHTML += "<br>Resource Mass: ";
if (ops.currentVessel.Resources.ResourceMass !== null) strHTML += numeral(ops.currentVessel.Resources.ResourceMass).format('0.000') + "t";
else strHTML += "N/A";
strHTML += "'><b><u>Resources:</u></b></span> ";
if (ops.currentVessel.Resources.Resources) {
strHTML += "<img id='prevRes' width='12' src='prevList.png' style='visibility: hidden; cursor: pointer; vertical-align: -1px' onclick='prevResource()'>";
// template the max number of visible resource icons and then actually load them 250ms later
for (resCount=0; resCount<5; resCount++) {
strHTML += "<div id='resTip" + resCount + "' style='display: none'>temp</div>";
strHTML += "<span style='cursor:help' class='tip-update' data-tipped-options=\"inline: 'resTip" + resCount + "', detach: false\">";
strHTML += "<img id='resImg" + resCount + "' src='' style='display: none; padding-left: 1px; padding-right: 2px'></span>";
}
strHTML += "<img id='nextRes' width='12' src='nextList.png' style='visibility: hidden; cursor: pointer; vertical-align: -1px' onclick='nextResource()'>";
setTimeout(updateResourceIcons, 250, update);
} else strHTML += "None";
$("#dataField8").fadeIn();
$("#dataField8").html(strHTML);
// decide whether to display recource scroll arrows
if (ops.currentVessel.Resources.Resources && ops.currentVessel.Resources.Resources.split("|").length > 5) $("#nextRes").css("visibility", "visible");
else $("#prevRes").css("display", "none");
// !NotNull means a resource record exists for this UT but is empty, so we are removing the field at this time
} else $("#dataField8").fadeOut();
} else $("#dataField8").fadeOut();
}
function vesselCommsUpdate(update) {
if (ops.currentVessel.Comms) {
if (ops.currentVessel.Comms.Comms) {
strHTML = "<span class='tipped' style='cursor:help' title='";
if (ops.currentVessel.Comms.Connection) strHTML += "Signal Delay: <0.003s";
else strHTML += "No Connection";
strHTML += "'><b><u>Comms:</u></b></span> ";
if (ops.currentVessel.Comms.Comms) {
ops.currentVessel.Comms.Comms.split("|").forEach(function(item) {
var iconStr = "";
if (!ops.currentVessel.Comms.Connection) iconStr = "no";
strHTML += "<img class='tipped' title='" + item.split(";")[1] + "' style='cursor:help' src='" + iconStr + item.split(";")[0] + ".png'></a> ";
});
} else strHTML += "None";
$("#dataField9").fadeIn();
if (update && (!ops.currentVessel.Comms.commsHTML || (ops.currentVessel.Comms.commsHTML && strHTML != ops.currentVessel.Comms.commsHTML))) {
flashUpdate("#dataField9", "#77C6FF", "#FFF");
}
$("#dataField9").html(strHTML);
ops.currentVessel.Comms.commsHTML = strHTML;
// no data in the Comms field means a record exists for this UT but is empty, so we are removing the field at this time
} else $("#dataField9").fadeOut();
} else $("#dataField9").fadeOut();
}
function vesselRelatedUpdate(update) {
// either this has just the vessel name to show now, or it has a time that needs to be checked first
if ((ops.currentVessel.Catalog.Related && !ops.currentVessel.Catalog.Related.split(";").length == 3) ||
(ops.currentVessel.Catalog.Related && ops.currentVessel.Catalog.Related.split(";").length > 3 && parseInt(ops.currentVessel.Catalog.Related.split(";")[3]) <= currUT())) {
$("#dataField10").fadeIn();
if (update && !$("#dataField9").html().includes(ops.currentVessel.Catalog.Related.split(";")[0])) flashUpdate("#dataField10", "#77C6FF", "#FFF");
var strHTML = "<b>Related Vessel:</b> <span class='fauxLink tipped' style='cursor: pointer' onclick=\"swapContent('vessel', '" + ops.currentVessel.Catalog.Related.split(";")[0] + "')\" ";
strHTML += "title='" + ops.currentVessel.Catalog.Related.split(";")[2] + "'>";
strHTML += ops.currentVessel.Catalog.Related.split(";")[1] + "</span>";
$("#dataField10").html(strHTML);
} else $("#dataField10").fadeOut();
}
function vesselAddlInfoUpdate(update) {
if (ops.currentVessel.Catalog.AddlRes) {
var newRes;
var strHTML = '';
ops.currentVessel.Catalog.AddlRes.split("|").forEach(function(item) {
if (parseFloat(item.split(";")[0]) < currUT()) {
strHTML += "<span class='tipped' title='" + item.split(";")[1] + "'><a target='_blank' style='color: black' href='" + item.split(";")[2] + "'><i class='" + AddlResourceItems[item.split(";")[1]] + "'></i></a></span> ";
// if the item isn't visible yet, save the UT so we can add an update notice for it
} else {
if (!newRes) newRes = parseFloat(item.split(";")[0]);
else if (parseFloat(item.split(";")[0]) < newRes) newRes = parseFloat(item.split(";")[0]);
}
});
if (strHTML) {
if (update && (!ops.currentVessel.Catalog.AddlResHTML || (ops.currentVessel.Catalog.AddlResHTML && strHTML != ops.currentVessel.Catalog.AddlResHTML))) {
flashUpdate("#dataField11", "#77C6FF", "#FFF");
}
$("#dataField11").html("<b>Additional Information:</b> " + strHTML);
$("#dataField11").fadeIn();
ops.currentVessel.Catalog.AddlResHTML = strHTML;
// there could be data but turns out we can't show it yet
} else $("#dataField11").fadeOut();
if (newRes) ops.updatesList.push({ type: "object", id: ops.currentVessel.Catalog.DB, UT: newRes });
} else $("#dataField11").fadeOut();
}
function vesselLastUpdate(update) {
if (update && !$("#dataField12").html().includes(UTtoDateTime(ops.currentVessel.CraftData.UT))) flashUpdate("#dataField12", "#77C6FF", "#FFF");
$("#distanceTip").html(UTtoDateTimeLocal(ops.currentVessel.CraftData.UT))
if (ops.currentVessel.CraftData.DistanceTraveled) $("#distanceTip").append("<br>Current Distance Traveled: " + ops.currentVessel.CraftData.DistanceTraveled + "km");
$("#dataField12").html("<b>Last Update:</b> <u><span class='tip-update' style='cursor:help' data-tipped-options=\"inline: 'distanceTip'\">" + UTtoDateTime(ops.currentVessel.CraftData.UT) + " UTC</span></u>")
$("#dataField12").fadeIn()
}
function vesselHistoryUpdate() {
$("#missionHistory").fadeIn()
// reset the history
$("#prevEvent").empty()
$("#prevEvent").append($('<option>', { value: null, text: 'Prev Event(s)' }));
$("#prevEvent").prop("disabled", true);
$("#nextEvent").empty()
$("#nextEvent").append($('<option>', { value: null, text: 'Next Event(s)' }));
$("#nextEvent").prop("disabled", true);
// disable history buttons - they will be re-enabled as needed
$("#prevEventButton").button("option", "disabled", true);
$("#nextEventButton").button("option", "disabled", true);
// fill up the previous events
ops.currentVessel.History.reverse().forEach(function(item) {
if (item.UT < ops.currentVessel.CraftData.UT && item.Title != ops.currentVessel.CraftData.CraftDescTitle) {
if ((ops.ascentData.active && item.UT <= checkLaunchTime()) || !ops.ascentData.active) {
$("#prevEvent").append($('<option>', {
value: item.UT,
text: item.Title
}));
$("#prevEvent").prop("disabled", false);
$("#prevEventButton").button("option", "disabled", false);
}
}
});
// fill up the next events
ops.currentVessel.History.reverse().forEach(function(item) {
// if this isn't a past event, we don't want the current event (equal to the current UT) to show up
if (!ops.currentVessel.CraftData.pastEvent && item.UT > ops.currentVessel.CraftData.UT && item.Title != ops.currentVessel.CraftData.CraftDescTitle && item.UT < currUT()) {
$("#nextEvent").append($('<option>', {
value: item.UT,
text: item.Title
}));
$("#nextEvent").prop("disabled", false);
$("#nextEventButton").button("option", "disabled", false);
// otherwise if it's a previous event we do want the most recent event in this list
} else if (ops.currentVessel.CraftData.pastEvent && item.UT > ops.currentVessel.CraftData.UT && item.Title != ops.currentVessel.CraftData.CraftDescTitle && item.UT <= currUT()) {
$("#nextEvent").append($('<option>', {
value: item.UT,
text: item.Title
}));
$("#nextEvent").prop("disabled", false);
$("#nextEventButton").button("option", "disabled", false);
}
});
// update to remove the loading text
$("#dataLabel").html("Mission History");
// check for future event
if (ops.currentVessel.CraftData.NextEventTitle && !ops.currentVessel.CraftData.pastEvent) {
$("#nextEvent").append($('<option>', {
value: ops.currentVessel.CraftData.NextEventTitle,
text: "Scheduled Event"
}));
$("#nextEvent").prop("disabled", false);
}
}
function vesselContentUpdate(update) {
// we can't know whether this body has a surface map if we are still waiting for map data to load
// since map data is called after GGB load, make sure that's not happening either
// finally, ops data could still be loading as well
if (!isGGBAppletLoaded || ops.surface.isLoading || ops.updateData.find(o => o.isLoading === true)) {
return setTimeout(vesselContentUpdate, 50, update);
}
// decide what kind of content we have to deal with
// pre-launch/static data event.
if (ops.currentVessel.CraftData.Content.charAt(0) == "@") {
// Don't need to update unless content is not the same
if (!ops.currentVessel.CraftData.prevContent || (ops.currentVessel.CraftData.prevContent && ops.currentVessel.CraftData.prevContent != ops.currentVessel.CraftData.Content)) {
showMap();
// remove any previous markers and surface plots
if (launchsiteMarker) ops.surface.map.removeLayer(launchsiteMarker);
if (vesselMarker) ops.surface.map.removeLayer(vesselMarker);
launchsiteMarker = null;
clearSurfacePlots();
// extract the data
var data = ops.currentVessel.CraftData.Content.split("@")[1].split("|");
// these elements should only appear on general surface maps
if (layerPins) {
ops.surface.map.removeLayer(layerPins);
ops.surface.layerControl.removeLayer(layerPins);
}
// set launchsite icon
launchsiteIcon = L.icon({ popupAnchor: [0, -43], iconUrl: 'markers-spacecenter.png', iconSize: [30, 40], iconAnchor: [15, 40], shadowUrl: 'markers-shadow.png', shadowSize: [35, 16], shadowAnchor: [10, 12] });
// decide if this is still pre-launch or not
var strLaunchIconCaption = "<b>Launch Location</b><br>"
if (ops.currentVessel.CraftData.MissionStartTerm != "Launch") strLaunchIconCaption = "";
// if launch is in progress and there's an altitude to report, include it
var launchAltitude = "";
if (data.length > 3) launchAltitude = "<br>" + data[3] + "km ASL";
// place the marker and build the information window for it, then center the map on it and create a popup for it
launchsiteMarker = L.marker([data[0], data[1]], {icon: launchsiteIcon}).addTo(ops.surface.map);
var latlng = { lat: parseInt(data[0]), lng: parseInt(data[1]) };
launchsiteMarker.bindPopup(strLaunchIconCaption + data[2] + launchAltitude + "<br>[" + numeral(data[0]).format('0.0000') + "°" + getLatLngCompass(latlng).lat + ", " + numeral(data[1]).format('0.0000') + "°" + getLatLngCompass(latlng).lng + "]" , { closeOnClick: false });
ops.surface.map.setView(launchsiteMarker.getLatLng(), 3);
launchsiteMarker.openPopup();
// close the popup after 5 seconds if this is a past event or a prelaunch state
// make sure to reset the timeout in case the page has been loaded with new data before the 5s expire
clearTimeout(mapMarkerTimeout);
if (ops.currentVessel.CraftData.pastEvent || strLaunchIconCaption) {
mapMarkerTimeout = setTimeout(function () { if (launchsiteMarker) launchsiteMarker.closePopup(); }, 5000);
}
}
// dynamic map with orbital information
} else if (ops.currentVessel.CraftData.Content.charAt(0) == "!" && !ops.currentVessel.CraftData.Content.includes("[")) {
// extract the data
var data = ops.currentVessel.CraftData.Content.split("!")[1].split("|");
// only show dynamic information if this is a current state in an ongoing mission
// also only show if there is surface data for a map & orbital data
if (!isMissionEnded() && !ops.currentVessel.CraftData.pastEvent && ops.surface.Data && ops.currentVessel.Orbit.Eph) {
// remove any previous markers
if (launchsiteMarker) ops.surface.map.removeLayer(launchsiteMarker);
launchsiteMarker = null;
showMap();
$("#mapDialog").dialog("close");
var isPlottable = false;
if (ops.currentVesselPlot &&
ops.currentVesselPlot.obtData.length && // a plot exists
ops.currentVesselPlot.id == ops.currentVessel.Catalog.DB && // the plot belongs to this vessel
ops.currentVesselPlot.eph == ops.currentVessel.Orbit.Eph && // the data used for the plot is still valid
ops.currentVesselPlot.obtData[ops.currentVesselPlot.obtData.length-1].endUT > currUT() // the plot itself runs longer than the current time
) isPlottable = true;
// if this is not plottable or there is no previous content, we need to render new data
if (!update && (!isPlottable || (!isPlottable && !ops.currentVessel.CraftData.prevContent))) renderMapData();
// if this is an update with changed content, we need to render new trajectories
else if (update && ops.currentVessel.CraftData.prevContent != ops.currentVessel.CraftData.Content) renderMapData();
// if this is an not an update and has the same content, just redraw
else if (!update && isPlottable) redrawVesselPlots();
// we're looking at old orbital data
} else {
// no need to update unless it's not the same as before or there's no orbit
if (!ops.currentVessel.Orbit.Eph || !ops.currentVessel.CraftData.prevContent || (ops.currentVessel.CraftData.prevContent && ops.currentVessel.CraftData.prevContent != ops.currentVessel.CraftData.Content)) {
$("#content").empty();
hideMap();
// two images?
if (data[1].includes(".png")) {
$("#content").html("<div class='fullCenter'><img width='475' class='contentTip' style='cursor: help' title='Ecliptic View<br>Dynamic orbit unavailable - viewing old data' src='" + data[0] + "'> <img width='475' class='tipped' data-tipped-options=\"target: 'mouse'\" style='cursor: help' title='Polar View<br>Dynamic orbit unavailable - viewing old data' src='" + data[1] + "'></div>");
// one image
} else {
$("#content").html("<img class='fullCenter contentTip' style='cursor: help' title='" + data[1] + "' src='" + data[0] + "'>");
}
$("#content").fadeIn();
}
}
// static orbits with dynamic information
} else if (ops.currentVessel.CraftData.Content.charAt(0) == "!" && ops.currentVessel.CraftData.Content.includes("[")) {
// streaming ascent data, possibly with video
} else if (ops.currentVessel.CraftData.Content.charAt(0) == "~") {
// just plain HTML
} else {
hideMap();
$("#content").empty();
$("#content").html(ops.currentVessel.CraftData.Content);
$("#content").fadeIn();
}
// save the content data so next load we don't update if we don't have to
ops.currentVessel.CraftData.prevContent = ops.currentVessel.CraftData.Content;
$("#contentBox").spin(false);
// create any tooltips since we will likely miss the default tip creation waiting on async data load
// behavior of tooltips depends on the device
if (is_touch_device()) showOpt = 'click';
else showOpt = 'mouseenter';
Tipped.create('.contentTip', { showOn: showOpt, hideOnClickOutside: is_touch_device(), target: 'mouse', hideOn: {element: 'mouseleave'} });
}
// JQuery callbacks
// only handle this if the page is a vessel instead of crew
$("#infoBox").hover(function() {
if (ops.pageType == "vessel" && ops.currentVessel && !ops.ascentData.active) {
if (!$("#infoDialog").dialog("isOpen")) $("#infoTitle").html("Click Here for Additional Information");
$("#partsImg").fadeIn();
}
}, function() {
if (ops.pageType == "vessel" && ops.currentVessel && !ops.ascentData.active) {
// wait to give tooltips a chance to hide on mouseover before checking to see if we're actually off the image
setTimeout(function() {
if (!ops.currentVessel) return;
if (!$('#infoBox').is(":hover")) {
$("#infoTitle").html(ops.currentVessel.CraftData.CraftDescTitle);
$("#partsImg").fadeOut();
}
}, 500);
}
});
// upon selection of a new list item, take the user to that event
$("#prevEvent").change(function () {
if ($("#prevEvent").val()) loadVessel(ops.currentVessel.Catalog.DB, parseFloat($("#prevEvent").val()));
});
$("#nextEvent").change(function () {
// could be a future event
if ($("#nextEvent").val() && $("#nextEvent").val() != "Next Event(s)") {
if (isNaN($("#nextEvent").val())) {
$("#siteDialog").html($("#nextEvent").val());
$("#siteDialog").dialog("option", "title", "Scheduled Event");
$("#siteDialog").dialog("option", "width", 250);
$("#siteDialog").dialog( "option", "buttons", [{
text: "Close",
click: function() {
$("#siteDialog").dialog("close");
}
}]);
$("#siteDialog").dialog("open");
$("#nextEvent").val("Next Event(s)");
} else loadVessel(ops.currentVessel.Catalog.DB, parseFloat($("#nextEvent").val()));
}
});
// history paging via buttons
function prevHistoryButton() {
if (!ops.currentVessel) return; // clicked too fast, in between data calls
var histIndex;
for (histIndex = ops.currentVessel.History.length-1; histIndex >= 0; histIndex--) {
if (ops.currentVessel.History[histIndex].UT < ops.currentVessel.CraftData.UT) break;
}
loadVessel(ops.currentVessel.Catalog.DB, ops.currentVessel.History[histIndex].UT);
if (histIndex == 0) $("#prevEventButton").button("option", "disabled", true);
$("#nextEventButton").button("option", "disabled", false);
}
function nextHistoryButton() {
if (!ops.currentVessel) return; // clicked too fast, in between data calls
var histIndex;
for (histIndex = 0; histIndex <= ops.currentVessel.History.length; histIndex++) {
if (ops.currentVessel.History[histIndex].UT > ops.currentVessel.CraftData.UT) break;
}
if (histIndex == ops.currentVessel.History.length-1) $("#nextEventButton").button("option", "disabled", true);
loadVessel(ops.currentVessel.Catalog.DB, ops.currentVessel.History[histIndex].UT);
$("#prevEventButton").button("option", "disabled", false);
}
// opens the dialog box with more details - this is the same box that holds crew details, was just implemented here first
function showInfoDialog() {
if (!$("#infoDialog").dialog("isOpen") && !ops.ascentData.active) $("#infoDialog").dialog("open")
}
// provides full details for all vessel parts, ensures the parts catalog is loaded
function assignPartInfo() {
if (!partsCatalog.length) return setTimeout(assignPartInfo, 100);
$(".imgmap").each(function() {
var part = partsCatalog.find(o => o.Part === $(this).attr("id"));
// behavior of tooltips depends on the device
if (is_touch_device()) showOpt = 'click';
else showOpt = 'mouseenter';
// is there a title and are there multiples of this part to add to the title?
var strPartHtml = "";
if (part.Title) {
strPartHtml += "<b>" + part.Title;
if ($(this).attr("amount")) strPartHtml += " (x" + $(this).attr("amount") + ")";
strPartHtml += "</b>";
}
strPartHtml += part.HTML;
// are there notes for this part?
if (part.Notes) {
// get all the notes
var notes = part.Notes.split("&");
// find out if any apply to this vessel and if so add the note to the HTML
notes.forEach(function(note) {
var regex = new RegExp(note.split("%")[0]);
if (ops.currentVessel.Catalog.DB.match(regex)) strPartHtml += "<b>Note:</b> " + note.split("%")[1];
});
}
Tipped.create("#" + part.Part, strPartHtml, { showOn: showOpt, hideOnClickOutside: is_touch_device(), target: 'mouse', offset: { y: 2 } });
});
}
// called only to update the vessel data after it has already been loaded initially
function updateVesselData(vessel) {
// check if this vessel has any orbital data
loadDB("loadVesselOrbitData.asp?db=" + vessel.id + "&ut=" + currUT(), addGGBOrbitAJAX);
// perform a live data update if we are looking at the vessel in question at the moment
if (ops.pageType == "vessel" && ops.currentVessel.Catalog.DB == vessel.id) {
// these elements should only be updated if the vessel is not undergoing an active ascent and is viewing the current record
if (!ops.ascentData.active && !ops.currentVessel.CraftData.pastEvent) {
// we need to retain this information
if (ops.currentVessel.Comms) var commsHTML = ops.currentVessel.Comms.commsHTML;
if (ops.currentVessel.Crew) var crewHTML = ops.currentVessel.Crew.crewHTML;
if (ops.currentVessel.Orbit) {
var orbitalPeriodHTML = ops.currentVessel.Orbit.orbitalPeriodHTML;
var velocityHTML = ops.currentVessel.Orbit.velocityHTML;
}
if (ops.currentVessel.Resources) var resHTML = ops.currentVessel.Resources.resHTML;
var prevContent = ops.currentVessel.CraftData.prevContent;
// update the current data with the updated data and then carry out updates to individual sections
for (var futureProp in vessel.FutureData) {
for (var prop in ops.currentVessel) {
// only update data that exists and is current for this time
if (futureProp == prop && vessel.FutureData[futureProp] && vessel.FutureData[futureProp].UT <= currUT()) {
ops.currentVessel[prop] = vessel.FutureData[futureProp];
}
}
}
// restore the data
if (ops.currentVessel.Comms) ops.currentVessel.Comms.commsHTML = commsHTML;
if (ops.currentVessel.Crew) ops.currentVessel.Crew.crewHTML = crewHTML;
if (ops.currentVessel.Orbit) {
ops.currentVessel.Orbit.orbitalPeriodHTML = orbitalPeriodHTML;
ops.currentVessel.Orbit.velocityHTML = velocityHTML;
}
if (ops.currentVessel.Resources) {
ops.currentVessel.Resources.resHTML = resHTML;
ops.currentVessel.Resources.resIndex = 0;
}
ops.currentVessel.CraftData.prevContent = prevContent;
vesselHistoryUpdate();
vesselTimelineUpdate(true);
vesselInfoUpdate(true);
vesselVelocityUpdate(true);
vesselPeUpdate(true);
vesselApUpdate(true);
vesselEccUpdate(true);
vesselIncUpdate(true);
vesselPeriodUpdate(true);
vesselCrewUpdate(true);
vesselResourcesUpdate(true);
vesselCommsUpdate(true);
vesselAddlInfoUpdate(true);
vesselMETUpdate(true);
vesselRelatedUpdate(true);
vesselLastUpdate(true);
vesselContentUpdate(true);
}
// create the tooltips
// behavior of tooltips depends on the device
if (is_touch_device()) showOpt = 'click';
else showOpt = 'mouseenter';
Tipped.create('.tipped', { showOn: showOpt, hideOnClickOutside: is_touch_device(), detach: false, hideOn: {element: 'mouseleave'} });
Tipped.create('.tip-update', { showOn: showOpt, hideOnClickOutside: is_touch_device(), detach: false, hideOn: {element: 'mouseleave'} });
}
// fetch new data. Add a second just to make sure we don't get the same current data
vessel.isLoading = true;
loadDB("loadOpsData.asp?db=" + vessel.id + "&UT=" + (currUT()+1) + "&type=" + vessel.type + "&pastUT=NaN", loadOpsDataAJAX);
}
// following functions perform parsing on data strings
function getVesselImage() {
if (!ops.currentVessel.CraftData.CraftImg) return "nadaOp.png";
else return ops.currentVessel.CraftData.CraftImg.split("|")[vesselRotationIndex].split("~")[0];
}
function getPartsHTML() {
if (!ops.currentVessel.CraftData.CraftImg) return null;