diff options
author | BlueRaja <BlueRaja.admin@gmail.com> | 2013-03-07 03:00:04 -0600 |
---|---|---|
committer | BlueRaja <BlueRaja.admin@gmail.com> | 2013-03-07 03:00:04 -0600 |
commit | 534566ca37d8da800188b073652003671fc9671a (patch) | |
tree | cd14d9353d19a365a80b519a21feeefe9152efcd | |
parent | ef912adeeac6be3d623d602ce17f69b15ce65aa8 (diff) | |
parent | ee270d30697914e322dd1256e2e3e0b60df0ced5 (diff) | |
download | pathery-534566ca37d8da800188b073652003671fc9671a.tar.xz |
Merge branch 'master' of git.raylu.net:pathery
Conflicts:
includes/db.inc.php
-rw-r--r-- | css/chat.css | 8 | ||||
-rw-r--r-- | css/mapeditor.css | 10 | ||||
-rw-r--r-- | css/maps.css | 7 | ||||
-rw-r--r-- | images/linkdsp.png | bin | 0 -> 38111 bytes | |||
-rw-r--r-- | includes/header.php | 1 | ||||
-rw-r--r-- | includes/mapclass.php | 82 | ||||
-rw-r--r-- | index.php | 15 | ||||
-rw-r--r-- | js/mapspecs.js | 14 | ||||
-rw-r--r-- | pages/chat.php | 37 | ||||
-rw-r--r-- | pages/home.php | 2 | ||||
-rw-r--r-- | pages/mapeditor.php | 284 | ||||
-rw-r--r-- | pages/share.php | 20 | ||||
-rw-r--r-- | redirect.php | 83 |
13 files changed, 540 insertions, 23 deletions
diff --git a/css/chat.css b/css/chat.css index 9608093..66cd086 100644 --- a/css/chat.css +++ b/css/chat.css @@ -3,7 +3,7 @@ font-family: 'Trebuchet MS1', 'Trebuchet MS', sans-serif; border: 1px solid gray; background-color:#999; - width: 700px; + width: 680px; margin: 7px; padding: 2px; border-radius: 10px; @@ -11,7 +11,11 @@ border-top-right-radius: 20px; } .chatButton { - margin: 4px; + margin: 0px; +} +.chatMute { + margin: 0px; + width: 15px; } #chatContainer { diff --git a/css/mapeditor.css b/css/mapeditor.css new file mode 100644 index 0000000..60a6e78 --- /dev/null +++ b/css/mapeditor.css @@ -0,0 +1,10 @@ + + + +.plusMinus { + float:left; + width:130px; + border:1px solid gray; + padding:2px; + margin:2px; +}
\ No newline at end of file diff --git a/css/maps.css b/css/maps.css index 604192c..86a2f76 100644 --- a/css/maps.css +++ b/css/maps.css @@ -188,6 +188,13 @@ background-image: url(../images/OverlayTileFaceted20.png);
}
+.tileDisplay div {
+ float:left;
+ border:1px solid blue;
+ margin:2px;
+ width:36px;
+ height:36px;
+}
/* grid stuff */
diff --git a/images/linkdsp.png b/images/linkdsp.png Binary files differnew file mode 100644 index 0000000..118ae0b --- /dev/null +++ b/images/linkdsp.png diff --git a/includes/header.php b/includes/header.php index 136c2eb..44d028e 100644 --- a/includes/header.php +++ b/includes/header.php @@ -10,6 +10,7 @@ function htmlHeader($css = array(), $title = 'Pathery', $desc = '', $scripts = a <link href="css/page.css?v=011013" rel="stylesheet" type="text/css" />
<link href="css/maps.css?v=122612" rel="stylesheet" type="text/css" />
+ <link rel="image_src" type="image/png" href="/images/linkdsp.png" />
<?php
foreach ($css as $c) {
echo " <link href=\"css/$c.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
diff --git a/includes/mapclass.php b/includes/mapclass.php index 9e91d3f..24b9108 100644 --- a/includes/mapclass.php +++ b/includes/mapclass.php @@ -43,8 +43,15 @@ class map { public function __construct($code = NULL, $mapID = NULL) { //TODO: Use new code by default. if ($mapID !== NULL) $this->ID = $mapID; - if ($code !== NULL) $this->applyMapFromOldCode($code); - //$this->applyMapFromCode($code); + if ($code !== NULL) { + $dimensions = explode('.', explode(':', $code)[0])[0]; + if (strpos($dimensions, 'x') == true) { + $this->applyMapFromOldCode($code); + } else { + $this->applyMapFromCode($code); + } + } + } public function applyMapFromOldCode($code) { @@ -218,8 +225,7 @@ class map { //Outputs the new code. public function getCode() { //If we already have the code on hand... - if ($this->code) - return $this->code; + //if ($this->code) return $this->code; //Otherwise we need to build the code: $headers[0] = $this->width; $headers[1] = $this->height; @@ -247,6 +253,74 @@ class map { return $code; } + function getOldCode() { + + $code = ""; //The string to return to the database. + $index = 0; //The current number of tiles from the last tile saved. + + $code = $this->width.'x'.$this->height; + $code .= '.c'.$this->checkpoints; + $code .= '.r0'; //rocks... yeah. + $code .= '.w'.$this->walls; + $code .= '.t'.$this->teleports; + $code .= '.'.$this->name; + $code .= ".:"; + + $oldNames['o'] = 'o'; + + $oldNames['s'] = 's'; + $oldNames['s2'] = 'S'; + $oldNames['f'] = 'f'; + + $oldNames['c'] = 'a'; + $oldNames['c2'] = 'b'; + $oldNames['c3'] = 'c'; + $oldNames['c4'] = 'd'; + $oldNames['c5'] = 'e'; + + $oldNames['t'] = 't'; + $oldNames['t2'] = 'm'; + $oldNames['t3'] = 'g'; + $oldNames['t4'] = 'i'; + $oldNames['t5'] = 'k'; + + $oldNames['u'] = 'u'; + $oldNames['u2'] = 'n'; + $oldNames['u3'] = 'h'; + $oldNames['u4'] = 'j'; + $oldNames['u5'] = 'l'; + + $oldNames['x'] = 'x'; + $oldNames['x2'] = 'X'; + + $oldNames['r'] = 'r'; + $oldNames['r2'] = 'R'; + + for( $i = 0; $i < $this->height; $i++) { + for( $j = 0; $j < $this->width; $j++) { + if($this->tiles[$i][$j][0] != 'o') { + //As long as the tile is NOT open, embed it in the code. + + + $type = $this->tiles[$i][$j][0]; + $value = $this->tiles[$i][$j][1]; + if ($value <= 1) $value = ''; + + $code .= $index.$oldNames[$type.$value].'.'; + + + //$code .= $index.$mapMatrix[$i][$j].'.'; + //Start from 0 again. + $index = -1; + } + $index += 1; + } + } + + return $code; + + } + //Other "Magical" functions. public function __toString() { return $this->name; @@ -99,8 +99,15 @@ switch ($request) { break;
case "redirect":
- $to = $_GET['to'];
- DoRedirect("<strong>THIS URL COULD BE UNSAFE! Please confirm!</strong><br/>", $to, $duration = "8");
+ //Whitelist things?
+ if (true) {
+ require('redirect.php');
+ } else {
+ //Redirect instantly:
+ $to = $_GET['to'];
+ DoRedirect(NULL, $to, $duration = "0");
+ }
+ exit;
break;
case "hometutorial":
@@ -212,6 +219,10 @@ switch ($request) { require 'pages/chat.php';
break;
+ case "mapeditor":
+ require 'pages/mapeditor.php';
+ break;
+
case "admin":
if ($_SESSION['isAdmin'] == true) {
require 'pages/admin.php';
diff --git a/js/mapspecs.js b/js/mapspecs.js index 2387a00..ecc5c9d 100644 --- a/js/mapspecs.js +++ b/js/mapspecs.js @@ -92,6 +92,12 @@ function grid_click(obj) { y = tmp[1];
x = tmp[2];
+
+ if(typeof(mapdata[mapid]) == 'Object' && mapdata[mapid].editMap == true) {
+ mapClick(obj);
+ return;
+ }
+
//The users solution - prepare it if it's not started
if (solution[mapid] == undefined) {
getmapdata(mapid);
@@ -838,7 +844,7 @@ var Tile = { "x" : "Single-Path-Rock"};
//Map as object. If target width is NULL or False, default width is used.
-function mapAsHTML(map, targetWidth, demo) {
+function mapAsHTML(map, targetWidth, mapEditor) {
map.mapid = map.ID;
//console.log("MapID:", map.mapid);
@@ -872,9 +878,9 @@ function mapAsHTML(map, targetWidth, demo) { // GOAL WOULD BE THIS LINE INSTEAD.. As it's not retarded.
//var idHandle = map.ID+','+x+','+y;
-
+
//oldy is used for Position too... for now
- if (type == 'o') {
+ if (type == 'o' || mapEditor == true) {
mapgrid += "<div style='float:left; width:"+tileWidth+"px; height:"+tileWidth+"px; ' class='mapcell "+type+value+"' title='Position: "+x+","+oldy+"' id='"+idHandle+"' onClick='grid_click(this)' >";
mapgrid += "<div id='child_"+idHandle+"' class='child'></div></div>";
} else {
@@ -885,6 +891,8 @@ function mapAsHTML(map, targetWidth, demo) { }
mapgrid += '</div>';
+ if (mapEditor == true) return mapgrid;
+
var r = '';
//TODO: Track down where that 1 pixel is comingfrom, width-1 is a hack.
diff --git a/pages/chat.php b/pages/chat.php index 27122d8..d2198c7 100644 --- a/pages/chat.php +++ b/pages/chat.php @@ -45,6 +45,9 @@ function getChatDone(data) { var p; //our prep string
var newChats = false;
+ var lastDisplay = '';
+ var lastMessage = '';
+
////console.log('datalength', data.length);
if (data.length < 3 || data == 'false')
@@ -118,6 +121,8 @@ function getChatDone(data) { items.push('<div class="chatMessage'+strClass+'" id="C_' + chat.ID + '">' + p + '</div>');
newChats = true;
}
+ lastDisplay = chat.displayName
+ lastMessage = chat.message
if (chat.ID > 0) lastID = chat.ID;
});
@@ -130,15 +135,18 @@ function getChatDone(data) { var atBottom = (elem.scrollTop() >= elem[0].scrollHeight - elem.outerHeight() - 1);
$("#chatContainer").append(items.join(''));
-
+
if (atBottom || firstGetChat) {
$("#chatContainer").scrollTop($("#chatContainer")[0].scrollHeight);
firstGetChat = false;
}
- soundManager.setVolume('charm', 20);
- soundManager.setPan('charm', -60)
- soundManager.setPosition('charm',150);
- soundManager.play('charm');
+ document.title = lastDisplay+': '+lastMessage.substring(0, 10)+'... Pathery Chat';
+ if (!document.getElementById('chatMute').checked) {
+ soundManager.setVolume('charm', 20);
+ soundManager.setPan('charm', -60)
+ soundManager.setPosition('charm',150);
+ soundManager.play('charm');
+ }
}
}
@@ -150,10 +158,13 @@ function chatReplaceAndEncode(chat) { //Surround all URLs with a <a> link
var URLexp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
- chat = chat.replace(URLexp, "<a href='redirect?to=$1' target='top'>$1</a>");
+ chat = chat.replace(URLexp, "<a href='redirect?to=$1' target='_blank'>$1</a>");
//Replace # in the URL with %23
- chat = chat.replace(/<a href='redirect\?to=(.*?)(#)(.*?)' target='top'>/ig, "<a href='redirect?to=$1%23$3' target='top'>");
+ chat = chat.replace(/<a href='redirect\?to=(.*?)(#)(.*?)' target='_blank'>/ig, "<a href='redirect?to=$1%23$3' target='_blank'>");
+ chat = chat.replace(/<a href='redirect\?to=(.*?)(&)(.*?)' target='_blank'>/ig, "<a href='redirect?to=$1%26$3' target='_blank'>");
+ //Making the bet that not all browsers do the same:
+ chat = chat.replace(/<a href='redirect\?to=(.*?)(&)(.*?)' target='_blank'>/ig, "<a href='redirect?to=$1%26$3' target='_blank'>");
return chat;
}
@@ -212,6 +223,10 @@ function htmlEncode(value){ }
}
+function setChatMute(value) {
+ savePref('chatMute', value);
+}
+
</script>
<div class='wrapper'>
@@ -223,6 +238,14 @@ function htmlEncode(value){ <form id='sendChat' onsubmit="return false">
<? if($accepted) { /*Only show the chat button if we're logged in*/ ?>
<input type="hidden" name="stuff" value="1724">
+
+ <?
+ $chatMute = '';
+ if (isset($_COOKIE['pref_chatMute']) && $_COOKIE['pref_chatMute'] == "true") $chatMute = "checked='checked' ";
+ echo "
+ <input title='Mute sound?' onClick='setChatMute(this.checked)' type='checkbox' id='chatMute' class='chatMute' $chatMute/>";
+ ?>
+
<input class='chatButton' type="button" class="send" id='chatSendBtn' value='Send' onClick="sendChat();">
<input class='chatInputMessage' type="text" name="message" id="message" value="" maxlength="255" autocomplete="off" >
<? } ?>
diff --git a/pages/home.php b/pages/home.php index 544b3fe..8c88d49 100644 --- a/pages/home.php +++ b/pages/home.php @@ -9,7 +9,7 @@ include_once ('./includes/constants.php'); htmlHeader(
array('stats'), 'Pathery',
- 'Compete to create the longest path possible. New maps every day!',
+ 'Path lengthening competition inspired by Tower Defense mazing concepts',
array('scores', 'dateformat')
);
diff --git a/pages/mapeditor.php b/pages/mapeditor.php new file mode 100644 index 0000000..87fef32 --- /dev/null +++ b/pages/mapeditor.php @@ -0,0 +1,284 @@ +<?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; +} + + +htmlHeader(array('stats', 'mapeditor'), 'Map Editor', + 'Map Editor', + array('dateformat')); + + +?> + +<body> +<?php +echo soundManager2(); +topbar($Links); + +?> +<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); +function start() { + $('#testMapDisplay').html(mapAsHTML(testMap)); +} + + +var grid_clickOverride = true; +function mapClick(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); + loadPlayableMap(); +} + +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 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(); +} + +function loadPlayableMap() { + + var URLString = 'mapeditor?mapByMap='+JSON.stringify(testMap); + $.ajax({ + type: "GET", + url: URLString, + cache: true, + data: '', + 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); + } + }); +} + +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; + } + $.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> + + </fieldset> + + </form> + </div> + + <form><div> + <div class='' id='' style='float:left; width:340px;height:350px;'> + + <fieldset style='width:300px'> + <legend>Settings:</legend> + <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( + 's', 's2', 'f', 'w', + 'space', + 'r', 'r2', 'o', 'q', 'x', 'x2', + '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"></div> + <div style='clear:both;'></div> + <div class='wrapper'> + <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(); +?>
\ No newline at end of file diff --git a/pages/share.php b/pages/share.php index 098c281..3c72c11 100644 --- a/pages/share.php +++ b/pages/share.php @@ -6,10 +6,12 @@ htmlHeader(array('stats')); <body>
<?php
+echo soundManager2();
topbar($Links);
include('./includes/maps.php');
+include('./includes/mapclass.php');
@@ -18,18 +20,28 @@ if (is_int($_GET['mapid'] + 0)) $mapcode = getMapCode($mapID);
//New code:
-if ($_GET['mapcode'])
- $mapcode = $_GET['mapcode'];
+if ($_GET['mapcode']) $mapcode = $_GET['mapcode'];
-$map = GenerateMapByCode($mapcode);
+//$map = GenerateMapByCode($mapcode);
+$map = new map($mapcode);
+$map->ID = 0;
+
+echo "<div class='wrapper'>";
+echo "<script>";
+echo "document.write(mapAsHTML(";
+echo json_encode($map);
+echo "))";
+echo "</script>";
+echo "</div>";
//echo DisplayMap($map, 1, 'example', 1);
-echo DisplayMap($map, 1);
+//echo DisplayMap($map, 1);
?>
+
<script>
loadSol('1:<? echo $_GET[solution]; ?>');
</script>
diff --git a/redirect.php b/redirect.php new file mode 100644 index 0000000..e010d94 --- /dev/null +++ b/redirect.php @@ -0,0 +1,83 @@ +<?
+$to = $_GET['to'];
+include('globe.php');
+?>
+<html>
+
+<head>
+<title>Pathery.com - Redirecting...</title>
+
+<meta http-equiv="refresh" content="6;URL=<? echo $to; ?>">
+
+<style>
+body {
+background-color: #121212;
+color:#ddd
+}
+
+.update {
+ background-color: #222229;
+ margin:0 auto;
+ margin-top: 200px;
+ width:400px;
+ border: 0px outset #aaa;
+ padding: 10px;
+ border-radius: 25px;
+}
+h3 {
+ text-align: center;
+}
+
+.buttons a {
+ margin: 10px;
+ opacity: 0.7;
+ filter: alpha(opacity=70);
+}
+.buttons a:hover {
+ opacity: 1;
+ filter: alpha(opacity=100);
+}
+
+a {
+ text-decoration: underline;
+ color: #aaaa99;
+}
+a:hover {
+ text-decoration: underline;
+ color: #FFFFFF;
+}
+</style>
+
+<script>
+
+var timeLeft = 5;
+var countdownRedirectInt = self.setInterval(countdownRedirect, 1000);
+
+function countdownRedirect() {
+ if (timeLeft <= 0) {
+ return;
+ }
+ timeLeft--;
+ var handle = document.getElementById("redirectTitle")
+ handle.innerHTML = 'You are being redirected in '+timeLeft+' seconds';
+
+ if (timeLeft <= 0) {
+ window.location = "<? echo $to; ?>";
+ }
+}
+// http://www.mazetd.4xg.net/redirect?to=http://www.mazetd.4xg.net/redirect?to=http://www.youtube.com/watch?v=FCSBoOcGFFE
+</script>
+
+</head>
+<body>
+
+<div class='update'>
+<h3 id='redirectTitle'>You are being redirected in 5 seconds</h3>
+<p>Let's go!: <a href='<? echo $to; ?>'><? echo $to; ?></a></p>
+
+<p>Back to: <a href='<? echo $mydomain; ?>' title='Go back'><? echo $mydomain; ?></a>
+</p>
+</div>
+
+</body>
+</html>
\ No newline at end of file |