From 51d99728286212717003009dd5706bb74edcb272 Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Wed, 1 May 2013 01:54:08 -0700 Subject: Challengesss Challenges... DB Updates. Challenges --- ajax/challenges.ajax.php | 23 +++++++++---- db updates.sql | 4 +++ do.php | 44 ++++++++++++++++-------- includes/datas.php | 12 ++++++- pages/challengeeditor.php | 20 ++++++++--- 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 diff --git a/do.php b/do.php index 1e2760f..43da407 100644 --- a/do.php +++ b/do.php @@ -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);
Goal:
"inequality"
E.G. greater than, less than, equal:
hint +
dialogStart +
dialogFail +
dialogSuccess
Order:
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('
Grayed out Obscured Map Here.
').show(); - $("#mainDisplay").append('
Grayed out Obscured Map Here.
').show(); - $("#mainDisplay").append('
Grayed out Obscured Map Here.
').show(); - $("#mainDisplay").append('
Grayed out Obscured Map Here.
').show(); + //$("#mainDisplay").append('
Grayed out Obscured Map Here.
').show(); + //$("#mainDisplay").append('
Grayed out Obscured Map Here.
').show(); + viewDepth = 1; + $('#dialogBox').html("Choose a level"); } function formatChallengeThumbnail(map) { - var r = '
'; 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 = " Load this solution"; r += "
  • " r += getChallengeDisplayString(challenge) + loadSolutionString + "
  • "; @@ -227,20 +253,50 @@ function showNav() { } +function showChallengeTiers() { + $('#dialogBox').html("Choose a tier to play"); + var tmp = "
    "; + tmp += "

    Easy

    "; + tmp += "
    "; + tmp += "
    "; + tmp += "

    Normal

    "; + tmp += "
    "; + tmp += "
    "; + tmp += " Hard"; + tmp += "
    "; + + $('#mainDisplay').html(tmp); +} + +

    Challenges - I'z working on this stuff.

    - + +
    Greetings tester of test-needed things.
    -
    +

    Easy

    -
    - Normal +
    +

    Normal

    Hard -- cgit v1.2.3