summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--css/chat.css8
-rw-r--r--css/mapeditor.css10
-rw-r--r--css/maps.css7
-rw-r--r--images/linkdsp.pngbin0 -> 38111 bytes
-rw-r--r--includes/db.inc.php7
-rw-r--r--includes/header.php1
-rw-r--r--includes/mapclass.php14
-rw-r--r--index.php4
-rw-r--r--js/mapspecs.js14
-rw-r--r--pages/chat.php34
-rw-r--r--pages/home.php2
-rw-r--r--pages/mapeditor.php283
12 files changed, 361 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
new file mode 100644
index 0000000..118ae0b
--- /dev/null
+++ b/images/linkdsp.png
Binary files differ
diff --git a/includes/db.inc.php b/includes/db.inc.php
index 6cd3f01..e1db0ee 100644
--- a/includes/db.inc.php
+++ b/includes/db.inc.php
@@ -1,11 +1,6 @@
<?php
-
-global $mysqlid;
$db_host = "db2894.perfora.net";
$db_user = "dbo362854667";
$db_name = "db362854667";
$db_pass = "mazes4me";
-$mysqlid = @mysql_connect($db_host,$db_user, $db_pass) or die("Cannot connect to database.");
-@mysql_select_db($db_name, $mysqlid) or die("Invalid database.");
-
-?>
+?> \ No newline at end of file
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..bc5a6e5 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;
diff --git a/index.php b/index.php
index 9a5f7d7..f909306 100644
--- a/index.php
+++ b/index.php
@@ -212,6 +212,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..443ddfe 100644
--- a/js/mapspecs.js
+++ b/js/mapspecs.js
@@ -92,6 +92,12 @@ function grid_click(obj) {
y = tmp[1];
x = tmp[2];
+
+ if(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..f2d2231 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,10 @@ 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'>");
return chat;
}
@@ -212,6 +220,10 @@ function htmlEncode(value){
}
}
+function setChatMute(value) {
+ savePref('chatMute', value);
+}
+
</script>
<div class='wrapper'>
@@ -223,6 +235,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..402f2d6
--- /dev/null
+++ b/pages/mapeditor.php
@@ -0,0 +1,283 @@
+<?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
+ $map->getCode();
+ 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