diff --git a/assets/style.css b/assets/style.css index d71d3fd..807e7b0 100644 --- a/assets/style.css +++ b/assets/style.css @@ -45,3 +45,25 @@ tr{ border: 1px solid black; background-color: darkorange; } + +@keyframes fadeInDown { + from { + opacity: 0; + transform: translateY(-1rem); + } + to { + opacity: 1; + transform: translateY(0); + } +} + +@keyframes fadeOutUp { + from { + opacity: 1; + transform: translateY(0); + } + to { + opacity: 0; + transform: translateY(-1rem); + } +} diff --git a/components/cluepopup.html b/components/cluepopup.html new file mode 100644 index 0000000..5f1f650 --- /dev/null +++ b/components/cluepopup.html @@ -0,0 +1,53 @@ +{{define "cluepopup"}} +
+ +
+{{end}} diff --git a/components/mimeclue.html b/components/mimeclue.html index 0454965..76efacf 100644 --- a/components/mimeclue.html +++ b/components/mimeclue.html @@ -1,17 +1,21 @@ {{define "mimeclue"}}
- - - +
+ + + +
{{end}} diff --git a/components/room.html b/components/room.html index ea4c239..bfb0847 100644 --- a/components/room.html +++ b/components/room.html @@ -45,5 +45,10 @@ {{template "mimeclue"}} {{end}} +
+ {{if .Room.MimeDone}} + {{template "cluepop"}} + {{end}} +
{{end}} diff --git a/handlers/auth.go b/handlers/auth.go index b565243..0f2172d 100644 --- a/handlers/auth.go +++ b/handlers/auth.go @@ -49,7 +49,10 @@ func HandleNameCheck(w http.ResponseWriter, r *http.Request) { } func HandleFrontLogin(w http.ResponseWriter, r *http.Request) { - r.ParseForm() + if err := r.ParseForm(); err != nil { + abortWithError(w, err.Error()) + return + } username := r.PostFormValue("username") if username == "" { msg := "username not provided" diff --git a/handlers/game.go b/handlers/game.go index 0165bca..4def335 100644 --- a/handlers/game.go +++ b/handlers/game.go @@ -240,3 +240,29 @@ func HandleJoinRoom(w http.ResponseWriter, r *http.Request) { } tmpl.ExecuteTemplate(w, "room", fi) } + +func HandleGiveClue(w http.ResponseWriter, r *http.Request) { + if err := r.ParseForm(); err != nil { + abortWithError(w, err.Error()) + return + } + clue := r.PostFormValue("clue") + num := r.PostFormValue("number") + fi, err := getFullInfoByCtx(r.Context()) + if err != nil { + abortWithError(w, err.Error()) + return + } + fi.Room.MimeDone = true + notify(models.NotifyMimePrefix+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 dc6d91d..8f2b2d0 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,7 @@ func ListenToRequests(port string) error { mux.HandleFunc("POST /room-create", handlers.HandleCreateRoom) mux.HandleFunc("GET /start-game", handlers.HandleStartGame) mux.HandleFunc("GET /room-join", handlers.HandleJoinRoom) - // mux.HandleFunc("GET /roomlist", handlers.HandleRoomList) + mux.HandleFunc("POST /give-clue", handlers.HandleGiveClue) //elements mux.HandleFunc("GET /room/createform", handlers.HandleShowCreateForm) mux.HandleFunc("GET /room/hideform", handlers.HandleHideCreateForm) diff --git a/models/keys.go b/models/keys.go index a87a399..eb9707f 100644 --- a/models/keys.go +++ b/models/keys.go @@ -9,4 +9,5 @@ var ( CacheStatePrefix = "state-" // sse NotifyRoomUpdatePrefix = "roomupdate_" + NotifyMimePrefix = "mimeclue_" ) diff --git a/models/main.go b/models/main.go index 4fb6d86..56bc77f 100644 --- a/models/main.go +++ b/models/main.go @@ -53,6 +53,7 @@ type Room struct { BlueCounter uint8 RedCounter uint8 RedTurn bool // false is blue turn + MimeDone bool IsPublic bool // GameSettings *GameSettings `json:"settings"` IsRunning bool `json:"is_running"`