diff options
-rw-r--r-- | ajax/challenges.ajax.php | 23 | ||||
-rw-r--r-- | db updates.sql | 4 | ||||
-rw-r--r-- | do.php | 44 | ||||
-rw-r--r-- | includes/datas.php | 12 | ||||
-rw-r--r-- | pages/challengeeditor.php | 20 | ||||
-rw-r--r-- | pages/challengelist.php | 88 |
6 files changed, 148 insertions, 43 deletions
diff --git a/ajax/challenges.ajax.php b/ajax/challenges.ajax.php index f27f3bb..cac9e75 100644 --- a/ajax/challenges.ajax.php +++ b/ajax/challenges.ajax.php @@ -6,7 +6,7 @@ include('../includes/maps.php'); include_once('../includes/sqlEmbedded.php');
if ($_GET['getChallengeIDs'] == 'true') {
- echo getChallengesByTier($_GET['userID']);
+ echo getChallengesByTier($_GET['tier'], $_GET['userID']);
exit;
}
@@ -50,10 +50,11 @@ function getChallengeCode($challengeID) { -function getChallengesByTier($userIdUnsanitized) {
+function getChallengesByTier($tierUnsanitized, $userIdUnsanitized) {
include_once('../includes/sqlEmbedded.php');
$userID = mysql_escape_string($userIdUnsanitized);
+ $tier = mysql_escape_string($tierUnsanitized);
$sql = "SELECT challengeMaps.ID AS challengeMapID, challengeMaps.challengeTier, challengeMaps.name AS name,
challengeSolutions.dateSolved, challengeSolutions.challengeID AS challengeID,
@@ -62,12 +63,17 @@ function getChallengesByTier($userIdUnsanitized) { INNER JOIN challengeMaps ON challenges.mapID = challengeMaps.ID
LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID AND challengeSolutions.userID = '$userID'
WHERE challenges.enabled = 1
- AND challengeMaps.challengeTier <= (SELECT challengeTier FROM users WHERE ID = '$userID' LIMIT 1) OR 1
+ AND challengeMaps.challengeTier = '$tier'
ORDER BY challengeMaps.challengeTier, challengeMaps.challengeSuborder, challenges.ordering";
+ //AND challengeMaps.challengeTier <= (SELECT challengeTier FROM users WHERE ID = '$userID' LIMIT 1) OR 1
+
$result = mysql_query($sql) OR die(mysql_error()."SQL: $sql");
if (mysql_num_rows($result) >= 1) {
- while($data = mysql_fetch_array($result)) {
+ $i = 0;
+ //$layer['x'] = '';
+ while($data = mysql_fetch_assoc($result)) {
+ $i++;
//echo $data['challengeMapID'];
$tier = $data['challengeTier'];
$challengeSuborder = $data['challengeSuborder'];
@@ -79,8 +85,10 @@ function getChallengesByTier($userIdUnsanitized) { $mapObj = new map($data['mapCode']);
$mapObj->ID = $challengeMapID;
- $layer[$data['challengeMapID']][$challengeID] = $data;
- $layer[$data['challengeMapID']]['mapObject'] = $mapObj;
+ $layer['CM'.$data['challengeMapID']][$challengeID] = $data;
+ $layer['CM'.$data['challengeMapID']]['mapObject'] = $mapObj;
+ $challenges = getChallenges($data['challengeMapID'], $userID);
+ $layer['CM'.$data['challengeMapID']]['challenges'] = $challenges;
//$layer[] = $data;
}
return json_encode($layer);
@@ -112,7 +120,8 @@ function loadChallengesForMap($mapIdUnsanitized, $userIdUnsanitized) SELECT challenges.ID AS challengeID, challenges.inequality, challenges.goal, challenges.hint,
challenges.restrictWallCount, challenges.restrictWallPlacement, challenges.restrictTeleportCount,
challenges.restrictTeleportsUsed, challenges.restrictStartPoint, challenges.restrictEndPoint,
- challengeSolutions.dateSolved
+ challengeSolutions.dateSolved,
+ challenges.dialogStart, challenges.dialogFail, challenges.dialogSuccess
FROM challenges
LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID AND challengeSolutions.userID = '$userID'
WHERE challenges.mapID = '$mapID' AND challenges.enabled = 1
diff --git a/db updates.sql b/db updates.sql index c6f6aa9..d248ef2 100644 --- a/db updates.sql +++ b/db updates.sql @@ -1,2 +1,6 @@ -- db updates reset after patch on March 24th. +--Dialog to challenges: +ALTER TABLE `challenges` ADD `dialogStart` VARCHAR( 200 ) DEFAULT NULL , +ADD `dialogFail` VARCHAR( 200 ) DEFAULT NULL , +ADD `dialogSuccess` VARCHAR( 200 ) DEFAULT NULL ;
\ No newline at end of file @@ -129,23 +129,32 @@ if ($_GET['r'] == 'getpath') { $mapID = $_GET[mapid] + 0;
if (!is_int($mapID)) return;
//$firephp->log($mapID, "mapID");
+
+ //Is a challenge?
+ $challenge = ($_GET['isChallenge'] == 'true');
+
+
- //TODO: Get rid of this hackyness:
- //the first 10 ID's reserved for challenges & tutorial.
- if ($mapID > 10)
+ if ($challenge) {
+ $mapcode = getChallengeMapCode($mapID);
+ } else {
$mapcode = getMapCode($mapID);
- else
- $mapcode = $_GET['mapcode'];
-
+ }
+ //Hack - trust any map with an ID below 10.
+ if ($mapID < 10) $mapcode = $_GET['mapcode'];
+
//mygrid will be the map, with the solution applied.
$map = GenerateMapByCode($mapcode);
$mygrid = MergeMapSolution($map, $solution);
//Check both starting point groups for paths
$json = routeMultiPath($mygrid);
-
$moves = $json['totalMoves'];
+
+ //Return some basic info:
$json['mapid'] = $mapID;
+ $json['isAChallenge'] = $challenge;
+ $json['mapcodeExecuted'] = $mapcode;
//What could go wrong?
if ($json['blocked']) {
@@ -165,12 +174,16 @@ if ($_GET['r'] == 'getpath') { die($encoded);
}
- if ($_GET['isChallenge'] == 'true' AND isChallengeMap($mapID)) {
- // $firephp->log('Calling challenges');
- $json['info'][] = 'Executed as a challenge';
- $json['completedChallenges'] = getCompletedChallenges($userID, $mapID, $solution, $moves, $json['path']);
- // $firephp->log('Challenges called!');
- die(json_encode($json));
+
+ if ($_GET['isChallenge'] == 'true') {
+ if (isChallengeMap($mapID)) {
+ // $firephp->log('Calling challenges');
+ $json['info'][] = 'Executed as a challenge';
+ $json['completedChallenges'] = getCompletedChallenges($userID, $mapID, $solution, $moves, $json['path']);
+ // $firephp->log('Challenges called!');
+ die(json_encode($json));
+ }
+ exit;
}
//Get current score data. - to see if a pertinent score was beat.
@@ -235,9 +248,10 @@ if ($_GET['r'] == 'getpath') { // return;
//} //x
+ //TODO: Delete the below?
//TODO: I changed this; note these changes before re-applying the above.
//Challenge/Tutorial?
- if ($mapID <= 10 AND $_GET['isChallenge'] = 'true') {
+/* if ($mapID <= 10 AND $_GET['isChallenge'] = 'true') {
$json['error'][] = 'executed as a challenge';
//This will allow me to give insentive to logging in.
@@ -257,7 +271,7 @@ if ($_GET['r'] == 'getpath') { getCompletedChallenges($userID, $mapID, $solution, $moves, $paths);
//die(json_encode($json));
}
-
+ */
// --------- USER NOT LOGGED IN?
if ($_SESSION['accepted'] !== 1) {
diff --git a/includes/datas.php b/includes/datas.php index 934c1d7..2e48b14 100644 --- a/includes/datas.php +++ b/includes/datas.php @@ -463,6 +463,16 @@ function isChallengeMap($mapID) { $result = mysql_query($sql) or die(mysql_error()); return (mysql_num_rows($result) != 0); } +function getChallengeMapCode($mapID) { + $sql = "SELECT `code` + FROM `challengeMaps` + WHERE + ID = '$mapID'; + "; + $result = mysql_query($sql); + $row = mysql_fetch_row($result); + return $row[0]; +} function getUserChallengeTier($userID) { @@ -1015,7 +1025,7 @@ function loadChallengeListing($userIdUnsanitized) INNER JOIN challengeMaps ON challenges.mapID = challengeMaps.ID LEFT JOIN challengeSolutions ON challenges.ID = challengeSolutions.challengeID AND challengeSolutions.userID = '$userID' WHERE challenges.enabled = 1 - AND challengeMaps.challengeTier <= (SELECT challengeTier FROM users WHERE ID = '$userID' LIMIT 1) + AND challengeMaps.challengeTier <= (SELECT challengeTier FROM users WHERE ID = '$userID' LIMIT 1) OR 1 ORDER BY challengeMaps.challengeTier, challengeMaps.challengeSuborder, challenges.ordering"; $result = mysql_query($sql) OR die(mysql_error()."SQL: $sql"); diff --git a/pages/challengeeditor.php b/pages/challengeeditor.php index 33a9511..9b1371f 100644 --- a/pages/challengeeditor.php +++ b/pages/challengeeditor.php @@ -55,15 +55,15 @@ function addNewChallengeMap($mapCode, $tier, $subOrder, $name) { } //Returns challenge ID -function addNewChallenge($mapID, $inequality, $goal, $ordering, $hint, +function addNewChallenge($mapID, $inequality, $goal, $ordering, $hint, $dialogStart, $dialogFail, $dialogSuccess, $restrictWallCount = 'null', $restrictWallPlacement = 'null', $restrictTeleportCount = 'null', $restrictTeleportsUsed = 'null', $restrictStartPoint = 'null', $restrictEndPoint = 'null') { $sql = "INSERT INTO `challenges` ( - `mapID`, `inequality`, `goal`, `ordering`, `hint` + `mapID`, `inequality`, `goal`, `ordering`, `hint`, `dialogStart`, `dialogFail`, `dialogSuccess` ) VALUES ( - '$mapID', '$inequality', $goal, $ordering, '$hint' + '$mapID', '$inequality', $goal, $ordering, '$hint', '$dialogStart', '$dialogFail', '$dialogSuccess' )"; // `restrictWallCount`, `restrictWallPlacement`, `restrictTeleportCount`, @@ -96,7 +96,16 @@ if (isset($_POST['challengeMapID'])) { $goal = $_POST['goal']; $ordering = $_POST['ordering']; $hint = $_POST['hint']; - $challengeID = addNewChallenge($mapID, $inequality, $goal, $ordering, $hint); + + $dialogStart = $_POST['dialogStart']; + $dialogFail = $_POST['dialogFail']; + $dialogSuccess = $_POST['dialogSuccess']; + + $challengeID = addNewChallenge( + $mapID, $inequality, $goal, + $ordering, $hint, $dialogStart, + $dialogFail, $dialogSuccess + ); $infoDisplayText = "Challenge Added!: $challengeID"; } @@ -153,6 +162,9 @@ topbar($Links); <br />Goal:<input name='goal' size="5" type="number" value="" class="forminput"/> <br /><b>"inequality" </b><br />E.G. greater than, less than, equal: <input name='inequality' size="15" type="text" value="" class="forminput"/> <br />hint <input name='hint' size="15" type="hint" value="" class="forminput"/> + <br />dialogStart <input name='dialogStart' size="20" type="hint" value="" class="forminput"/> + <br />dialogFail <input name='dialogFail' size="20" type="hint" value="" class="forminput"/> + <br />dialogSuccess <input name='dialogSuccess' size="20" type="hint" value="" class="forminput"/> <br />Order:<input name='ordering' size="5" type="text" value="" class="forminput"/> <br /><input type="submit" value="Add Challenge" class="forminput"/> </div> diff --git a/pages/challengelist.php b/pages/challengelist.php index d460ef5..db5608e 100644 --- a/pages/challengelist.php +++ b/pages/challengelist.php @@ -33,8 +33,10 @@ function challengeGo() {} //Temporary hack.. isChallenge = true; -function navShowChallengeTiers() { +var viewTier; +var viewDepth; +function navShowChallengeTiers() { } function navShowLevels(tier) { @@ -45,6 +47,7 @@ function navShowLevels(tier) { var urlString = 'ajax/challenges.ajax.php?getChallengeIDs=true'; urlString += "&userID="+userObj.ID; + urlString += "&tier="+tier; $.ajax({ type: "GET", url: urlString, @@ -52,25 +55,34 @@ function navShowLevels(tier) { data: '', fail: function() { alert("ajax error - if this persists check your connection."); }, complete: function(data) {showLevelsResponse(data.responseText);} - }); + }); + viewTier = tier; } function showLevelsResponse(response) { var json = decryptJSON(response); + var speedDelay = 100; $.each(json, function(key, challengeObj) { - console.log("tests", key, challengeObj); + console.log("tests", speedDelay, key, challengeObj); //$("#thumb_"+mapID).html(formatMapThumbForNav(data.responseText)).show(); - $("#mainDisplay").append(formatChallengeThumbnail(challengeObj.mapObject)).show(); - mapdata[key] = challengeObj.mapObject; + + //var randomSpeed = 500 + Math.floor((Math.random()*300)+1); + //var speedDelay = 100 + (parseInt(challengeObj.mapObject.ID) * 100); + speedDelay = speedDelay + 200; + + $("#mainDisplay").append(formatChallengeThumbnail(challengeObj.mapObject)); + $('#challengeMapThumb_'+challengeObj.mapObject.ID).hide().fadeIn(speedDelay); + + mapdata[challengeObj.mapObject.ID] = challengeObj.mapObject; }); - $("#mainDisplay").append('<div style="float:left; margin:8px; width:200px; height:180px;" class="mapThumbnail">Grayed out Obscured Map Here.</div>').show(); - $("#mainDisplay").append('<div style="float:left; margin:8px; width:200px; height:180px;" class="mapThumbnail">Grayed out Obscured Map Here.</div>').show(); - $("#mainDisplay").append('<div style="float:left; margin:8px; width:200px; height:180px;" class="mapThumbnail">Grayed out Obscured Map Here.</div>').show(); - $("#mainDisplay").append('<div style="float:left; margin:8px; width:200px; height:180px;" class="mapThumbnail">Grayed out Obscured Map Here.</div>').show(); + //$("#mainDisplay").append('<div style="float:left; margin:8px; width:200px; height:180px;" class="mapThumbnail">Grayed out Obscured Map Here.</div>').show(); + //$("#mainDisplay").append('<div style="float:left; margin:8px; width:200px; height:180px;" class="mapThumbnail">Grayed out Obscured Map Here.</div>').show(); + viewDepth = 1; + $('#dialogBox').html("Choose a level"); } function formatChallengeThumbnail(map) { - var r = '<div onclick="displayChallengeMap('+map.ID+')"'; + var r = '<div id="challengeMapThumb_'+map.ID+'" onclick="displayChallengeMap('+map.ID+')"'; r+= 'style="float:left; margin:8px;width:200px;height:180px;" class="mapThumbnail">'; r+= mapThumbnailHTML(map,200, 160)+'</div>'; return r; @@ -94,6 +106,7 @@ function displayChallengeMap(challengeMapID) { }); $("#mainDisplay").append(challengeNextBtn(challengeMapID)); $("#mainDisplay").append(challengePrevBtn(challengeMapID)); + viewDepth = 2; } function challengeNextBtn(challengeMapID) { @@ -106,6 +119,11 @@ function challengePrevBtn(challengeMapID) { } +function back() { + if (viewDepth == 2) navShowLevels(viewTier); + if (viewDepth == 1) showChallengeTiers(); +} + function challengesHTML(response, challengeMapID) { var json = decryptJSON(response); @@ -118,8 +136,16 @@ function challengesHTML(response, challengeMapID) { var cssClass; $.each(json, function(key, challenge) { console.log('d', key, challenge); - if (challenge.dateSolved) cssClass = 'challenge_complete'; - else cssClass = 'challenge_incomplete'; + if (challenge.dateSolved) { + cssClass = 'challenge_complete'; + } else { + cssClass = 'challenge_incomplete'; + } + //TODO: for first incomplete challenge + //if (challenge.dialogStart) { + $('#dialogBox').html(challenge.dialogStart); + //} + var loadSolutionString = " <a href='javascript:requestChallengeSolution(\""+challengeMapID+"\", \""+challenge.challengeID+"\");'> Load this solution</a>"; r += "<li class='"+cssClass+"' id='challenge_id_"+challenge.challengeID+"'>" r += getChallengeDisplayString(challenge) + loadSolutionString + "</li>"; @@ -227,20 +253,50 @@ function showNav() { } +function showChallengeTiers() { + $('#dialogBox').html("Choose a tier to play"); + var tmp = " <div onclick='navShowLevels(0);' style='float:left; margin:20px; border:20px solid white;padding:40px'>"; + tmp += " <h2>Easy</h2>"; + tmp += "</div>"; + tmp += "<div onclick='navShowLevels(1);' style='float:left; margin:20px; border:20px solid white;padding:40px'>"; + tmp += " <h2>Normal</h2>"; + tmp += "</div>"; + tmp += "<div style='float:left; margin:10px; border:10px solid gray;padding:20px'>"; + tmp += " Hard"; + tmp += "</div>"; + + $('#mainDisplay').html(tmp); +} </script> +<style> + +#dialogBox { + width:96%; + height:22px; + background-color:gray; + color:orange; + border-radius:10px; + padding:4px; + font-size:13pt; + margin-bottom:10px; +} + +</style> + <div id="challengelist_wrapper" class="wrapper" style='overflow: auto;'> <h3>Challenges - I'z working on this stuff.</h3> -<div id='backBtn'><a href='' class='next'>Back Btn</a></div> +<div id='backBtn' style='float:left;'><a href='javascript:back();' class='next'>Back</a></div> +<div id='dialogBox'>Greetings tester of test-needed things.</div> <div id='mainDisplay' style='width:99%;overflow: hidden;'> - <div onclick='navShowLevels(1);' style='float:left; margin:20px; border:20px solid white;padding:40px'> + <div onclick='navShowLevels(0);' style='float:left; margin:20px; border:20px solid white;padding:40px'> <h2>Easy</h2> </div> - <div style='float:left; margin:10px; border:10px solid gray;padding:20px'> - Normal + <div onclick='navShowLevels(1);' style='float:left; margin:20px; border:20px solid white;padding:40px'> + <h2>Normal</h2> </div> <div style='float:left; margin:10px; border:10px solid gray;padding:20px'> Hard |