From b135356d3f99b73107564a07f2ad3436edd75d55 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Sat, 3 May 2025 10:22:50 +0300 Subject: [PATCH] Enha: leave one room model for now --- handlers/actions.go | 2 +- handlers/handlers.go | 15 ++++++++++----- models/main.go | 31 +++---------------------------- models/state.go | 9 +++++++-- 4 files changed, 21 insertions(+), 36 deletions(-) diff --git a/handlers/actions.go b/handlers/actions.go index 3cdd177..34a4a0f 100644 --- a/handlers/actions.go +++ b/handlers/actions.go @@ -5,7 +5,7 @@ import ( "golias/models" ) -func createRoom(ctx context.Context, req *models.RoomReq) (*models.RoomPublic, error) { +func createRoom(ctx context.Context, req *models.RoomReq) (*models.Room, error) { return nil, nil } diff --git a/handlers/handlers.go b/handlers/handlers.go index 71cbf5d..5207d62 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -26,11 +26,16 @@ func init() { } var roundWords = map[string]string{ - "hamster": "blue", - "child": "red", - "wheel": "white", - "condition": "black", - "test": "white", + "hamster": "blue", + "child": "red", + "wheel": "white", + "condition": "black", + "test": "white", + "ball": "blue", + "violin": "red", + "rat": "white", + "perplexity": "blue", + "notion": "red", } func HandlePing(w http.ResponseWriter, r *http.Request) { diff --git a/models/main.go b/models/main.go index 59e1510..b66f943 100644 --- a/models/main.go +++ b/models/main.go @@ -43,6 +43,9 @@ type Room struct { Cards []WordCard GameSettings *GameSettings `json:"settings"` Result uint8 // 0 for unknown; 1 is win for red; 2 if for blue; + BlueCounter uint8 + RedCounter uint8 + RedTurn bool // false is blue turn } type WordCard struct { @@ -51,34 +54,6 @@ type WordCard struct { Revealed bool } -type RoomPublic struct { - ID string `json:"id" db:"id"` - CreatedAt time.Time `json:"created_at" db:"created_at"` - PlayerList []string `json:"player_list"` - CreatorName string `json:"creator_name"` - GameSettings *GameSettings `json:"settings"` - RedMime string - TeamTurn string - BlueMime string - RedGuessers []string - BlueGuessers []string - Cards []WordCard -} - -func (r Room) ToPublic() RoomPublic { - return RoomPublic{ - ID: r.ID, - CreatedAt: r.CreatedAt, - PlayerList: r.PlayerList, - GameSettings: r.GameSettings, - CreatorName: r.CreatorName, - RedMime: r.RedMime, - BlueMime: r.BlueMime, - RedGuessers: r.RedGuessers, - BlueGuessers: r.BlueGuessers, - } -} - type GameSettings struct { IsRunning bool `json:"is_running"` Language string `json:"language" example:"en" form:"language"` diff --git a/models/state.go b/models/state.go index f0b93bc..b833bfb 100644 --- a/models/state.go +++ b/models/state.go @@ -42,7 +42,7 @@ func StrToUserRole(s string) UserRole { type UserState struct { Username string - Room RoomPublic + Room Room Team UserTeam Role UserRole } @@ -54,8 +54,13 @@ func MakeTestState() *UserState { {Word: "wheel", Color: "white"}, {Word: "condition", Color: "black"}, {Word: "test", Color: "white"}, + {Word: "ball", Color: "blue"}, + {Word: "violin", Color: "red"}, + {Word: "rat", Color: "white"}, + {Word: "perplexity", Color: "blue"}, + {Word: "notion", Color: "red"}, } - room := RoomPublic{ + room := Room{ ID: "test-id", CreatedAt: time.Now(), CreatorName: "test-name",