rename State.GM THINGS to State.GM.Things

master
Bel LaPointe 2023-03-27 11:00:40 -06:00
parent f647a03467
commit 9ece270a13
3 changed files with 36 additions and 29 deletions

View File

@ -34,8 +34,13 @@ type (
configUserState struct {
Player int
Message string
Alias string
Vote string
GM configUserStateGM
}
configUserStateGM struct {
Alias string
LastAlias string
Vote string
}
configPlayer struct {

View File

@ -194,8 +194,8 @@ func (v01 *V01) serveGMStatus(w http.ResponseWriter, r *http.Request) {
func (v01 *V01) serveGMSomeoneSaidAlias(w http.ResponseWriter, r *http.Request) {
v01.cfg.Quiet = true
for k, v := range v01.cfg.Users {
v.State.Message = v.State.Alias
v.State.Alias = ""
v.State.GM.LastAlias = v.State.GM.Alias
v.State.GM.Alias = ""
v01.cfg.Users[k] = v
}
v01.servePutBroadcastValue(fmt.Sprintf("<<SOMEONE SAID %q>>", strings.ToUpper(r.URL.Query().Get("message"))))
@ -226,7 +226,7 @@ func (v01 *V01) serveGMFillNonPlayerAliases(w http.ResponseWriter, r *http.Reque
i := 0
for k, v := range v01.cfg.Users {
if v.State.Player == 0 {
v.State.Alias = pool[i]
v.State.GM.Alias = pool[i]
v01.cfg.Users[k] = v
i += 1
}
@ -238,8 +238,8 @@ func (v01 *V01) serveGMElect(w http.ResponseWriter, r *http.Request) {
aliasWinner := ""
votes := map[string]int{}
for k, v := range v01.cfg.Users {
votes[v.State.Vote] = votes[v.State.Vote] + 1 // todo into state.gm
if v.State.Message == alias { // todo lowkey aliases pls // todo into state.gm
votes[v.State.GM.Vote] = votes[v.State.GM.Vote] + 1 // todo into state.gm
if v.State.GM.LastAlias == alias { // todo lowkey aliases pls // todo into state.gm // TODO y no test fail
aliasWinner = k
}
}
@ -267,7 +267,7 @@ func (v01 *V01) serveGMVote(w http.ResponseWriter, r *http.Request) {
case http.MethodGet:
counts := map[string]string{}
for k, v := range v01.cfg.Users {
if v.State.Vote != "" {
if v.State.GM.Vote != "" {
counts[k] = "voted"
} else {
counts[k] = "voting"
@ -282,7 +282,7 @@ func (v01 *V01) serveGMVote(w http.ResponseWriter, r *http.Request) {
http.Error(w, "bad voter/candidate", http.StatusBadRequest)
return
}
v.State.Vote = candidate
v.State.GM.Vote = candidate
v01.cfg.Users[voter] = v
}
}

View File

@ -178,7 +178,9 @@ func TestServeGM(t *testing.T) {
v01.cfg.Quiet = false
v01.cfg.Users = map[string]configUser{
"bel": configUser{State: configUserState{
Alias: "driver",
GM: configUserStateGM{
Alias: "driver",
},
Message: "if someone else says 'driver', then you get to play",
}},
"broadcast": configUser{State: configUserState{
@ -189,10 +191,10 @@ func TestServeGM(t *testing.T) {
if !v01.cfg.Quiet {
t.Error(v01.cfg.Quiet)
}
if v := v01.cfg.Users["bel"]; v.State.Alias != "" {
t.Error(v.State.Alias)
} else if v.State.Message != "driver" {
t.Error(v.State.Message)
if v := v01.cfg.Users["bel"]; v.State.GM.Alias != "" {
t.Error(v.State.GM.Alias)
} else if v.State.GM.LastAlias != "driver" {
t.Error(v.State.GM.LastAlias)
}
if bc := v01.cfg.Users["broadcast"]; bc.State.Message == ":)" {
t.Error(bc)
@ -227,13 +229,13 @@ func TestServeGM(t *testing.T) {
"zach": configUser{State: configUserState{Player: 0}},
}
do(v01, "/gm/rpc/fillNonPlayerAliases", "[qt]")
if v := v01.cfg.Users["bel"]; v.State.Alias != "" {
t.Error(v.State.Alias)
if v := v01.cfg.Users["bel"]; v.State.GM.Alias != "" {
t.Error(v.State.GM.Alias)
} else if v.State.Player != 1 {
t.Error(v.State.Player)
}
if v := v01.cfg.Users["zach"]; v.State.Alias != "qt" {
t.Error(v.State.Alias)
if v := v01.cfg.Users["zach"]; v.State.GM.Alias != "qt" {
t.Error(v.State.GM.Alias)
} else if v.State.Player != 0 {
t.Error(v.State.Player)
}
@ -259,8 +261,8 @@ func TestServeGM(t *testing.T) {
v01 := NewV01(ctx, nil)
v01.cfg.Users = map[string]configUser{"bel": {}, "zach": {}}
do(v01, "/gm/rpc/vote?user=bel&payload=zach", "")
if v01.cfg.Users["bel"].State.Vote != "zach" {
t.Error(v01.cfg.Users["bel"].State.Vote)
if v01.cfg.Users["bel"].State.GM.Vote != "zach" {
t.Error(v01.cfg.Users["bel"].State.GM.Vote)
}
})
@ -283,7 +285,7 @@ func TestServeGM(t *testing.T) {
t.Run("get mid vote", func(t *testing.T) {
v01 := NewV01(ctx, nil)
v01.cfg.Users = map[string]configUser{"bel": {State: configUserState{Vote: "zach", Message: "driver"}}}
v01.cfg.Users = map[string]configUser{"bel": {State: configUserState{GM: configUserStateGM{Vote: "zach"}, Message: "driver"}}}
resp := do(v01, "/gm/rpc/vote", "", "GET")
var result result
if err := yaml.Unmarshal(resp.Body.Bytes(), &result); err != nil {
@ -319,9 +321,9 @@ func TestServeGM(t *testing.T) {
t.Run("happy", func(t *testing.T) {
v01 := NewV01(ctx, nil)
v01.cfg.Users = map[string]configUser{
"bel": configUser{State: configUserState{Vote: "zach", Message: "driver", Player: 1}},
"zach": configUser{State: configUserState{Vote: "bel", Message: "pizza"}},
"bill": configUser{State: configUserState{Vote: "bel", Message: "", Player: 2}},
"bel": configUser{State: configUserState{GM: configUserStateGM{Vote: "zach", LastAlias: "driver"}, Player: 1}},
"zach": configUser{State: configUserState{GM: configUserStateGM{Vote: "bel", LastAlias: "pizza"}}},
"bill": configUser{State: configUserState{GM: configUserStateGM{Vote: "bel"}, Player: 2}},
}
resp := do(v01, "/gm/rpc/elect?alias=pizza", "")
var result result
@ -349,9 +351,9 @@ func TestServeGM(t *testing.T) {
v01 := NewV01(ctx, nil)
v01.cfg.Players = []configPlayer{{}}
v01.cfg.Users = map[string]configUser{
"bel": configUser{State: configUserState{Vote: "zach", Message: "driver", Player: 1}},
"zach": configUser{State: configUserState{Vote: "bel", Message: ""}},
"bill": configUser{State: configUserState{Vote: "bel", Message: ""}},
"bel": configUser{State: configUserState{GM: configUserStateGM{Vote: "zach", LastAlias: "driver"}, Player: 1}},
"zach": configUser{State: configUserState{GM: configUserStateGM{Vote: "bel"}}},
"bill": configUser{State: configUserState{GM: configUserStateGM{Vote: "bel"}}},
}
resp := do(v01, "/gm/rpc/elect?alias=driver", "")
var result result
@ -385,8 +387,8 @@ func TestServeGM(t *testing.T) {
v01 := NewV01(ctx, nil)
v01.cfg.Players = []configPlayer{{}}
v01.cfg.Users = map[string]configUser{
"bel": configUser{State: configUserState{Vote: "zach", Message: "driver", Player: 1}},
"zach": configUser{State: configUserState{Vote: "bel", Message: "pizza"}},
"bel": configUser{State: configUserState{GM: configUserStateGM{Vote: "zach", LastAlias: "driver"}, Player: 1}},
"zach": configUser{State: configUserState{GM: configUserStateGM{Vote: "bel", LastAlias: "pizza"}}},
}
resp := do(v01, "/gm/rpc/elect?alias=pizza", "")
var result result