Refactor code to change 'skip' to 'replace' referring to cards. Update logic for skipping cards to properly set played status.
This commit is contained in:
parent
9a09e2d87c
commit
4aeb30013a
|
|
@ -13,8 +13,8 @@ $second = false;
|
|||
if ( isset($_REQUEST["second"]) && ($_REQUEST["second"] == "true") ) $second = true;
|
||||
$initialcard = false;
|
||||
if ( isset($_REQUEST["initialcard"]) && ($_REQUEST["initialcard"] == "true") ) $initialcard = true;
|
||||
$skip = false;
|
||||
if ( isset($_REQUEST["skip"]) && ($_REQUEST["skip"] == "true") ) $skip = true;
|
||||
$replace = false;
|
||||
if ( isset($_REQUEST["replace"]) && ($_REQUEST["replace"] == "true") ) $replace = true;
|
||||
$reverse = false;
|
||||
if ( isset($_REQUEST["reverse"]) && ($_REQUEST["reverse"] == "true") ) $reverse = true;
|
||||
|
||||
|
|
@ -50,6 +50,30 @@ if ( $random_image === false ) {
|
|||
sendResponse();
|
||||
}
|
||||
|
||||
// If we are replacing a card set the previous card to unplayed,
|
||||
// set the replacement card to played, then immediately send the response
|
||||
if ( $replace ) {
|
||||
if ( $initialcard ) {
|
||||
$data["error"] = true;
|
||||
$data["message"] = "Replacement card requested when no card present";
|
||||
sendResponse();
|
||||
}
|
||||
$last_cardlist_index = array_key_last($_SESSION['cardlist']);
|
||||
$last_played_index = array_key_last($_SESSION['cardlist'][$last_cardlist_index]);
|
||||
$_SESSION['cardlist'][$last_cardlist_index][$last_played_index]->setPlayed(false);
|
||||
$_SESSION['cardlist'][$last_cardlist_index][$last_played_index]->save();
|
||||
$random_image->setPlayed(true);
|
||||
$random_image->save();
|
||||
$_SESSION['cardlist'][$last_cardlist_index][$last_played_index] = $random_image;
|
||||
$data['cards'] = $_SESSION['cardlist'][$last_cardlist_index];
|
||||
$data['cardcount'] = $_SESSION['cardcount'];
|
||||
sendResponse();
|
||||
}
|
||||
|
||||
// Always increment the card count unless it's the first card request
|
||||
if ( !$initialcard ) $_SESSION['cardcount']++;
|
||||
$data['cardcount'] = $_SESSION['cardcount'];
|
||||
|
||||
$new_cards = [];
|
||||
if ( $second ) {
|
||||
$new_cards[] = $previous_cards[0];
|
||||
|
|
@ -57,13 +81,8 @@ if ( $second ) {
|
|||
$new_cards[] = $random_image;
|
||||
$_SESSION['cardlist'][] = $new_cards;
|
||||
$data['cards'] = $new_cards;
|
||||
|
||||
if ( !$skip && !$initialcard ) $_SESSION['cardcount']++;
|
||||
if ( !$skip ) {
|
||||
$random_image->setPlayed(true);
|
||||
$random_image->save();
|
||||
}
|
||||
$data['cardcount'] = $_SESSION['cardcount'];
|
||||
|
||||
sendResponse();
|
||||
|
||||
|
|
|
|||
11
js/main.js
11
js/main.js
|
|
@ -1,6 +1,6 @@
|
|||
var resetting = false;
|
||||
var initialCard = true;
|
||||
var skipCard = false;
|
||||
var replaceCard = false;
|
||||
var showingSecondCard = false;
|
||||
const audioDice = new Audio("audio/dice.mp3");
|
||||
const PREVIOUS = true;
|
||||
|
|
@ -28,7 +28,8 @@ $(document).ready(function() {
|
|||
$("#mana_sun_img").on("click", function() { rollDice(); });
|
||||
$("#mana_water_img").on("click", function() { $(".diceroll").addClass("hidden"); });
|
||||
$("#mana_fire_img").on("click", function() {
|
||||
skipCard = true;
|
||||
if ( initialCard ) return;
|
||||
replaceCard = true;
|
||||
getCard();
|
||||
});
|
||||
$("#mana_tree_img").on("click", function() { window.open("manage.php", "_blank"); });
|
||||
|
|
@ -75,7 +76,7 @@ function resetPage(count = 0) {
|
|||
$(".diceroll").addClass("hidden");
|
||||
resetting = false;
|
||||
initialCard = true;
|
||||
skipCard = false;
|
||||
replaceCard = false;
|
||||
showingSecondCard = false;
|
||||
if ( !initialReset ) {
|
||||
showCardCount(data.cardcount);
|
||||
|
|
@ -138,12 +139,12 @@ function getCard(reverse = false) {
|
|||
data: {
|
||||
second: showingSecondCard,
|
||||
initialcard: initialCard,
|
||||
skip: skipCard,
|
||||
replace: replaceCard,
|
||||
reverse: reverse
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(data, stat, jqo) {
|
||||
skipCard = false;
|
||||
replaceCard = false;
|
||||
if ( data.error ) {
|
||||
$("#firstimg").attr("src", "");
|
||||
$("#secondimg").attr("src", "");
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user