This commit is contained in:
Pavel Flegr 2026-05-07 19:46:01 +02:00
commit 7b54ed8e53
3 changed files with 21 additions and 0 deletions

View file

@ -585,6 +585,10 @@ func (g *Game) buildState(p *Player, chosenSuit Suit) GameScriptState {
copy(h, pl.Hand)
hands[i] = h
}
discardCopy := make([]Card, len(g.DiscardPile))
copy(discardCopy, g.DiscardPile)
deckCopy := make([]Card, len(g.Deck))
copy(deckCopy, g.Deck)
return GameScriptState{
ActiveSuit: g.ActiveSuit,
@ -593,6 +597,8 @@ func (g *Game) buildState(p *Player, chosenSuit Suit) GameScriptState {
ChosenSuit: chosenSuit,
Hand: handCopy,
PlayerHands: hands,
DiscardPile: discardCopy,
Deck: deckCopy,
CurrentPlayerIndex: g.CurrentPlayer,
PlayerCount: len(g.Players),
HandCounts: counts,

View file

@ -97,6 +97,8 @@ type GameScriptState struct {
ChosenSuit Suit
Hand []Card // acting player's full hand (including cards being played)
PlayerHands [][]Card
DiscardPile []Card
Deck []Card
CurrentPlayerIndex int
PlayerCount int
HandCounts []int // cards held by each player, in seat order
@ -237,6 +239,15 @@ func (sr *ScriptRuntime) stateVal(s GameScriptState) goja.Value {
}
playerHands[i] = cards
}
discardPile := make([]interface{}, len(s.DiscardPile))
for i, c := range s.DiscardPile {
discardPile[i] = map[string]string{"suit": string(c.Suit), "value": string(c.Value)}
}
deck := make([]interface{}, len(s.Deck))
for i, c := range s.Deck {
deck[i] = map[string]string{"suit": string(c.Suit), "value": string(c.Value)}
}
counts := make([]interface{}, len(s.HandCounts))
for i, n := range s.HandCounts {
counts[i] = n
@ -260,6 +271,8 @@ func (sr *ScriptRuntime) stateVal(s GameScriptState) goja.Value {
"chosenSuit": string(s.ChosenSuit),
"hand": hand,
"playerHands": playerHands,
"discardPile": discardPile,
"deck": deck,
"currentPlayerIndex": s.CurrentPlayerIndex,
"playerCount": s.PlayerCount,
"handCounts": counts,

View file

@ -61,6 +61,8 @@ The script MUST export these functions (no classes, no imports):
chosenSuit string suit the player chose when playing an Upper (wildcard)
hand Card[] the acting player's FULL hand, including cards being played
playerHands Card[][] full hands of all players in seat order
discardPile Card[] full discard pile snapshot (includes previously played cards)
deck Card[] current draw deck snapshot
currentPlayerIndex number acting player seat index
playerCount number total number of players
handCounts number[] cards held by each player (seat order)