diff --git a/src/Game.hs b/src/Game.hs index ff81076..a162be6 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -35,8 +35,8 @@ exportPlayers game = let (Player.Players players) = KoiKoi.players game in players -extractPrivateState :: PlayerID -> Game -> PrivateState -extractPrivateState playerID game = PrivateState { +privateState :: PlayerID -> Game -> PrivateState +privateState playerID game = PrivateState { opponentHand = getHand opponentID players , deck = KoiKoi.deck game } @@ -53,8 +53,8 @@ publicPlayer player = PublicPlayer { , yakus = Player.yakus player } -extractPublicState :: Game -> PublicState -extractPublicState game = PublicState { +publicState :: Game -> PublicState +publicState game = PublicState { mode = KoiKoi.mode game , scores = KoiKoi.scores game , month = KoiKoi.month game @@ -76,13 +76,13 @@ export playerID game = do return $ PublicGame { nonce = Saltine.encode n , playerHand = getHand playerID (KoiKoi.players game) - , privateState = secretbox encrypt n $ toJSON privateState - , publicState - , publicSignature = signDetached (secret sign) $ toJSON publicState + , private = secretbox encrypt n $ toJSON private + , public + , publicSignature = signDetached (secret sign) $ toJSON public } where - publicState = extractPublicState game - privateState = extractPrivateState playerID game + public = publicState game + private = privateState playerID game toJSON :: ToJSON a => a -> ByteString toJSON = toStrict . encode diff --git a/www/game.js b/www/game.js index dd31ddf..ba62750 100644 --- a/www/game.js +++ b/www/game.js @@ -53,7 +53,7 @@ function Game(modules) { } function handleGameMessage(o) { - if(o.game.publicState.turns == 0) { + if(o.state.public.turns == 0) { if(o.logs.length > 0) { // but still some logs, from the previous round return modules.async.sequence(applyDiff(o), setGame(o)); // so play the diff, then set the new round } else { @@ -66,13 +66,13 @@ function Game(modules) { function setGame(o) { return function(f) { - setStatus(o.game); - setCaptures(o.game); + setStatus(o.state); + setCaptures(o.state); [ - [sets.river, o.game.river, RiverCard], - [sets.you.hand, o.game.players[modules.session.getKey()].hand, HandCard] + [sets.river, o.state.public.river, RiverCard], + [sets.you.hand, o.state.playerHand, HandCard] ].forEach(function(args) {setCardSet.apply(null, args)}); - setTheirCards(o.game); + setTheirCards(o.state); handleStep(o)(f); }; } @@ -96,10 +96,10 @@ function Game(modules) { function handleTurnedCard(o, f) { if(status.step == "Turned") { - setTurned(o.game.step.contents); + setTurned(o.state.public.step.contents); } else { - if(status.step == "ToPlay" && o.game.playing == o.game.oyake) { - rest.className = ["card", "turn" + o.game.publicState.turns].join(' '); + if(status.step == "ToPlay" && o.state.public.playing == o.state.public.oyake) { + rest.className = ["card", "turn" + o.state.public.turns].join(' '); } if(deck.lastChild.id != "rest") { deck.removeChild(deck.lastChild); @@ -120,7 +120,7 @@ function Game(modules) { function theyScored(o, f) { modules.screen.dialog({ - text: modules.i18n.get('theyScored')(modules.room.name(o.game.playing)), + text: modules.i18n.get('theyScored')(modules.room.name(o.state.public.playing)), answers: [ {label: 'ok', action: f} ] @@ -129,10 +129,10 @@ function Game(modules) { function gameEnd(o, f) { var winner, maxScore; - for(var key in o.game.scores) { - if(maxScore == undefined || o.game.scores[key] > maxScore) { + for(var key in o.state.public.scores) { + if(maxScore == undefined || o.state.public.scores[key] > maxScore) { winner = key; - maxScore = o.game.scores[key]; + maxScore = o.state.public.scores[key]; } } modules.screen.dialog({ @@ -151,7 +151,7 @@ function Game(modules) { function applyDiff(o) { return modules.async.sequence.apply(null, o.logs.map(animate).concat( - modules.async.apply(setStatus, o.game), + modules.async.apply(setStatus, o.state), handleStep(o) ) ); @@ -246,35 +246,35 @@ function Game(modules) { function setStatus(game) { modules.dom.clear(status.dom); - status.step = game.step.tag; - if(game.month != status.month) { - status.month = game.month; + status.step = game.public.step.tag; + if(game.public.month != status.month) { + status.month = game.public.month; } status.dom.appendChild( modules.dom.make('li', {textContent: modules.i18n.get('monthFlower')(modules.i18n.get(status.month))}) ); var turn = null; - status.playing = modules.session.is(game.playing); + status.playing = modules.session.is(game.public.playing); if(status.playing) { sets.you.hand.dom.classList.toggle("yourTurn", status.step == "ToPlay"); turn = modules.i18n.get("yourTurn"); } else { sets.you.hand.dom.classList.remove("yourTurn"); - turn = modules.i18n.get('playing')(modules.room.name(game.playing)); + turn = modules.i18n.get('playing')(modules.room.name(game.public.playing)); } status.dom.appendChild(modules.dom.make('li', {textContent: turn})); } function setCaptures(game) { - for(var key in game.players) { + for(var key in game.public.players) { var elem = document.getElementById(modules.session.is(key) ? "you" : "them"); - elem.getElementsByClassName('score')[0].textContent = game.scores[key] + " pts"; + elem.getElementsByClassName('score')[0].textContent = game.public.scores[key] + " pts"; var byClass = {} Object.values(modules.hanafuda.Family).forEach(function(family) { byClass[family.class] = elem.getElementsByClassName(family.class)[0]; modules.dom.clear(byClass[family.class]); }); - game.players[key].meld.forEach(function(cardName) { + game.public.players[key].meld.forEach(function(cardName) { var card = new Card(cardName); byClass[card.value.family.class].appendChild(card.dom); }); @@ -294,7 +294,7 @@ function Game(modules) { function setTheirCards(game) { var turnsTheyPlayed = Math.floor( - (game.publicState.turns + (modules.session.is(game.oyake) ? 0 : 1)) / 2 + (game.public.turns + (modules.session.is(game.public.oyake) ? 0 : 1)) / 2 ); modules.dom.clear(sets.them.hand.dom); for(var i = 0; i < 8 - turnsTheyPlayed; i++) {