Closed Spooky-0 closed 4 years ago
Hi!
Your moves which rely on the secret state can be changed to the following format (see here):
moves: {
moveThatUsesSecret: {
move: (G, ctx) => {
...
},
client: false,
}
}
This tells boardgame.io to process these moves only on the server.
I tried this - or at least I thinki I did. I didn't quite undestand the documentation. I might have gotten something else wrong tho. But if that is indeed the way to do it, i will look more into this.
THanks.
What you did here looks like it should work!
Perhaps there still is an issue with the playerView
? Could you try the following?
playerView: (G, ctx, playerID) => {
let playerG = {...G}
for (var i = 0; i < G.deck.length; i++) {
playerG.deck[i] = null
}
// Hide your own cards
var id = parseInt(playerID)
if (!(isNaN(id))) { // However, if this is not a multiplayer then this is NaN. For testing only, as this game can only be played Multiplayer.
console.log("Hiding for player", id)
var len = playerG.hands[id].length
for (var i = 0; i < len; i++) {
playerG.hands[id].cards = null
}
}
return playerG
},
I got it to work by doing the magical Immer trick:
playerView: (G, ctx, playerID) => {
// Hide your own cards
var id = parseInt(playerID)
if (isNaN(id)) { // However, if this is not a multiplayer then this is NaN.
// // For testing only, as this game can only be played Multiplayer.
console.log(playerID)
return G
}
return {
...G,
deck: G.deck.map((value, index) => { return null}),
hands: G.hands.map((hand: IHand, index: number) => {
if (index !== id) {
return hand
}
return <IHand> {
cards: hand.cards.map((card: ICard, index_card: number) => {return null}),
hints: hand.hints,
player: hand.player
}
})
}
dont ask me why this works :)
Untill now, I have only worked locally. There are only two fields in G which should be hidden to the player. It is the deck, and your own hand. This is the interface of G
and I want
G.deck and G.hands[myId].cards to be hidden.
is how I tried.. but when playing a move which relies on secret state I get