-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.js
executable file
·90 lines (69 loc) · 1.72 KB
/
map.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
class Map {
static objs = {}
constructor (name) {
Map.objs[name] = this
}
}
class MapView {
static draw_hexagon(x, y, size) {
const ctx = MapView.canvas.getContext('2d')
ctx.beginPath();
ctx.moveTo(x + size * Math.cos(0), y + size * Math.sin(0));
for (var i = 1; i <= 6; i++) {
ctx.lineTo(x + size * Math.cos(i * 2 * Math.PI / 6), y + size * Math.sin(i * 2 * Math.PI / 6));
}
ctx.closePath();
ctx.stroke();
}
static drawSquare(x, y, size) {
const ctx = MapView.canvas.getContext('2d')
ctx.beginPath();
ctx.rect(x, y, size, size);
ctx.stroke();
}
static get_html () {
const html = `
<div id="map-container">
<div id="map-creation-container">
<h1>Creation</h1>
<div>
<select id="map-selector">
<option></option>
</select>
</div>
<div>
<label for="map-name">Name</label>
<input type="text" id="map-name" />
</div>
<div>
<label for="map-lines">Lines</label>
<input type="number" id="map-lines" min="1" max="7" />
</div>
<div>
<label for="map-columns">Columns</label>
<input type="number" id="map-columns" min="1" max="18" />
</div>
<button>Create map</button>
</div>
<div>
<h1>Grid</h1>
<canvas id="map-canvas" width="1799" height="699"/>
</div>
</div>`
return html
}
static draw_grid () {
const lines = 7
const columns = 18
const factor = 100
for (let i = 0; i < lines; i++) {
for (let j = 0; j < columns; j++) {
MapView.drawSquare((factor*j), (factor*i), factor)
}
}
}
}
new Content('map', MapView.get_html())
MapView.container = document.getElementById('map-container')
MapView.canvas = document.getElementById('map-canvas')
MapView.draw_grid()