forked from SiegeEngineers/aoe2techtree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
265 lines (240 loc) · 9.89 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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<meta charset="utf-8"/>
<title>Age of Empires II Tech Tree</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="container">
<div id="navigation">
<select id="civselect" onchange="loadCiv()">
<option>Aztecs</option>
<option>Berbers</option>
<option>Britons</option>
<option>Burmese</option>
<option>Byzantines</option>
<option>Celts</option>
<option>Chinese</option>
<option>Ethiopians</option>
<option>Franks</option>
<option>Goths</option>
<option>Huns</option>
<option>Incas</option>
<option>Indians</option>
<option>Italians</option>
<option>Japanese</option>
<option>Khmer</option>
<option>Koreans</option>
<option>Magyars</option>
<option>Malay</option>
<option>Malians</option>
<option>Mayans</option>
<option>Mongols</option>
<option>Persians</option>
<option>Portuguese</option>
<option>Saracens</option>
<option>Slavs</option>
<option>Spanish</option>
<option>Teutons</option>
<option>Turks</option>
<option>Vietnamese</option>
<option>Vikings</option>
</select>
<div id="info">Version: Age of Empires II HD Patch 5.8 |
<a href="https://github.com/HSZemi/aoe2techtree" target="_blank">GitHub</a>
</div>
</div>
<div id="wrapper">
<div id="metainfo">
<div id="civinfo">
<h2 id="civname">Loading…</h2>
<hr>
<p id="civtext"></p>
</div>
<div id="thanks">
Made by
<a href="https://hszemi.de" target="_blank">hszemi</a>, with huge thanks to Jineapple, TriRem, and pip
<br> Descriptions taken from the
<a href="https://www.voobly.com/gamemods/mod/650/Max-Extended-Help-AK" target="_blank">Max-Extended-Help-WK
mod</a>
<br> Item Metadata (cost, HP etc.) taken from
<a href="https://github.com/HSZemi/aoe2dat" target="_blank">aoe2dat</a>
</div>
</div>
<div id="techtree">
<div id="helptext"></div>
</div>
</div>
</div>
<script src="js/svg.min.js"></script>
<script src="js/techtree.js"></script>
<script src="js/civs.js"></script>
<script type="text/javascript">
var tree = getDefaultTree();
var data = {};
let connections = getConnections();
let connectionpoints = getConnectionPoints(tree);
loadJson(function (response) {
data = JSON.parse(response);
let hash = window.location.hash.substr(1);
if (hash in data.civs) {
document.getElementById('civselect').value = hash;
}
var draw = SVG('techtree').size(tree.width, tree.height)
draw.rect(tree.width, tree.height).attr({fill: '#e7c28e'}).click(function () {
hideHelp();
});
draw.rect(tree.width, 6).attr({fill: '#4d3617'}).click(function () {
hideHelp();
}).y(tree.height / 4);
draw.rect(tree.width, 6).attr({fill: '#4d3617'}).click(function () {
hideHelp();
}).y(tree.height / 4 * 2);
draw.rect(tree.width, 6).attr({fill: '#4d3617'}).click(function () {
hideHelp();
}).y(tree.height / 4 * 3);
for (let connection of connections) {
let from = connectionpoints.get(connection[0]);
let to = connectionpoints.get(connection[1]);
let intermediate_height = from.y + (tree.element_height * 2 / 3);
draw.polyline([from.x, from.y, from.x, intermediate_height, to.x, intermediate_height, to.x, to.y])
.fill('none').stroke({width: 2})
.click(function () {
hideHelp();
});
}
for (let lane of tree.lanes) {
for (let r of Object.keys(lane.rows)) {
let row = lane.rows[r];
for (let caret of row) {
var rect = draw.rect(caret.width, caret.height).attr({
fill: caret.type.colour,
id: caret.id
}).move(caret.x, caret.y);
let name = formatName(caret.name);
var text = draw.text(name)
.font({family: 'Helvetica', size: 8})
.attr({fill: '#fff', 'text-anchor': 'middle', id: caret.id + '_text'})
.move(caret.x + caret.width / 2, caret.y + caret.height / 1.5);
var image_placeholder = draw.rect(caret.width * 0.6, caret.height * 0.6)
.attr({fill: 'rgba(0,0,0,0.5)', id: caret.id + '_imgph'})
.move(caret.x + caret.width * 0.2, caret.y);
let prefix = 'img/';
var image = draw.image(prefix + imagePrefix(caret.id) + '.png', caret.width * 0.6, caret.height * 0.6)
.attr({id: caret.id + '_img'})
.move(caret.x + caret.width * 0.2, caret.y);
var cross = draw.polygon([1, 0, 3, 2, 5, 0, 6, 1, 4, 3, 6, 5, 5, 6, 3, 4, 1, 6, 0, 5, 2, 3, 0, 1])
.attr({fill: 'rgba(255,0,0,0.5)', id: caret.id + '_x'})
.addClass('cross')
.size(caret.width * 0.6, caret.height * 0.6)
.move(caret.x + caret.width * 0.2, caret.y);
var overlaytrigger = draw.rect(caret.width, caret.height)
.attr({fill: 'rgba(0,0,0,0)', id: caret.id + '_overlay'})
.move(caret.x, caret.y)
.data({'type': caret.type.type, 'caret': caret, 'name': caret.name, 'id': caret.id})
.click(function () {
displayHelp(caret.id + '_overlay');
});
}
}
}
loadCiv();
});
function imagePrefix(name) {
return name
.replace("building_", "Buildings/")
.replace("unit_", "Units/")
.replace("tech_", "Techs/");
}
function loadCiv() {
var selectedCiv = document.getElementById('civselect').value;
civ(selectedCiv, tree);
document.getElementById('civname').innerText = selectedCiv;
if (selectedCiv in data.civs) {
document.getElementById('civtext').innerHTML = data.key_value[data.civs[selectedCiv]];
window.location.hash = selectedCiv;
} else {
document.getElementById('civtext').innerHTML = "";
}
hideHelp();
}
function loadJson(callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', 'data/data.json', true);
xobj.onreadystatechange = function () {
if (xobj.readyState === 4 && xobj.status === 200) {
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
callback(xobj.responseText);
}
};
xobj.send(null);
}
function displayHelp(overlayId) {
let helptext = document.getElementById("helptext");
let overlay = SVG.get(overlayId);
let name = overlay.data('name');
let id = overlay.data('id');
let caret = overlay.data('caret');
let type = overlay.data('type');
let content = getHelpText(name, id, type);
helptext.innerHTML = content;
helptext.style.display = "block";
let top = caret.y + caret.height;
if (top + helptext.offsetHeight > tree.height) {
top = top - helptext.offsetHeight - caret.height;
}
helptext.style.top = top + "px";
helptext.style.left = Math.max(0, (caret.x - helptext.offsetWidth)) + "px";
let helpbox = helptext.getBoundingClientRect();
if (helpbox.left < 0) {
helptext.style.left = Math.max(0, (caret.x - helptext.offsetWidth)) - helpbox.left + "px";
}
}
function hideHelp() {
helptext.style.display = "none";
}
function getHelpText(name, id, type) {
let entitytype = 'buildings';
if (type === "UNIT" || type === "UNIQUEUNIT") {
entitytype = 'units';
}
if (type === "TECHNOLOGY") {
entitytype = 'techs';
}
let text = data.key_value[data.name_key[entitytype][name]];
if (text === undefined) {
return "?";
}
let meta = data.meta[entitytype][name];
text = text.replace(/‹cost›/, "Cost: " + cost(meta.Cost));
text = text.replace(/‹hp›/, "HP: " + meta.HP);
text = text.replace(/‹attack›/, "Attack: " + meta.Attack);
text = text.replace(/‹Armor›/, "Armor: " + meta.MeleeArmor);
text = text.replace(/‹Piercearmor›/, "Piercearmor: " + meta.PierceArmor);
text = text.replace(/‹garrison›/, "Garrison: " + meta.GarrisonCapacity);
text = text.replace(/‹range›/, "Range: " + meta.Range);
return text;
}
function cost(cost_object) {
let value = "";
if ("Food" in cost_object) {
value += " " + cost_object.Food + "F";
}
if ("Wood" in cost_object) {
value += " " + cost_object.Wood + "W";
}
if ("Gold" in cost_object) {
value += " " + cost_object.Gold + "G";
}
if ("Stone" in cost_object) {
value += " " + cost_object.Stone + "S";
}
return value;
}
</script>
</body>
</html>