-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
158 lines (147 loc) · 5.52 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
<html>
<head>
<link rel="shortcut icon" href="favicon.ico">
<title>GoBan - vios.ai - Go Game v0.3.3</title>
<script src="goban.js"></script>
<style>
* {
margin: 0; padding: 0;
border-spacing: 0;
box-sizing: border-box;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
table {
margin-left: auto;
margin-right: auto;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body onresize="resizeHandler()">
<table>
<tr>
<td class="ui" colspan=3 align="center" style="margin-left: auto; margin-right: auto;">
<button type="submit" onclick="doLoad('sgf-autoSave');">Load Auto Save</button> or
<button type="submit" onclick="doLoad(selList.value);">Load</button>:
<select id="saveList"></select> or
<input type="file" id="fileSel" onchange="doLoadFile(files[0]);" style="width: 24ch" />
- or -
<button type="submit" onclick="doSave();">Save/Export</button>
<div style="display: inline-block;" id="saveInfo">...</div><br />
</td>
</tr>
<tr>
<td id="goban-container" style="width: 100%" colspan="3">
<canvas id="goban" style="cursor: none;"></canvas>
</td>
<tr td class="ui">
<td>
Coords: <input type="checkbox" onchange="goban.withCoordinates=this.checked;goban.Redraw();" checked />,
Move#: <input type="checkbox" onchange="goban.withMoveNumbers=this.checked;goban.Redraw();" />,
Infos: <input type="checkbox" onchange="goban.withGroupNumbers=this.checked;goban.Redraw();" checked />,
Sound: <input type="checkbox" onchange="goban.withSounds=this.checked;" checked />
</td>
<td>
<select onchange="goban.SetMode(value)">
<option value="P" selected>Play</option>
<option value="B">Place B</option>
<option value="W">Place W</option>
</select>
Size:
<!--
<input type="radio" name="size" value="9" onchange="goban.Resize(9);resizeHandler();" checked> 9x9
<input type="radio" name="size" value="13" onchange="goban.Resize(13);resizeHandler();"> 13x13
<input type="radio" name="size" value="19" onchange="goban.Resize(19);resizeHandler();"> 19x19
-->
<select onchange="goban.Resize(parseInt(value));resizeHandler();">
<option value="19">19x19</option>
<option value="13">13x13</option>
<option value="9" selected>9x9</option>
</select>
</td>
<td align="right">
<button type="submit" onmouseover="goban.withLastMoveHighlight=true; goban.Redraw();" onmouseout="goban.withLastMoveHighlight=false; goban.Redraw();" onclick="goban.Undo();">Undo last move</button>
</td>
</tr>
</table>
<script>
var goban = new GoBan(9)
function resizeHandler() {
var size = goban.n
console.log("Size is " + size)
var min = window.innerHeight
var scaling = 0.90
if (min * scaling > window.innerWidth) {
min = window.innerWidth
scaling = 1
}
if (window.innerHeight <= scale * min) {
min = window.innerHeight
scale = 0.9 // 90% so there is room for UI at top/bottom
}
console.log("Min Height/Width is " + min)
var sz = size + 2 // +1 for goban border +1 for coords
if (!goban.ui) {
scaling = 1 // 100%
sz -= 1 // no extra space for coords
}
var scale = Math.floor(min * scaling / sz + 0.0001)
console.log("New scale is " + scale + " device px ratio " + window.devicePixelRatio)
goban.Draw(document.getElementById("goban"), scale);
//goban.drawStone(1,1, "orange", 399)
return true // (redraw) already done. goban.html doesn't return true
}
resizeHandler()
var selList = document.getElementById("saveList")
if (!localStorage.nSavedGames) {
localStorage.nSavedGames = 0
}
for (i = 1; i <= localStorage.nSavedGames; i++) {
var option = document.createElement("option");
option.text = "sgf-" + i
selList.add(option)
}
selList.selectedIndex = localStorage.nSavedGames - 1
function doSave(gameIdx = undefined) {
if (!gameIdx) {
gameIdx = ++localStorage.nSavedGames
}
var name = "sgf-" + gameIdx
localStorage.setItem(name, goban.Save())
var option = document.createElement("option");
option.text = name
selList.add(option)
selList.selectedIndex = localStorage.nSavedGames - 1
var info = document.getElementById("saveInfo")
var uriContent = "data:application/sgf," + encodeURIComponent(goban.Save());
info.innerHTML = "Saved <a download='" + name + ".sgf' href='" + uriContent + "'>" + name + "</a>";
}
function doLoad(name) {
if (goban.Load(localStorage.getItem(name))) {
resizeHandler()
}
}
function doLoadFile(f) {
console.log("doLoadFile called for " + f.name + " sz " + f.size)
var reader = new FileReader();
reader.onload = function(e) {
var data = e.target.result;
if (goban.Load(data)) {
resizeHandler()
}
}
reader.readAsText(f);
}
function doLoadURL(url) {
console.log('Attempting to load url', url)
fetch(url).then(doc => doc.blob()).then((blob) => {
doLoadFile(blob)
}).catch(err => { throw err })
}
var qs = window.location.search
if (qs.startsWith("?url=")) {
doLoadURL(decodeURIComponent(qs.substr(5)))
}
</script>
</body>
</html>