asd
This commit is contained in:
parent
e2c4d4cb83
commit
ef045f9353
4 changed files with 76 additions and 108 deletions
|
|
@ -86,14 +86,16 @@ function onChoice(choice, state) {
|
|||
|
||||
// GameScriptState is the rich context object passed into every JS function call.
|
||||
type GameScriptState struct {
|
||||
ActiveSuit Suit
|
||||
PenaltyCards int
|
||||
SkipNext bool
|
||||
ChosenSuit Suit
|
||||
Hand []Card // acting player's full hand (including cards being played)
|
||||
PlayerCount int
|
||||
HandCounts []int // cards held by each player, in seat order
|
||||
Direction int // 1 = clockwise, -1 = counter-clockwise
|
||||
ActiveSuit Suit
|
||||
PenaltyCards int
|
||||
SkipNext bool
|
||||
ChosenSuit Suit
|
||||
Hand []Card // acting player's full hand (including cards being played)
|
||||
PlayerHands [][]Card
|
||||
CurrentPlayerIndex int
|
||||
PlayerCount int
|
||||
HandCounts []int // cards held by each player, in seat order
|
||||
Direction int // 1 = clockwise, -1 = counter-clockwise
|
||||
}
|
||||
|
||||
// OnPlayedResult carries every mutation onPlayed() can request.
|
||||
|
|
@ -209,19 +211,29 @@ func (sr *ScriptRuntime) stateVal(s GameScriptState) goja.Value {
|
|||
for i, c := range s.Hand {
|
||||
hand[i] = map[string]string{"suit": string(c.Suit), "value": string(c.Value)}
|
||||
}
|
||||
playerHands := make([]interface{}, len(s.PlayerHands))
|
||||
for i, h := range s.PlayerHands {
|
||||
cards := make([]interface{}, len(h))
|
||||
for j, c := range h {
|
||||
cards[j] = map[string]string{"suit": string(c.Suit), "value": string(c.Value)}
|
||||
}
|
||||
playerHands[i] = cards
|
||||
}
|
||||
counts := make([]interface{}, len(s.HandCounts))
|
||||
for i, n := range s.HandCounts {
|
||||
counts[i] = n
|
||||
}
|
||||
return sr.vm.ToValue(map[string]interface{}{
|
||||
"activeSuit": string(s.ActiveSuit),
|
||||
"penaltyCards": s.PenaltyCards,
|
||||
"skipNext": s.SkipNext,
|
||||
"chosenSuit": string(s.ChosenSuit),
|
||||
"hand": hand,
|
||||
"playerCount": s.PlayerCount,
|
||||
"handCounts": counts,
|
||||
"direction": s.Direction,
|
||||
"activeSuit": string(s.ActiveSuit),
|
||||
"penaltyCards": s.PenaltyCards,
|
||||
"skipNext": s.SkipNext,
|
||||
"chosenSuit": string(s.ChosenSuit),
|
||||
"hand": hand,
|
||||
"playerHands": playerHands,
|
||||
"currentPlayerIndex": s.CurrentPlayerIndex,
|
||||
"playerCount": s.PlayerCount,
|
||||
"handCounts": counts,
|
||||
"direction": s.Direction,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue