Remove inelegant handling of remaining cards count in client thanks to newly available count in 'deck' property of game states

This commit is contained in:
Sasha 2018-07-28 12:48:31 +02:00
parent 4e220fa1c0
commit b61dd53f91
1 changed files with 5 additions and 11 deletions

View File

@ -5,8 +5,7 @@ function Game(modules) {
dom: document.getElementById("status"),
playing: false,
step: null,
month: null,
played: 0
month: null
};
var sets = {
river: {
@ -30,12 +29,12 @@ function Game(modules) {
['river', o.game.river, RiverCard],
['yourHand', o.game.players[modules.session.getKey()].hand, HandCard]
].forEach(function(args) {setCardSet.apply(null, args)});
setTheirCards(o.game.oyake);
setTheirCards(o.game);
if(status.step == "Turned") {
setTurned(o.game.step.contents);
} else {
if(status.step == "ToPlay" && o.game.playing == o.game.oyake) {
rest.className = ["card", "count" + (24 - status.played)].join(' ');
rest.className = ["card", "count" + o.game.deck].join(' ');
}
if(deck.lastChild.id != "rest") {
deck.removeChild(deck.lastChild);
@ -67,11 +66,6 @@ function Game(modules) {
status.step = game.step.tag;
if(game.month != status.month) {
status.month = game.month;
status.played = 0;
} else {
if(status.step == "ToPlay") {
status.played++;
}
}
status.dom.appendChild(
modules.dom.make('li', {textContent: "This month's flower is the " + status.month})
@ -116,9 +110,9 @@ function Game(modules) {
});
}
function setTheirCards(oyake) {
function setTheirCards(game) {
var turnsTheyPlayed = Math.floor(
(status.played + (modules.session.is(oyake) ? 0 : 1)) / 2
(24 - game.deck + (modules.session.is(game.oyake) ? 0 : 1)) / 2
);
modules.dom.clear(sets.theirHand.dom);
for(var i = 0; i < 8 - turnsTheyPlayed; i++) {