Fix for both hand issue and normalization issue
This commit is contained in:
parent
9ba77c96fc
commit
c31eab7294
@ -109,6 +109,7 @@ sub addCards {
|
|||||||
|
|
||||||
sub addDeck {
|
sub addDeck {
|
||||||
my ($sessionID,$deckID) = @_;
|
my ($sessionID,$deckID) = @_;
|
||||||
|
if (defined($sessions{$sessionID}{"decks"}{$deckID})) { print "ERROR: Deck already exsists!\n"; return 0; }
|
||||||
$sessions{$sessionID}{"decks"}{$deckID} = { name => "$deckID", cards => [] };
|
$sessions{$sessionID}{"decks"}{$deckID} = { name => "$deckID", cards => [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +125,7 @@ sub uploadDDF {
|
|||||||
|
|
||||||
sub addPool {
|
sub addPool {
|
||||||
my ($sessionID,$poolID) = @_;
|
my ($sessionID,$poolID) = @_;
|
||||||
|
if (defined($sessions{$sessionID}{"pools"}{$poolID})) { print "ERROR: Pool already exsists!\n"; return 0; }
|
||||||
$sessions{$sessionID}{"pools"}{$poolID} = { name => "$poolID", cards => [] };
|
$sessions{$sessionID}{"pools"}{$poolID} = { name => "$poolID", cards => [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,6 +186,7 @@ sub renamePool {
|
|||||||
|
|
||||||
sub addHand {
|
sub addHand {
|
||||||
my ($sessionID, $userID, $handID) = @_;
|
my ($sessionID, $userID, $handID) = @_;
|
||||||
|
if (defined($sessions{$sessionID}{"users"}{$userID}{hands}{$handID})) { print "ERROR: Hand Already Exsists\n"; return 0; }
|
||||||
$sessions{$sessionID}{"users"}{$userID}{hands}{$handID} = { cards => [] };
|
$sessions{$sessionID}{"users"}{$userID}{hands}{$handID} = { cards => [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,6 +250,16 @@ sub getPoolTop {
|
|||||||
return @{$sessions{$sessionID}{"pools"}{$poolID}->{cards}}[0];
|
return @{$sessions{$sessionID}{"pools"}{$poolID}->{cards}}[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub normalizeSession {
|
||||||
|
my $sessionID = shift;
|
||||||
|
unless ($sessionID) { return print "ERROR: Session not provided\n"; }
|
||||||
|
unless (scalar getDecks($sessionID)) { addDeck($sessionID,"default"); }
|
||||||
|
unless (scalar getPools($sessionID)) { addPool($sessionID,"default"); }
|
||||||
|
for (getUsers($sessionID)) {
|
||||||
|
unless(scalar getHands($sessionID, $_)) { addHand($sessionID,$_,"default"); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
########################Game Logic ends here#############################
|
########################Game Logic ends here#############################
|
||||||
|
|
||||||
#########################Server Logic below##############################
|
#########################Server Logic below##############################
|
||||||
@ -304,7 +317,7 @@ my $server = Net::WebSocket::Server->new(
|
|||||||
}
|
}
|
||||||
if (defined($messageData->{action})) {
|
if (defined($messageData->{action})) {
|
||||||
if ($messageData->{action} =~ /join/ ) { if (joinSession($conn->{session},$conn->{user})) { $conn->send_utf8('{"info":"join success", "request":"update"}'); } }
|
if ($messageData->{action} =~ /join/ ) { if (joinSession($conn->{session},$conn->{user})) { $conn->send_utf8('{"info":"join success", "request":"update"}'); } }
|
||||||
if ($messageData->{action} =~ /update/ ) { my $sessionID = $conn->{session}; for ($conn->server->connections) { if ($_->{session} == $conn->{session}) {
|
if ($messageData->{action} =~ /update/ ) { my $sessionID = $conn->{session}; normalizeSession($conn->{session}); for ($conn->server->connections) { if ($_->{session} == $conn->{session}) {
|
||||||
#This might be a lot to do at once, might need to break it up in the future.
|
#This might be a lot to do at once, might need to break it up in the future.
|
||||||
# Update all connections joined to this session.
|
# Update all connections joined to this session.
|
||||||
# User List
|
# User List
|
||||||
@ -370,9 +383,9 @@ my $server = Net::WebSocket::Server->new(
|
|||||||
$conn->send_utf8('{"info":"pool cleared", "request":"update"}');
|
$conn->send_utf8('{"info":"pool cleared", "request":"update"}');
|
||||||
}
|
}
|
||||||
if ($messageData->{action} =~ /muligan/) {
|
if ($messageData->{action} =~ /muligan/) {
|
||||||
my @cards = delHand($conn->{session},$messageData->{hand});
|
my @cards = delHand($conn->{session},$conn->{user},$messageData->{hand});
|
||||||
addCards($conn->{session},$messageData->{deck},\@cards);
|
addCards($conn->{session},$messageData->{deck},\@cards);
|
||||||
addHand($conn->{session},$messageData->{hand});
|
addHand($conn->{session},$conn->{user},$messageData->{hand});
|
||||||
$conn->send_utf8('{"info":"hand returned to deck","request":"update"}');
|
$conn->send_utf8('{"info":"hand returned to deck","request":"update"}');
|
||||||
}
|
}
|
||||||
if ($messageData->{action} =~ /shuffle/) {
|
if ($messageData->{action} =~ /shuffle/) {
|
||||||
|
@ -78,15 +78,21 @@ function updateEvent() {
|
|||||||
myHands.forEach(function (handID) {
|
myHands.forEach(function (handID) {
|
||||||
var hand = window.gameState.hands[handID];
|
var hand = window.gameState.hands[handID];
|
||||||
window.UI.display[handID] = elementPlace("#hands","Hand_"+hand.name,"hand"+(hand.name == window.gameState.active.hand ? " selected" : ""),"li");
|
window.UI.display[handID] = elementPlace("#hands","Hand_"+hand.name,"hand"+(hand.name == window.gameState.active.hand ? " selected" : ""),"li");
|
||||||
window.UI.display[handID].controls = elementPlace("#Hand_"+hand.name,null,"controls","div");
|
window.UI.display[handID].controls = elementPlace("#Hand_"+hand.name,"Hand_controls_"+hand.name,"controls","div");
|
||||||
window.UI.display[handID].controls.innerHTML = "<div>"+hand.name+"</div>";
|
window.UI.display[handID].controls.innerHTML = "<div>"+hand.name+"</div>";
|
||||||
// Muligan Hand
|
buttonAdd("#Hand_controls_"+hand.name,null,"Muligan",function () {
|
||||||
// Delete Hand
|
window.gameSession.send('{"action":"muligan","hand":"'+handID+'","deck":"'+window.gameState.active.deck+'"}');
|
||||||
|
}, "hand_button muligan", "div");
|
||||||
|
buttonAdd("#Hand_controls_"+hand.name,null,"X",function () {
|
||||||
|
window.gameSession.send('{"action":"del","type":"hand","id":"'+handID+'"}');
|
||||||
|
}, "hand_button delete", "div");
|
||||||
window.UI.display[handID].cards = elementPlace("#Hand_"+hand.name,hand.name+"_cards",null,"ol");
|
window.UI.display[handID].cards = elementPlace("#Hand_"+hand.name,hand.name+"_cards",null,"ol");
|
||||||
hand.cards.forEach(function (card,index) {
|
hand.cards.forEach(function (card,index) {
|
||||||
window.UI.display[handID].cards[index] = elementPlace("#"+hand.name+"_cards",null,"card","li");
|
window.UI.display[handID].cards[index] = elementPlace("#"+hand.name+"_cards",null,"card","li");
|
||||||
window.UI.display[handID].cards[index].innerHTML = card;
|
window.UI.display[handID].cards[index].innerHTML = card+'<div id="card'+handID+index+'_controls"></div>';
|
||||||
// Play Card
|
buttonAdd("#card"+handID+index+"_controls",null,"Play Card", function () {
|
||||||
|
window.gameSession.send('{"action":"play","hand":"'+handID+'","cardID":"'+index+'","pool":"'+window.gameState.active.pool+'"}');
|
||||||
|
}, "card_button play", "div");
|
||||||
});
|
});
|
||||||
window.UI.display[handID].onclick = function () {
|
window.UI.display[handID].onclick = function () {
|
||||||
window.gameState.active.hand = hand.name;
|
window.gameState.active.hand = hand.name;
|
||||||
@ -106,7 +112,7 @@ function updateEvent() {
|
|||||||
myPools.forEach(function (poolID) {
|
myPools.forEach(function (poolID) {
|
||||||
var pool = window.gameState.pools[poolID];
|
var pool = window.gameState.pools[poolID];
|
||||||
window.UI.display[poolID] = elementPlace("#pools","Pool_"+pool.name,"pool"+(pool.name == window.gameState.active.pool ? " selected" : ""),"li");
|
window.UI.display[poolID] = elementPlace("#pools","Pool_"+pool.name,"pool"+(pool.name == window.gameState.active.pool ? " selected" : ""),"li");
|
||||||
window.UI.display[poolID].innerText = pool.name+":"+pool.top;
|
window.UI.display[poolID].innerHTML = pool.name+":"+pool.top;
|
||||||
// Delete Pool
|
// Delete Pool
|
||||||
window.UI.display[poolID].onclick = function () {
|
window.UI.display[poolID].onclick = function () {
|
||||||
window.gameState.active.pool = pool.name;
|
window.gameState.active.pool = pool.name;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user