forked from foolswood/Hexagongame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.html
161 lines (143 loc) · 4.61 KB
/
editor.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
<html>
<style>
.pile {position:relative; height: 90%}
.thing {position: absolute; display: none; width: 100%; height: 100%}
ul {list-style-type: circle}
</style>
<body>
<div style="height: 100%; width: 70%; float: left">
<object id="A" type="image/svg+xml" data="hexagons.svg" width="100%" height="60%" style="border:thin solid black"></object>
<div id="tools" style="border: thin solid black; height:40%">
<div id="tool_menu">
<select id="tool_select", onchange="tool_select(this.value)">
<option value="json">Json</option>
<option value="plain">Plain</option>
</select>
<button type="button" onclick="apply()">Apply</button>
</div>
<div class="pile">
<textarea id="json" class="thing">{"maze":["RgB"],"start":[0,0],"end":[1,0],"startcolour":"w"}</textarea>
<textarea id="plain" class="thing">RgB</textarea>
</div>
</div>
</div>
<div style="float: left; width:29%; height: 100%; border: thin solid black">
<div>
<button type="button" onclick="analyse()">Analyse</button>
<select id="hex_select", onchange="filter_solutions()">
</select>
</div>
<ul id="solution_list">
</ul>
</div>
</body>
<script src="svg_interface.es" type="text/ecmascript"></script>
<script src="serialiser.es" type="text/ecmascript"></script>
<script src="std_game.es" type="text/ecmascript"></script>
<script src="menu_maze.es" type="text/ecmascript"></script>
<script src="solver.es" type="text/ecmascript"></script>
<script>
var iface, active_tool
var level = JSON.parse(document.getElementById("json").value)
var game, solutions
var solver_bg_colours = {
"r": "mistyrose",
"b": "lavender",
"g": "lightgreen",
"y": "lemonchiffon",
"w": "white",
"k": "gainsboro"}
function tool_select(val) {
var prev = active_tool
active_tool = document.getElementById(val)
active_tool.setup()
active_tool.style.display = "block"
if (prev !== undefined) {
prev.style.display = "none"
}
}
var clearChildren = function(thing) {
while (thing.childNodes.length >= 1) {
thing.removeChild(thing.firstChild)
}
}
var prev_route_li
var route_draw = function(soln) {
var drawer = function() {
iface.addRoute(soln)
if (prev_route_li != undefined) {
prev_route_li.style.listStyleType = "circle"
}
this.style.listStyleType = "disc"
prev_route_li = this
}
return drawer
}
var show_solutions = function(solns) {
var sol_list = document.getElementById("solution_list")
clearChildren(sol_list)
var sol, sol_li, sol_span, soln
for (var s=0; s<solns.length; s++) {
soln = solns[s]
sol_li = document.createElement("li")
for (var t=0; t<soln.length; t++) {
sol = document.createTextNode(JSON.stringify(soln[t][0]))
sol_span = document.createElement("span")
sol_span.style.backgroundColor = solver_bg_colours[soln[t][1]]
sol_span.appendChild(sol)
sol_li.appendChild(sol_span)
sol_li.onclick = route_draw(soln)
}
sol_list.appendChild(sol_li)
}
}
function filter_solutions() {
var select_value = document.getElementById("hex_select").value
// Handle the special case where value is ""
var solns = solutions[select_value]
var ep = JSON.parse(select_value)
var solns_with_end = []
for (var s=0; s<solns.length; s++) {
solns_with_end.push(solns[s].concat([ep]))
}
show_solutions(solns_with_end)
}
function analyse() {
solutions = solver([level.start, "w"], get_std_moves_func(iface))
var state_dropdown = document.getElementById("hex_select")
var state_text, state_option
clearChildren(state_dropdown)
for (var s in solutions) {
state_text = document.createTextNode(s)
state_option = document.createElement("option", value=s)
state_option.appendChild(state_text)
state_dropdown.appendChild(state_option)
}
filter_solutions()
}
function preview() {
gameStandard(iface, level, preview)
}
function apply() {
active_tool.apply()
preview()
}
document.getElementById("json").setup = function() {
this.value = JSON.stringify(level)
}
document.getElementById("json").apply = function() {
level = JSON.parse(this.value)
}
document.getElementById("plain").setup = function() {
this.value = level.maze.join('\n')
}
document.getElementById("plain").apply = function() {
level.maze = this.value.split('\n')
}
window.onload = function() {
iface = new SVGInterface("A")
tool_select(document.getElementById("tool_select").value)
preview()
}
</script>
</html>