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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
|
<?php
include_once('./includes/maps.php');
include_once('./includes/mapclass.php');
//Self-ajax.
if ($_REQUEST['mapByCode']) {
$map = new map($_REQUEST['mapByCode']);
echo json_encode($map);
exit;
}
if ($_REQUEST['mapByMap']) {
$jsonMap = json_decode($_REQUEST['mapByMap']);
$map = new map();
foreach ($jsonMap as $key => $value) {
$map->$key = $value;
}
//Store the code in the object
$code = $map->getOldCode();
$map->code = $code;
echo json_encode($map);
exit;
}
if ($_REQUEST['genMap']) {
//function GenerateMap($rows, $cols, $rockchance, $numBlocks = -1, $cp = -1, $tp = -1, $mapName = '') {
$map = GenerateMap($_REQUEST['width'], $_REQUEST['height'], $_REQUEST['rockChance'], $_REQUEST['wallCount'], $_REQUEST['checkpoints'] % 6, $_REQUEST['teleports'] % 6);
//$map = GenerateMap($_REQUEST['height'], $_REQUEST['width'], $_REQUEST['rockChance'], 0, 0, 0);
//$map = insertPoint($map, $_REQUEST['points'], 'o');
$code = GenerateMapCode($map);
$map = new map($code);
echo json_encode($map);
exit;
}
//Add's a new custom challenge map - returns mapid
function addNewChallengeMap($map, $tier, $subOrder, $name) {
$mapcode = GenerateMapCode($map);
$sql = "INSERT INTO `challengeMaps`
(`code`, `ChallengeTier`, `ChallengeSuborder`, `Name`)
VALUES
('$mapcode', $tier, $subOrder, '$name')";
echo $sql;
mysql_query($sql);
$mapID = mysql_insert_id();
return $mapID;
}
//Returns challenge ID
function addNewChallenge($mapID, $inequality, $goal, $ordering, $hint,
$restrictWallCount = 'null', $restrictWallPlacement = 'null', $restrictTeleportCount = 'null',
$restrictTeleportsUsed = 'null', $restrictStartPoint = 'null', $restrictEndPoint = 'null') {
$sql = "INSERT INTO `challenges` (
`mapID`, `inequality`, `goal`, `ordering`, `hint`,
`restrictWallCount`, `restrictWallPlacement`, `restrictTeleportCount`,
`restrictTeleportsUsed`, `restrictStartPoint`, `restrictEndPoint`
)
VALUES (
'$mapID', '$inequality', $goal, $ordering, '$hint',
'$restrictWallCount', '$restrictWallPlacement', '$restrictTeleportCount',
'$restrictTeleportsUsed', '$restrictStartPoint', '$restrictEndPoint'
)";
echo $sql;
mysql_query($sql);
$challengeID = mysql_insert_id();
return $challengeID;
}
// Start Page:
htmlHeader(array('stats', 'mapeditor'), 'Map Editor',
'Map Editor',
array('dateformat'));
?>
<?php
echo soundManager2();
topbar($headerLinks);
?>
<script>
var testMap = new Object;
testMap.ID = 0;
testMap.editMap = true;
testMap.width = 6;
testMap.height = 5;
testMap.tiles = constructTiles(6, 5);
testMap.name = 'Testmap';
testMap.walls = 5;
setTimeout("reloadMap();", 500);
setTimeout("start();", 500);
function start() {
//$('#testMapDisplay').html(mapAsHTML(testMap));
$(window).mousedown(function(){
mouseIsDown = true;
});
$(window).mouseup(function(){
mouseIsDown = false;
});
}
var mouseIsDown = false;
var mapHasChanged = false;
function mapEditOver(obj) {
if (mouseIsDown == true) mapEditClick(obj);
}
function mapEditClick(obj) {
console.log("Map Click");
tmp = obj.id.split(',');
mapid = tmp[0] - 0;
//hack hacky hack.
y = tmp[1] - 1;
x = tmp[2];
testMap.tiles[y][x] = Array(palleteType, palleteValue);
y++;
$(obj).attr('class', 'mapcell '+palleteType+palleteValue);
mapHasChanged = true;
}
getMapTimer();
function getMapTimer() {
setTimeout("getMapTimer()", 3000);
if (mapHasChanged) {
loadPlayableMap();
mapHasChanged = false;
}
}
var palleteType = 's';
var palleteValue = '';
function paletteSelect(type, value) {
palleteValue = value;
palleteType = type;
}
function plusWalls() {
testMap.walls = testMap.walls - 0 + 1;
reloadMap();
}
function minusWalls() {
testMap.walls = testMap.walls - 1;
reloadMap();
}
function plusWidth() {
changeDimensions(testMap.width - 0 + 1, testMap.height);
}
function minusWidth() {
changeDimensions(testMap.width - 1, testMap.height);
}
function plusHeight() {
changeDimensions(testMap.width, testMap.height - 0 + 1);
}
function minusHeight() {
changeDimensions(testMap.width, testMap.height - 1);
}
function updateName() {
testMap.name = $('#mapName').val();
mapHasChanged = true;
}
function changeDimensions(width, height) {
testMap.tiles = constructTiles(width, height, testMap);
//testMap.tiles[0][3] = Array('s');
//testMap.tiles[4][3] = Array('f');
testMap.width = width;
testMap.height = height;
console.log('rl');
reloadMap();
}
var playableMap;
function reloadMap() {
$('#testMapDisplay').html(mapAsHTML(testMap, 590, true));
//Duplicate object
var returnedMap = jQuery.extend(true, {}, testMap);
loadPlayableMap();
}
var isLoadingMap = false;
function loadPlayableMap() {
if (isLoadingMap == true) return;
isLoadingMap = true;
//var URLString = 'mapeditor?mapByMap='+JSON.stringify(testMap);
var URLString = 'mapeditor';
$.ajax({
type: "POST",
url: URLString,
cache: true,
data: 'mapByMap='+JSON.stringify(testMap),
fail: function() { alert("error"); },
complete: function(data) {
playableMap = decryptJSON(data.responseText);
playableMap.editMap = false;
playableMap.ID = -1;
$('#playableMapDisplay').html(mapAsHTML(playableMap, 960));
$('#playableMapCodeDisplay').val(playableMap.code);
isLoadingMap = false;
}
});
}
function loadMap(by) {
var URLString = '';
var mapID = 0;
if (by == 'ID') {
mapID = $('#mapID').val();
URLString = 'a/map/'+mapID+'.js';
} else if (by == 'code') {
mapCode = $('#mapCode').val();
URLString = 'mapeditor?mapByCode='+mapCode;
} else if (by == 'gen') {
mapCode = $('#mapCode').val();
URLString = 'mapeditor?genMap=true'+mapCode;
var height = $('#genMapHeight').val();
var width = $('#genMapWidth').val();
var rockChance = $('#genMapRockChance').val();
var checkpoints = $('#genMapCheckpoints').val();
var teleports = $('#genMapTeleports').val();
URLString += '&height='+height;
URLString += '&width='+width;
URLString += '&wallCount='+testMap.walls;
URLString += '&rockChance='+rockChance;
URLString += '&checkpoints='+checkpoints;
URLString += '&teleports='+teleports;
}
$.ajax({
type: "GET",
url: URLString,
cache: true,
data: '',
fail: function() { alert("error"); },
complete: function(data) {
var map = decryptJSON(data.responseText);
testMap = map;
testMap.ID = 0;
testMap.editMap = true;
reloadMap();
}
});
}
function constructTiles(width, height, baseMap) {
console.log('construct start');
var tiles = new Array;
for (var y = 0; y < height; y++) {
tiles[y] = new Array;
for (var x = 0; x < width; x++) {
tiles[y][x] = new Array;
if (typeof(baseMap) !== 'undefined' &&
typeof(baseMap.tiles[y]) !== 'undefined' &&
typeof(baseMap.tiles[y][x]) !== 'undefined'
) tiles[y][x] = baseMap.tiles[y][x];
else tiles[y][x][0] = 'o';
}
}
console.log('construct done');
return tiles;
}
</script>
<div class='wrapper'>
<h3>Map Editor Beta</h3>
<div class='wrapper'>
<form>
<fieldset>
<legend>Load Map:</legend>
<div class='plusMinus'>
Load map by ID:<input id='mapID' size="5" type="text" value="" class="forminput"/>
<input type="button" value="Load" class="forminput" onclick='loadMap("ID")'/>
</div>
<div class='plusMinus' style='width:300px;'>
Load map by code:<input id='mapCode' size="30" type="text" value="" class="forminput"/>
<input type="button" value="Load" class="forminput" onclick='loadMap("code")'/>
</div>
<div class='plusMinus' style='width:300px;'>
Generate a random map:
<br />Height:<input id='genMapHeight' size="4" type="number" value="" class="forminput"/>
<br />Width:<input id='genMapWidth' size="4" type="number" value="" class="forminput"/>
<br />Rockchance 1 in:<input id='genMapRockChance' size="4" type="number" value="" class="forminput"/>
<br />Checkpoints:<input id='genMapCheckpoints' size="4" type="number" value="" class="forminput"/> (Max 5)
<br />Teleports:<input id='genMapTeleports' size="4" type="number" value="" class="forminput"/> (Max 5)
<input type="button" value="Generate" class="forminput" onclick='loadMap("gen")'/>
</div>
</fieldset>
</form>
</div>
<form><div>
<div class='' id='' style='float:left; width:340px;height:450px;'>
<fieldset style='width:300px'>
<legend>Settings:</legend>
<div class='plusMinus' style='width:270px'>
Map Name:<input onchange='updateName()' id='mapName' style='width:260px;' size="10" type="text" value="" class="forminput"/>
</div>
<div class='plusMinus'>
Height:<input type="button" value="+" class="forminput" onclick='plusHeight()'/>
<input type="button" value="-" class="forminput" onclick='minusHeight()'/>
</div>
<div class='plusMinus'>
<span style='width:70px;'>Width:</span><input type="button" value="+" class="forminput" onclick='plusWidth()'/>
<input type="button" value="-" class="forminput" onclick='minusWidth()'/>
</div>
<div class='plusMinus'>
<span style='width:70px;'>Walls:</span><input type="button" value="+" class="forminput" onclick='plusWalls()'/>
<input type="button" value="-" class="forminput" onclick='minusWalls()'/>
</div>
<div style='clear:both'></div>
<?PHP
$tilesArray = array(
//: q?
's', 's2', 'f', 'p',
'space',
'x', 'x2',
'space',
'r', 'r2', 'r3', 'o',
'space',
'c', 'c2', 'c3', 'c4', 'c5',
'space',
't', 't2', 't3', 't4', 't5',
'space',
'u', 'u2', 'u3', 'u4', 'u5'
);
foreach($tilesArray as $key) {
if ($key == 'space') {
echo '<div style="clear:both"></div>';
continue;
}
echo "
<div class='tileDisplay map'>
<div class='$key' onclick=\"paletteSelect('$key[0]', '$key[1]')\"></div>
</div>";
}
?>
</fieldset>
</div>
<fieldset style='width:590px'>
<legend>Edit Map:</legend>
<div id='testMapDisplay' style='float:left;'>
Loading...
</div>
</fieldset>
</div></form>
<div style='clear:both;'></div>
<div class="divide"><strong>Playable Map</strong></div>
<div style='clear:both;'></div>
<div class='wrapper'>
MapCode: <input id='playableMapCodeDisplay' size="100" type="text" value="" class="forminput"/>
</div>
<div id='playableMapDisplay' style='float:left;'>
Returned map goes here.
</div>
<div style='clear:both;'></div>
</div>
<?php
htmlFooter();
?>
|