-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
324 lines (295 loc) · 12.2 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sam's Battle Map</title>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<style>
:root {
--image-width: 1920px;
--image-height: 1070px;
--tile-width: 70px;
--tile-height: var(--tile-width);
--grid-line-width: 2px;
--grid-colour: Black;
--background-image: url("./Maps/towncross.jpg");
--x-offset: 10px;
--y-offset: 10px;
}
#main {
height: var(--image-height);
position: relative;
width: var(--image-width);
background-image: var(--background-image);
background-size: contain;
background-repeat: no-repeat;
margin: -8px 0px 0 -8px;
}
.grid {
background-image: repeating-linear-gradient(0deg,transparent,transparent calc(var(--tile-width) - var(--grid-line-width)),var(--grid-colour) calc(var(--tile-width) - var(--grid-line-width)),var(--grid-colour) var(--tile-width)),
repeating-linear-gradient(-90deg,transparent,transparent calc(var(--tile-height) - var(--grid-line-width)),var(--grid-colour) calc(var(--tile-height) - var(--grid-line-width)),var(--grid-colour) var(--tile-height));
background-size: var(--tile-width) var(--tile-height);
height: 100%;
position: absolute;
width: 100%;
margin-left: var(--x-offset);
margin-top: var(--y-offset);
}
.sidebar { height:95%;width:215px;background-color:rgb(0,0,0,0.75);position:fixed!important;z-index:1;margin-top: 8px; color: White;
}
.sidebar_button {
width: 190px;
position: fixed;
margin-left: 0px;
margin-top: 8px;
z-index: 1;
}
.medium {
width: 100%;
height: 100%;
max-height: calc(var(--tile-height) - var(--grid-line-width));
max-width: calc(var(--tile-width) - var(--grid-line-width));
margin-left: var(--grid-line-width);
margin-top: var(--grid-line-width);
background-size: 100% 100%;
}
.large {
width: 100%;
height: 100%;
max-height: calc(2 * var(--tile-height) - var(--grid-line-width));
max-width: calc(2 * var(--tile-width) - var(--grid-line-width));
margin-left: var(--grid-line-width);
margin-top: var(--grid-line-width);
background-size: 100% 100%;
}
.huge {
width: 100%;
height: 100%;
max-height: calc(3 * var(--tile-height) - var(--grid-line-width));
max-width: calc(3 * var(--tile-width) - var(--grid-line-width));
margin-left: var(--grid-line-width);
margin-top: var(--grid-line-width);
background-size: 100% 100%;
}
.draggable { float: left; }
</style>
</head>
<body>
<script>
var htmlStyles = window.getComputedStyle(document.querySelector("html"));
var tileWidth = parseInt(htmlStyles.getPropertyValue("--tile-width"));
var tileHeight = parseInt(htmlStyles.getPropertyValue("--tile-height"));
var xOffset = parseInt(htmlStyles.getPropertyValue("--x-offset")) + 1;
var yOffset = parseInt(htmlStyles.getPropertyValue("--y-offset")) + 1;
var gridColour = htmlStyles.getPropertyValue("--grid-colour");
var x = "Black";
var y = 42;
var z = htmlStyles.getPropertyValue("--background-image");
function sidebar_open() {
document.getElementById("sidebar").style.display = "block";
document.getElementById("sidebar_button").style.display = "none";
}
function sidebar_close() {
document.getElementById("sidebar").style.display = "none";
document.getElementById("sidebar_button").style.display = "block";
}
function value_update_line_colour() {
x = document.getElementById("gridColourInput").value;
document.documentElement.style.setProperty('--grid-colour', x);
}
function value_update_line_width() {
x = document.getElementById("gridWidthInput").value;
document.documentElement.style.setProperty('--grid-line-width', x + "px");
}
function value_update_grid_size() {
x = document.getElementById("tileWidthInput").value;
document.documentElement.style.setProperty('--tile-width', x + "px");
}
function value_update_grid_x_offset() {
x = document.getElementById("tileXOffsetInput").value;
document.documentElement.style.setProperty('--x-offset', x + "px");
}
function value_update_grid_y_offset() {
x = document.getElementById("tileYOffsetInput").value;
document.documentElement.style.setProperty('--y-offset', x + "px");
}
function background_update() {
mapString = document.getElementById("backgroundInput").value;
document.documentElement.style.setProperty('--background-image', "url(./Maps/" + mapString + ")");
}
function spawn_creature() {
y = document.getElementById("monsterSpawn").value;
z = document.getElementById("monsterSpawnNumber").value;
x = document.getElementById("monsterSpawnSize").value;
// return if it already exists
if (document.contains(document.getElementById("monster_" + y + "_" + z))) {
return;
}
translate_x = htmlStyles.getPropertyValue("--x-offset");
translate_y = htmlStyles.getPropertyValue("--y-offset");
var div = document.createElement("div");
div.id = "monster_" + y + "_" + z;
div.classList.add(x);
div.classList.add("draggable");
div.classList.add("container")
div.style.backgroundImage = "url('./Beasts/" + y + "')";
div.style.transform = "translate(" + translate_x + ", " + translate_y + ")";
$( div ).draggable({
grid: [parseInt(htmlStyles.getPropertyValue("--tile-width")),
parseInt(htmlStyles.getPropertyValue("--tile-width"))
]});
var divNumber = document.createTextNode(z);
divNumber.style
div.appendChild(divNumber);
document.getElementById("main").appendChild(div);
// Sidebar
var sidebarDiv = document.createElement("div");
sidebarDiv.id = "sidebar_monster_" + y + "_" + z;
var divLabel = document.createTextNode(y + " " + z + ": ");
var divInput = document.createElement("input");
divInput.setAttribute("type", "text");
sidebarDiv.appendChild(divLabel);
sidebarDiv.appendChild(divInput);
document.getElementById("sidebar").appendChild(sidebarDiv);
}
function destroy_creature() {
y = document.getElementById("monsterSpawn").value;
z = document.getElementById("monsterSpawnNumber").value;
// return if it doesn't exist
if (!document.contains(document.getElementById("monster_" + y + "_" + z))) {
return;
}
var creature = document.getElementById("monster_" + y + "_" + z);
document.getElementById("main").removeChild(creature);
// Sidebar
var sidebar_monster = document.getElementById("sidebar_monster_" + y + "_" + z);
document.getElementById("sidebar").removeChild(sidebar_monster);
}
function sidebar_add_creature() {
y = document.getElementById("monsterSpawn").value;
z = document.getElementById("monsterSpawnNumber").value;
var sidebarDiv = document.createElement("div");
sidebarDiv.id = "sidebar_monster_" + y + "_" + z;
var divLabel = document.createTextNode(y + " " + z + ": ");
var divInput = document.createElement("input");
divInput.setAttribute("type", "text");
sidebarDiv.appendChild(divLabel);
sidebarDiv.appendChild(divInput);
document.getElementById("sidebar").appendChild(sidebarDiv);
}
function sidebar_remove_creature() {
y = document.getElementById("monsterSpawn").value;
z = document.getElementById("monsterSpawnNumber").value;
var sidebar_monster = document.getElementById("sidebar_monster_" + y + "_" + z);
document.getElementById("sidebar").removeChild(sidebar_monster);
}
function spawn_player(characterName) {
// Destroy div if it already exists
if (document.contains(document.getElementById(characterName))) {
document.getElementById(characterName).remove();
}
// Create new div
var div = document.createElement("div");
div.id = characterName;
div.classList.add("medium");
div.classList.add("draggable");
div.style.backgroundImage = "url('./Characters/" + characterName + ".jpg')";
div.style.transform = "translate(" + htmlStyles.getPropertyValue("--x-offset") + ", " + htmlStyles.getPropertyValue("--y-offset") + ")";
$( div ).draggable({
grid: [parseInt(htmlStyles.getPropertyValue("--tile-width")),
parseInt(htmlStyles.getPropertyValue("--tile-width"))
]});
document.getElementById("main").appendChild(div);
// Keep the sidebar if that already exists
if (document.contains(document.getElementById("sidebar_" + characterName))) {
return;
}
var sidebarDiv = document.createElement("div");
sidebarDiv.id = "sidebar_" + characterName;
var divLabel = document.createTextNode(characterName + ": ");
var divInput = document.createElement("input");
divInput.setAttribute("type", "text");
sidebarDiv.appendChild(divLabel);
sidebarDiv.appendChild(divInput);
document.getElementById("sidebar").appendChild(sidebarDiv);
}
function spawn_players() {
spawn_player("Choke");
spawn_player("FaceSmasher");
spawn_player("Bardolemew");
spawn_player("Lucy");
spawn_player("Wen");
}
</script>
<div class = "sidebar_button" style="Display=block" id = "sidebar_button">
<button style="Button" onclick="sidebar_open()">☰</button>
</div>
<div class="sidebar" style="display:none" id = "sidebar">
<button onclick="sidebar_close()" type="Button">☰</button>
<br>
<label for="backgroundInput">Map:</label><br>
<select id="backgroundInput" oninput="background_update()">
<option value="towncross.jpg">Town Cross</option>
<option value="mine.png">Mine</option>
<option value="townmarket.png">Town Market</option>
<option value="testmapfromreddit.jpg">Test map </option>
</select>
<br>
<form>
<label for="gridColourInput">Grid Colour:</label>
<select id="gridColourInput" onclick="value_update_line_colour()">
<option value="Black">Black</option>
<option value="Red">Red</option>
<option value="White">White</option>
<option value="Blue">Blue</option>
</select><br>
<label for="gridWidthInput">Grid Width:</label>
<select id="gridWidthInput" onclick="value_update_line_width()">
<option value="0">Hidden</option>
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
</select><br>
<label for="tileWidth">Tile Width:</label><br>
<input type="range" id="tileWidthInput" name="tileWidth" min="5" max="250" value="70" oninput="this.form.tileWidthInputNumeric.value=this.value; value_update_grid_size()"/>
<input type="number" name="tileWidthInputNumeric" min="5" max="250" value="70" oninput="this.form.tileWidthInput.value=this.value; value_update_grid_size()"/>
<br>
<label for="tileXOffset">X Offset:</label><br>
<input type="range" id="tileXOffsetInput" name="tileXOffset" min="-125" max="125" value="10" oninput="this.form.tileXOffsetInputNumeric.value=this.value; value_update_grid_x_offset()"/>
<input type="number" name="tileXOffsetInputNumeric" min="-125" max="125" value="10" oninput="this.form.tileXOffsetInput.value=this.value; value_update_grid_x_offset()"/>
<br>
<label for="tileYOffset">Y Offset:</label><br>
<input type="range" id="tileYOffsetInput" name="tileYOffset" min="-125" max="125" value="10" oninput="this.form.tileYOffsetInputNumeric.value=this.value; value_update_grid_y_offset()"/>
<input type="number" name="tileYOffsetInputNumeric" min="-125" max="125" value="10" oninput="this.form.tileYOffsetInput.value=this.value; value_update_grid_y_offset()"/>
</form>
Creature:<br>
<select id="monsterSpawnSize">
<option value="medium">Medium</option>
<option value="large" >Large </option>
<option value="huge" >Huge </option>
</select>
<select id="monsterSpawn">
<option value="owlbear.gif">Owl Bear</option>
<option value="beholder.png">Beholder</option>
</select>
<select id="monsterSpawnNumber">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<br>
<button onclick="spawn_creature()" type="Button">Spawn</button>
<button onclick="destroy_creature()" type="Button">Remove</button>
<br>
<button onclick="spawn_players()" type="Button">Refresh Players</button>
<br><br>
</div>
<div id="main">
<div class="grid"/>
</div>
</body>
</html>