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

View file

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