Phase 1.1: Global state refactor into GameState struct with JSON serialization #6

Open
opened 2026-06-07 22:43:45 -06:00 by ppreeper · 0 comments
Owner

Description

The original C code uses global variables extensively (Country country, GArray *users, gint season, gint week, gint counters[], gint status[], gpointer statp, etc.). These are defined in src/variables.h. For a web game, we need proper state management.

Tasks

  • Create a GameState struct that encapsulates all global state
  • Move globals: country, users, season, week, week_round, counters, transfer_list, season_stats, cur_user, bets, jobs, job_teams, strategies, name_lists, lg_commentary, current_interest
  • Add JSON marshal/unmarshal support (json.Marshaler / json.Unmarshaler)
  • Create SaveGame() and LoadGame() functions
  • Replace global variable access across all code with state.Country, state.Users, etc.

Files Affected

  • All go/code/*.go files reference globals
  • variables.h equivalents in Go

Acceptance Criteria

  • Game state can be serialized to JSON and round-tripped
  • No remaining C-style global variables in Go code
  • Save/load cycle produces identical game state
## Description The original C code uses global variables extensively (`Country country`, `GArray *users`, `gint season`, `gint week`, `gint counters[]`, `gint status[]`, `gpointer statp`, etc.). These are defined in `src/variables.h`. For a web game, we need proper state management. ## Tasks - [ ] Create a `GameState` struct that encapsulates all global state - [ ] Move globals: `country`, `users`, `season`, `week`, `week_round`, `counters`, `transfer_list`, `season_stats`, `cur_user`, `bets`, `jobs`, `job_teams`, `strategies`, `name_lists`, `lg_commentary`, `current_interest` - [ ] Add JSON marshal/unmarshal support (`json.Marshaler` / `json.Unmarshaler`) - [ ] Create `SaveGame()` and `LoadGame()` functions - [ ] Replace global variable access across all code with `state.Country`, `state.Users`, etc. ## Files Affected - All `go/code/*.go` files reference globals - `variables.h` equivalents in Go ## Acceptance Criteria - Game state can be serialized to JSON and round-tripped - No remaining C-style global variables in Go code - Save/load cycle produces identical game state
ppreeper added this to the Phase 1 milestone 2026-06-07 22:50:22 -06:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ppreeper/bygfoot#6
No description provided.