diff --git a/components/actionhistory.html b/components/actionhistory.html new file mode 100644 index 0000000..ef3bf73 --- /dev/null +++ b/components/actionhistory.html @@ -0,0 +1,17 @@ +{{define "actionhistory"}} +
+ Backlog: + {{range .}} +
+ + {{.Actor}}: + {{.Action}}: + {{.Word}} + {{if .Number}} + - {{.Number}} + {{end}} + +
+ {{end}} +
+{{end}} diff --git a/components/cluepopup.html b/components/cluepopup.html deleted file mode 100644 index 5f1f650..0000000 --- a/components/cluepopup.html +++ /dev/null @@ -1,53 +0,0 @@ -{{define "cluepopup"}} -
- -
-{{end}} diff --git a/components/room.html b/components/room.html index bfb0847..e174109 100644 --- a/components/room.html +++ b/components/room.html @@ -45,10 +45,8 @@ {{template "mimeclue"}} {{end}} -
- {{if .Room.MimeDone}} - {{template "cluepop"}} - {{end}} +
+ {{template "actionhistory" .Room.ActionHistory}}
{{end}} diff --git a/handlers/elements.go b/handlers/elements.go index 32f2995..999409e 100644 --- a/handlers/elements.go +++ b/handlers/elements.go @@ -66,6 +66,14 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { } fi.Room.RevealSpecificWord(word) fi.Room.UpdateCounter() + action := models.Action{ + Actor: fi.State.Username, + ActorColor: string(fi.State.Team), + WordColor: color, + Action: "guessed", + Word: word, + } + fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) // if opened card is of color of opp team, change turn switch color { case "black": @@ -83,3 +91,17 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "") tmpl.ExecuteTemplate(w, "cardword", cardword) } + +func HandleActionHistory(w http.ResponseWriter, r *http.Request) { + fi, err := getFullInfoByCtx(r.Context()) + if err != nil { + abortWithError(w, err.Error()) + return + } + tmpl, err := template.ParseGlob("components/*.html") + if err != nil { + abortWithError(w, err.Error()) + return + } + tmpl.ExecuteTemplate(w, "actionhistory", fi.Room.ActionHistory) +} diff --git a/handlers/game.go b/handlers/game.go index 4def335..410ab01 100644 --- a/handlers/game.go +++ b/handlers/game.go @@ -253,16 +253,19 @@ func HandleGiveClue(w http.ResponseWriter, r *http.Request) { abortWithError(w, err.Error()) return } + action := models.Action{ + Actor: fi.State.Username, + ActorColor: string(fi.State.Team), + WordColor: string(fi.State.Team), + Action: "gave clue", + Word: clue, + Number: num, + } + fi.Room.ActionHistory = append(fi.Room.ActionHistory, action) fi.Room.MimeDone = true - notify(models.NotifyMimePrefix+fi.Room.ID, clue+num) + notify(models.NotifyBacklogPrefix+fi.Room.ID, clue+num) if err := saveFullInfo(fi); err != nil { abortWithError(w, err.Error()) return } - // tmpl, err := template.ParseGlob("components/*.html") - // if err != nil { - // abortWithError(w, err.Error()) - // return - // } - // tmpl.ExecuteTemplate(w, "room", fi) } diff --git a/main.go b/main.go index 8f2b2d0..604dd09 100644 --- a/main.go +++ b/main.go @@ -31,6 +31,7 @@ func ListenToRequests(port string) error { mux.HandleFunc("GET /room-join", handlers.HandleJoinRoom) mux.HandleFunc("POST /give-clue", handlers.HandleGiveClue) //elements + mux.HandleFunc("GET /actionhistory", handlers.HandleActionHistory) mux.HandleFunc("GET /room/createform", handlers.HandleShowCreateForm) mux.HandleFunc("GET /room/hideform", handlers.HandleHideCreateForm) mux.HandleFunc("GET /word/show-color", handlers.HandleShowColor) diff --git a/models/keys.go b/models/keys.go index eb9707f..e8dd4b9 100644 --- a/models/keys.go +++ b/models/keys.go @@ -9,5 +9,5 @@ var ( CacheStatePrefix = "state-" // sse NotifyRoomUpdatePrefix = "roomupdate_" - NotifyMimePrefix = "mimeclue_" + NotifyBacklogPrefix = "backlog_" ) diff --git a/models/main.go b/models/main.go index 56bc77f..d5e110d 100644 --- a/models/main.go +++ b/models/main.go @@ -37,24 +37,34 @@ type Team struct { Color string } +type Action struct { + Actor string + ActorColor string + Action string // clue | guess + Word string + WordColor string + Number string // for clue +} + type Room struct { ID string `json:"id" db:"id"` CreatedAt time.Time `json:"created_at" db:"created_at"` // RoomName string `json:"room_name"` - RoomPass string `json:"room_pass"` - RoomLink string - CreatorName string `json:"creator_name"` - PlayerList []string `json:"player_list"` - TeamTurn string - RedTeam Team - BlueTeam Team - Cards []WordCard - Result uint8 // 0 for unknown; 1 is win for red; 2 if for blue; - BlueCounter uint8 - RedCounter uint8 - RedTurn bool // false is blue turn - MimeDone bool - IsPublic bool + RoomPass string `json:"room_pass"` + RoomLink string + CreatorName string `json:"creator_name"` + PlayerList []string `json:"player_list"` + ActionHistory []Action + TeamTurn string + RedTeam Team + BlueTeam Team + Cards []WordCard + Result uint8 // 0 for unknown; 1 is win for red; 2 if for blue; + BlueCounter uint8 + RedCounter uint8 + RedTurn bool // false is blue turn + MimeDone bool + IsPublic bool // GameSettings *GameSettings `json:"settings"` IsRunning bool `json:"is_running"` Language string `json:"language" example:"en" form:"language"`