rename State.GM THINGS to State.GM.Things
parent
f647a03467
commit
9ece270a13
|
|
@ -34,8 +34,13 @@ type (
|
||||||
configUserState struct {
|
configUserState struct {
|
||||||
Player int
|
Player int
|
||||||
Message string
|
Message string
|
||||||
Alias string
|
GM configUserStateGM
|
||||||
Vote string
|
}
|
||||||
|
|
||||||
|
configUserStateGM struct {
|
||||||
|
Alias string
|
||||||
|
LastAlias string
|
||||||
|
Vote string
|
||||||
}
|
}
|
||||||
|
|
||||||
configPlayer struct {
|
configPlayer struct {
|
||||||
|
|
|
||||||
|
|
@ -194,8 +194,8 @@ func (v01 *V01) serveGMStatus(w http.ResponseWriter, r *http.Request) {
|
||||||
func (v01 *V01) serveGMSomeoneSaidAlias(w http.ResponseWriter, r *http.Request) {
|
func (v01 *V01) serveGMSomeoneSaidAlias(w http.ResponseWriter, r *http.Request) {
|
||||||
v01.cfg.Quiet = true
|
v01.cfg.Quiet = true
|
||||||
for k, v := range v01.cfg.Users {
|
for k, v := range v01.cfg.Users {
|
||||||
v.State.Message = v.State.Alias
|
v.State.GM.LastAlias = v.State.GM.Alias
|
||||||
v.State.Alias = ""
|
v.State.GM.Alias = ""
|
||||||
v01.cfg.Users[k] = v
|
v01.cfg.Users[k] = v
|
||||||
}
|
}
|
||||||
v01.servePutBroadcastValue(fmt.Sprintf("<<SOMEONE SAID %q>>", strings.ToUpper(r.URL.Query().Get("message"))))
|
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
|
i := 0
|
||||||
for k, v := range v01.cfg.Users {
|
for k, v := range v01.cfg.Users {
|
||||||
if v.State.Player == 0 {
|
if v.State.Player == 0 {
|
||||||
v.State.Alias = pool[i]
|
v.State.GM.Alias = pool[i]
|
||||||
v01.cfg.Users[k] = v
|
v01.cfg.Users[k] = v
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
|
|
@ -238,8 +238,8 @@ func (v01 *V01) serveGMElect(w http.ResponseWriter, r *http.Request) {
|
||||||
aliasWinner := ""
|
aliasWinner := ""
|
||||||
votes := map[string]int{}
|
votes := map[string]int{}
|
||||||
for k, v := range v01.cfg.Users {
|
for k, v := range v01.cfg.Users {
|
||||||
votes[v.State.Vote] = votes[v.State.Vote] + 1 // todo into state.gm
|
votes[v.State.GM.Vote] = votes[v.State.GM.Vote] + 1 // todo into state.gm
|
||||||
if v.State.Message == alias { // todo lowkey aliases pls // 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
|
aliasWinner = k
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -267,7 +267,7 @@ func (v01 *V01) serveGMVote(w http.ResponseWriter, r *http.Request) {
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
counts := map[string]string{}
|
counts := map[string]string{}
|
||||||
for k, v := range v01.cfg.Users {
|
for k, v := range v01.cfg.Users {
|
||||||
if v.State.Vote != "" {
|
if v.State.GM.Vote != "" {
|
||||||
counts[k] = "voted"
|
counts[k] = "voted"
|
||||||
} else {
|
} else {
|
||||||
counts[k] = "voting"
|
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)
|
http.Error(w, "bad voter/candidate", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
v.State.Vote = candidate
|
v.State.GM.Vote = candidate
|
||||||
v01.cfg.Users[voter] = v
|
v01.cfg.Users[voter] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,9 @@ func TestServeGM(t *testing.T) {
|
||||||
v01.cfg.Quiet = false
|
v01.cfg.Quiet = false
|
||||||
v01.cfg.Users = map[string]configUser{
|
v01.cfg.Users = map[string]configUser{
|
||||||
"bel": configUser{State: configUserState{
|
"bel": configUser{State: configUserState{
|
||||||
Alias: "driver",
|
GM: configUserStateGM{
|
||||||
|
Alias: "driver",
|
||||||
|
},
|
||||||
Message: "if someone else says 'driver', then you get to play",
|
Message: "if someone else says 'driver', then you get to play",
|
||||||
}},
|
}},
|
||||||
"broadcast": configUser{State: configUserState{
|
"broadcast": configUser{State: configUserState{
|
||||||
|
|
@ -189,10 +191,10 @@ func TestServeGM(t *testing.T) {
|
||||||
if !v01.cfg.Quiet {
|
if !v01.cfg.Quiet {
|
||||||
t.Error(v01.cfg.Quiet)
|
t.Error(v01.cfg.Quiet)
|
||||||
}
|
}
|
||||||
if v := v01.cfg.Users["bel"]; v.State.Alias != "" {
|
if v := v01.cfg.Users["bel"]; v.State.GM.Alias != "" {
|
||||||
t.Error(v.State.Alias)
|
t.Error(v.State.GM.Alias)
|
||||||
} else if v.State.Message != "driver" {
|
} else if v.State.GM.LastAlias != "driver" {
|
||||||
t.Error(v.State.Message)
|
t.Error(v.State.GM.LastAlias)
|
||||||
}
|
}
|
||||||
if bc := v01.cfg.Users["broadcast"]; bc.State.Message == ":)" {
|
if bc := v01.cfg.Users["broadcast"]; bc.State.Message == ":)" {
|
||||||
t.Error(bc)
|
t.Error(bc)
|
||||||
|
|
@ -227,13 +229,13 @@ func TestServeGM(t *testing.T) {
|
||||||
"zach": configUser{State: configUserState{Player: 0}},
|
"zach": configUser{State: configUserState{Player: 0}},
|
||||||
}
|
}
|
||||||
do(v01, "/gm/rpc/fillNonPlayerAliases", "[qt]")
|
do(v01, "/gm/rpc/fillNonPlayerAliases", "[qt]")
|
||||||
if v := v01.cfg.Users["bel"]; v.State.Alias != "" {
|
if v := v01.cfg.Users["bel"]; v.State.GM.Alias != "" {
|
||||||
t.Error(v.State.Alias)
|
t.Error(v.State.GM.Alias)
|
||||||
} else if v.State.Player != 1 {
|
} else if v.State.Player != 1 {
|
||||||
t.Error(v.State.Player)
|
t.Error(v.State.Player)
|
||||||
}
|
}
|
||||||
if v := v01.cfg.Users["zach"]; v.State.Alias != "qt" {
|
if v := v01.cfg.Users["zach"]; v.State.GM.Alias != "qt" {
|
||||||
t.Error(v.State.Alias)
|
t.Error(v.State.GM.Alias)
|
||||||
} else if v.State.Player != 0 {
|
} else if v.State.Player != 0 {
|
||||||
t.Error(v.State.Player)
|
t.Error(v.State.Player)
|
||||||
}
|
}
|
||||||
|
|
@ -259,8 +261,8 @@ func TestServeGM(t *testing.T) {
|
||||||
v01 := NewV01(ctx, nil)
|
v01 := NewV01(ctx, nil)
|
||||||
v01.cfg.Users = map[string]configUser{"bel": {}, "zach": {}}
|
v01.cfg.Users = map[string]configUser{"bel": {}, "zach": {}}
|
||||||
do(v01, "/gm/rpc/vote?user=bel&payload=zach", "")
|
do(v01, "/gm/rpc/vote?user=bel&payload=zach", "")
|
||||||
if v01.cfg.Users["bel"].State.Vote != "zach" {
|
if v01.cfg.Users["bel"].State.GM.Vote != "zach" {
|
||||||
t.Error(v01.cfg.Users["bel"].State.Vote)
|
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) {
|
t.Run("get mid vote", func(t *testing.T) {
|
||||||
v01 := NewV01(ctx, nil)
|
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")
|
resp := do(v01, "/gm/rpc/vote", "", "GET")
|
||||||
var result result
|
var result result
|
||||||
if err := yaml.Unmarshal(resp.Body.Bytes(), &result); err != nil {
|
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) {
|
t.Run("happy", func(t *testing.T) {
|
||||||
v01 := NewV01(ctx, nil)
|
v01 := NewV01(ctx, nil)
|
||||||
v01.cfg.Users = map[string]configUser{
|
v01.cfg.Users = map[string]configUser{
|
||||||
"bel": configUser{State: configUserState{Vote: "zach", Message: "driver", Player: 1}},
|
"bel": configUser{State: configUserState{GM: configUserStateGM{Vote: "zach", LastAlias: "driver"}, Player: 1}},
|
||||||
"zach": configUser{State: configUserState{Vote: "bel", Message: "pizza"}},
|
"zach": configUser{State: configUserState{GM: configUserStateGM{Vote: "bel", LastAlias: "pizza"}}},
|
||||||
"bill": configUser{State: configUserState{Vote: "bel", Message: "", Player: 2}},
|
"bill": configUser{State: configUserState{GM: configUserStateGM{Vote: "bel"}, Player: 2}},
|
||||||
}
|
}
|
||||||
resp := do(v01, "/gm/rpc/elect?alias=pizza", "")
|
resp := do(v01, "/gm/rpc/elect?alias=pizza", "")
|
||||||
var result result
|
var result result
|
||||||
|
|
@ -349,9 +351,9 @@ func TestServeGM(t *testing.T) {
|
||||||
v01 := NewV01(ctx, nil)
|
v01 := NewV01(ctx, nil)
|
||||||
v01.cfg.Players = []configPlayer{{}}
|
v01.cfg.Players = []configPlayer{{}}
|
||||||
v01.cfg.Users = map[string]configUser{
|
v01.cfg.Users = map[string]configUser{
|
||||||
"bel": configUser{State: configUserState{Vote: "zach", Message: "driver", Player: 1}},
|
"bel": configUser{State: configUserState{GM: configUserStateGM{Vote: "zach", LastAlias: "driver"}, Player: 1}},
|
||||||
"zach": configUser{State: configUserState{Vote: "bel", Message: ""}},
|
"zach": configUser{State: configUserState{GM: configUserStateGM{Vote: "bel"}}},
|
||||||
"bill": configUser{State: configUserState{Vote: "bel", Message: ""}},
|
"bill": configUser{State: configUserState{GM: configUserStateGM{Vote: "bel"}}},
|
||||||
}
|
}
|
||||||
resp := do(v01, "/gm/rpc/elect?alias=driver", "")
|
resp := do(v01, "/gm/rpc/elect?alias=driver", "")
|
||||||
var result result
|
var result result
|
||||||
|
|
@ -385,8 +387,8 @@ func TestServeGM(t *testing.T) {
|
||||||
v01 := NewV01(ctx, nil)
|
v01 := NewV01(ctx, nil)
|
||||||
v01.cfg.Players = []configPlayer{{}}
|
v01.cfg.Players = []configPlayer{{}}
|
||||||
v01.cfg.Users = map[string]configUser{
|
v01.cfg.Users = map[string]configUser{
|
||||||
"bel": configUser{State: configUserState{Vote: "zach", Message: "driver", Player: 1}},
|
"bel": configUser{State: configUserState{GM: configUserStateGM{Vote: "zach", LastAlias: "driver"}, Player: 1}},
|
||||||
"zach": configUser{State: configUserState{Vote: "bel", Message: "pizza"}},
|
"zach": configUser{State: configUserState{GM: configUserStateGM{Vote: "bel", LastAlias: "pizza"}}},
|
||||||
}
|
}
|
||||||
resp := do(v01, "/gm/rpc/elect?alias=pizza", "")
|
resp := do(v01, "/gm/rpc/elect?alias=pizza", "")
|
||||||
var result result
|
var result result
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue