1
|
|
|
(function() { |
2
|
|
|
"use strict"; |
3
|
|
|
|
4
|
|
|
window.voteSite = function(snUrl) { |
5
|
|
|
// Must not redirect the current page until after the external vote |
6
|
|
|
// site URL has been opened in a new tab. Use setTimeout to do this. |
7
|
|
|
setTimeout(function() { |
8
|
|
|
window.location = snUrl; |
9
|
|
|
}, 0); |
10
|
|
|
}; |
11
|
|
|
|
12
|
|
|
function doCalc(type, number, totalDest) { |
13
|
|
|
var i = 1, total = 0, df=document.FORM; |
14
|
|
|
for(; i<=number; i++) { |
15
|
|
|
total += df[type+i].value * 1; |
16
|
|
|
} |
17
|
|
|
df[totalDest].value = total; |
18
|
|
|
}; |
19
|
|
|
|
20
|
|
|
// Recalculate total number of ports, summing over level |
21
|
|
|
window.levelCalc = function(maxPortLevel) { |
22
|
|
|
doCalc('port', maxPortLevel, 'total'); |
23
|
|
|
}; |
24
|
|
|
|
25
|
|
|
// Recalculate sum of port race percentages |
26
|
|
|
window.raceCalc = function() { |
27
|
|
|
doCalc('race', 9, 'racedist'); |
28
|
|
|
}; |
29
|
|
|
|
30
|
|
|
// Set the total number of ports to zero |
31
|
|
|
window.setZero = function(maxPortLevel) { |
32
|
|
|
var df = document.FORM; |
33
|
|
|
for (var i=1; i<=maxPortLevel; i++) { |
34
|
|
|
df['port'+i].value = 0; |
35
|
|
|
} |
36
|
|
|
df.total.value = 0; |
37
|
|
|
}; |
38
|
|
|
|
39
|
|
|
// Set the port race distribution to be equal |
40
|
|
|
window.setEven = function() { |
41
|
|
|
var i = 2, df=document.FORM; |
42
|
|
|
df.race1.value = 12; |
43
|
|
|
for(; i<=9; i++) { |
44
|
|
|
df['race'+i].value = 11; |
45
|
|
|
} |
46
|
|
|
df.racedist.value = 100; |
47
|
|
|
}; |
48
|
|
|
|
49
|
|
|
var body, currentlyFlashing=false, flashColour, origColour, intervalFlash, timeoutStopFlash; |
50
|
|
|
|
51
|
|
|
function stopFlash() { |
52
|
|
|
clearInterval(intervalFlash); |
53
|
|
|
body.style.backgroundColor = origColour; |
|
|
|
|
54
|
|
|
currentlyFlashing = false; |
55
|
|
|
}; |
56
|
|
|
|
57
|
|
|
function bgFlash() { |
58
|
|
|
var body = document.getElementsByTagName('body')[0]; |
59
|
|
|
if(body.style.backgroundColor === origColour) { |
60
|
|
|
body.style.backgroundColor = flashColour; |
61
|
|
|
} |
62
|
|
|
else { |
63
|
|
|
body.style.backgroundColor = origColour; |
64
|
|
|
} |
65
|
|
|
}; |
66
|
|
|
|
67
|
|
|
window.triggerAttackBlink = function(colour) { |
68
|
|
|
if(origColour == null) { |
|
|
|
|
69
|
|
|
origColour = document.getElementsByTagName('body')[0].style.backgroundColor; |
70
|
|
|
} |
71
|
|
|
flashColour = '#'+colour; |
72
|
|
|
clearTimeout(timeoutStopFlash); |
73
|
|
|
if (currentlyFlashing === false) { |
74
|
|
|
currentlyFlashing = true; |
75
|
|
|
//flash 3 times |
76
|
|
|
bgFlash(); |
77
|
|
|
intervalFlash = setInterval(bgFlash,500); |
78
|
|
|
} |
79
|
|
|
timeoutStopFlash = setTimeout(stopFlash,3500); |
80
|
|
|
}; |
81
|
|
|
})(); |
82
|
|
|
|
83
|
|
|
// Used by shop_hardware.php |
84
|
|
|
function recalcOnKeyUp(transaction, hardwareTypeID, cost) { |
85
|
|
|
var form = document.getElementById(transaction + hardwareTypeID); |
86
|
|
|
form.total.value = form.amount.value * cost; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
// Used by planet_defense.php |
90
|
|
|
function showWeaponInfo(select) { |
91
|
|
|
var target = $(select).data('target'); |
92
|
|
|
var show = $("option:selected", select).data('show'); |
93
|
|
|
$(target).children().addClass('hide'); |
94
|
|
|
$(show).removeClass('hide'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
// Used by game_join.php |
98
|
|
|
function showRaceInfo(select) { |
99
|
|
|
var race_id = $("option:selected", select).val(); |
100
|
|
|
document.getElementById('race_image').src = "images/race/race" + race_id + ".jpg"; |
101
|
|
|
var desc = document.getElementById('race_descr'); |
102
|
|
|
$(desc).children().addClass('hide'); |
103
|
|
|
$(".race_descr" + race_id, desc).removeClass('hide'); |
104
|
|
|
createRaceRadarChart(race_id); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
// Used by game_join.php |
108
|
|
|
function createRaceRadarChart(race_id) { |
109
|
|
|
|
110
|
|
|
// Each array key is the race ID |
111
|
|
|
var races = { |
112
|
|
|
2: [[5.2, 10.0, 5.8, 8.1, 5.2], 'Alskant', '#FF00FF'], |
113
|
|
|
3: [[8.3, 5.0, 10.0, 3.3, 8.3], 'Creonti', '#FF8000'], |
114
|
|
|
4: [[9.5, 4.9, 9.5, 7.7, 9.5], 'Human', '#0000FF'], |
115
|
|
|
5: [[8.0, 6.1, 9.7, 10.0, 8.0], 'Ik\'Thorne', '#BFBFFF'], |
116
|
|
|
6: [[8.1, 4.7, 8.8, 4.3, 8.1], 'Salvene', '#00AA00'], |
117
|
|
|
7: [[10.0, 5.7, 8.7, 9.1, 10.0], 'Thevian', '#800000'], |
118
|
|
|
8: [[7.2, 6.3, 7.9, 6.2, 7.2], 'WQ Human', '#804040'], |
119
|
|
|
9: [[9.5, 4.9, 8.0, 5.1, 9.5], 'Nijarin', '#FF8080'] |
120
|
|
|
}; |
121
|
|
|
|
122
|
|
|
var data = [ |
123
|
|
|
{ |
124
|
|
|
type: 'scatterpolar', |
125
|
|
|
r: races[race_id][0], |
126
|
|
|
theta: ['Hunting', 'Trading', 'Combat', 'Utility', 'Hunting'], |
127
|
|
|
fill: 'toself', |
128
|
|
|
name: races[race_id][1], |
129
|
|
|
line: {color: races[race_id][2]}, |
130
|
|
|
title: { |
131
|
|
|
text: races[race_id][1] |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
]; |
135
|
|
|
|
136
|
|
|
var layout = { |
137
|
|
|
showlegend: true, |
138
|
|
|
polar: { |
139
|
|
|
radialaxis: { |
140
|
|
|
visible: true, |
141
|
|
|
showgrid: true, |
142
|
|
|
range: [0, 10], |
143
|
|
|
color: '#fff', |
144
|
|
|
}, |
145
|
|
|
bgcolor: '#111' |
146
|
|
|
}, |
147
|
|
|
paper_bgcolor: '#06240E', |
148
|
|
|
font: { |
149
|
|
|
color: '#fff' |
150
|
|
|
}, |
151
|
|
|
margin: { l: 170, r: 170, t: 0, b: 0 }, |
152
|
|
|
coloraxis: '#000' |
153
|
|
|
}; |
154
|
|
|
|
155
|
|
|
Plotly.newPlot('graphframe', data, layout, {staticPlot: true}); |
|
|
|
|
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
// Used by alliance_create.php and alliance_stat.php |
159
|
|
|
function togglePassword(select) { |
160
|
|
|
var showPassword = $(select).val() === "password"; |
161
|
|
|
// We need to both toggle the element display (for the user) and toggle the |
162
|
|
|
// disabled property (for the form submission). |
163
|
|
|
if (showPassword) { |
164
|
|
|
$("#password-display").show(); |
165
|
|
|
} else { |
166
|
|
|
$("#password-display").hide(); |
167
|
|
|
} |
168
|
|
|
$("#password-input").prop("disabled", !showPassword); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
// Used by message_view.php |
172
|
|
|
function toggleScoutGroup(senderID) { |
173
|
|
|
$('#group'+senderID).toggle(); |
174
|
|
|
} |
175
|
|
|
|