-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapedit.js
57 lines (44 loc) · 1.5 KB
/
mapedit.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
var svgns = "http://www.w3.org/2000/svg";
var mySvg;
var game_map;
var armies = Array(2);
window.onload = main;
function mapedit_hex_click(evt) {
var hex = evt.target;
var x = hex.getAttribute("gamemap_x");
var y = hex.getAttribute("gamemap_y");
game_map.map[x][y].tile_type += 1;
game_map.map[x][y].tile_type %= 8;
hex.setAttribute("fill", gamemap_get_fill(game_map.map[x][y].tile_type));
}
function mapedit_dump() {
game_map.Dump();
}
function main()
{
var container = document.getElementById("svgContainer");
mySvg = document.createElementNS(svgns, "svg");
mySvg.setAttribute("viewBox", "0 0 1280 700");
mySvg.setAttribute("version", "1.2");
mySvg.setAttribute("baseProfile", "tiny");
container.appendChild(mySvg);
game_map = new GameMap(15, 11);
for (var y = 0; y < game_map.height; y++)
{
for (var x = 0; x < game_map.width; x++)
{
game_map.map[x][y].sprite.setAttribute("gamemap_x", x);
game_map.map[x][y].sprite.setAttribute("gamemap_y", y);
game_map.map[x][y].sprite.setAttribute("onclick", "mapedit_hex_click(evt)");
}
}
var button =
create_hexagon
(
gamemap_get_map_screenx(game_map.width + 1),
gamemap_get_map_screeny(game_map.width + 1, 1),
hex_size,
"red"
);
button.setAttribute("onclick", "mapedit_dump()");
}