add frames array and comments for db insertion
This commit is contained in:
parent
8d35f26ac2
commit
4de6ada927
1 changed files with 8 additions and 9 deletions
|
|
@ -27,15 +27,7 @@ import (
|
||||||
log "github.com/spf13/jwalterweatherman"
|
log "github.com/spf13/jwalterweatherman"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Frame struct {
|
var frames []board.GameEvent
|
||||||
Turn int
|
|
||||||
State string
|
|
||||||
}
|
|
||||||
|
|
||||||
type GameMetadata struct {
|
|
||||||
BoardSize int
|
|
||||||
Winner string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used to store state for each SnakeState while running a local game
|
// Used to store state for each SnakeState while running a local game
|
||||||
type SnakeState struct {
|
type SnakeState struct {
|
||||||
|
|
@ -228,7 +220,9 @@ func (gameState *GameState) Run() error {
|
||||||
boardServer := board.NewBoardServer(boardGame)
|
boardServer := board.NewBoardServer(boardGame)
|
||||||
|
|
||||||
if gameState.outputFile != nil {
|
if gameState.outputFile != nil {
|
||||||
|
// insert initial game start into database
|
||||||
bytes, err := json.Marshal(boardGame)
|
bytes, err := json.Marshal(boardGame)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WARN.Printf("Failed to serialize frame event for turn%v", err)
|
log.WARN.Printf("Failed to serialize frame event for turn%v", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -367,6 +361,8 @@ func (gameState *GameState) Run() error {
|
||||||
boardServer.SendEvent(endEvent)
|
boardServer.SendEvent(endEvent)
|
||||||
|
|
||||||
if gameState.outputFile != nil {
|
if gameState.outputFile != nil {
|
||||||
|
// write frames array to db
|
||||||
|
// insert game end into database
|
||||||
bytes, err := json.Marshal(endEvent)
|
bytes, err := json.Marshal(endEvent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// log.WARN.Printf("Unable to serialize game end event: %v", err)
|
// log.WARN.Printf("Unable to serialize game end event: %v", err)
|
||||||
|
|
@ -838,6 +834,9 @@ func (gameState *GameState) buildFrameEvent(boardState *rules.BoardState) board.
|
||||||
|
|
||||||
// === New: Write frame event to output file if set ===
|
// === New: Write frame event to output file if set ===
|
||||||
if gameState.outputFile != nil {
|
if gameState.outputFile != nil {
|
||||||
|
// add frame event to array for now, will write to db at end of game
|
||||||
|
frames = append(frames, gameEvent)
|
||||||
|
|
||||||
bytes, err := json.Marshal(gameEvent)
|
bytes, err := json.Marshal(gameEvent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WARN.Printf("Failed to serialize frame event for turn %d: %v", boardState.Turn, err)
|
log.WARN.Printf("Failed to serialize frame event for turn %d: %v", boardState.Turn, err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue