Chore: model update
This commit is contained in:
@ -9,6 +9,44 @@ import (
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
type (
|
||||
UserTeam string
|
||||
UserRole string
|
||||
)
|
||||
|
||||
const (
|
||||
// UserTeam
|
||||
UserTeamBlue = "blue"
|
||||
UserTeamRed = "red"
|
||||
UserTeamNone = ""
|
||||
//UserRole
|
||||
UserRoleMime = "mime"
|
||||
UserRoleGuesser = "guesser"
|
||||
UserRoleNone = ""
|
||||
)
|
||||
|
||||
func StrToUserTeam(s string) UserTeam {
|
||||
switch s {
|
||||
case "blue":
|
||||
return UserTeamBlue
|
||||
case "red":
|
||||
return UserTeamRed
|
||||
default:
|
||||
return UserTeamNone
|
||||
}
|
||||
}
|
||||
|
||||
func StrToUserRole(s string) UserRole {
|
||||
switch s {
|
||||
case "mime":
|
||||
return UserRoleMime
|
||||
case "guesser":
|
||||
return UserRoleGuesser
|
||||
default:
|
||||
return UserRoleNone
|
||||
}
|
||||
}
|
||||
|
||||
type WordColor string
|
||||
|
||||
const (
|
||||
@ -50,20 +88,20 @@ type Team struct {
|
||||
}
|
||||
|
||||
type Action struct {
|
||||
ID int `json:"id" db:"id"`
|
||||
RoomID string `json:"room_id" db:"room_id"`
|
||||
Actor string `json:"actor" db:"actor"`
|
||||
ActorColor string `json:"actor_color" db:"actor_color"`
|
||||
Action string `json:"action_type" db:"action_type"`
|
||||
Word string `json:"word" db:"word"`
|
||||
WordColor string `json:"word_color" db:"word_color"`
|
||||
Number string `json:"number_associated" db:"number_associated"`
|
||||
CreatedAt time.Time `json:"created_at" db:"-"`
|
||||
CreatedAtUnix int64 `db:"created_at"`
|
||||
ID uint32 `json:"id" db:"id"`
|
||||
RoomID string `json:"room_id" db:"room_id"`
|
||||
Actor string `json:"actor" db:"actor"`
|
||||
ActorColor string `json:"actor_color" db:"actor_color"`
|
||||
Action string `json:"action_type" db:"action_type"`
|
||||
Word string `json:"word" db:"word"`
|
||||
WordColor string `json:"word_color" db:"word_color"`
|
||||
Number string `json:"number_associated" db:"number_associated"`
|
||||
CreatedAt time.Time `json:"created_at" db:"-"`
|
||||
CreatedAtUnix int64 `db:"created_at"`
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
ID int `json:"id" db:"id"`
|
||||
ID uint32 `json:"id" db:"id"`
|
||||
RoomID string `json:"room_id" db:"room_id"`
|
||||
Username string `json:"username" db:"username"`
|
||||
Team UserTeam `json:"team" db:"team"`
|
||||
@ -71,6 +109,15 @@ type Player struct {
|
||||
IsBot bool `json:"is_bot" db:"is_bot"`
|
||||
}
|
||||
|
||||
func InitPlayer(username string) *Player {
|
||||
return &Player{
|
||||
// last id + 1?
|
||||
Username: username,
|
||||
Team: UserTeamNone,
|
||||
Role: UserRoleNone,
|
||||
}
|
||||
}
|
||||
|
||||
type BotPlayer struct {
|
||||
Role UserRole // gueeser | mime
|
||||
Team UserTeam
|
||||
|
113
models/state.go
113
models/state.go
@ -1,113 +0,0 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type (
|
||||
UserTeam string
|
||||
UserRole string
|
||||
)
|
||||
|
||||
const (
|
||||
// UserTeam
|
||||
UserTeamBlue = "blue"
|
||||
UserTeamRed = "red"
|
||||
UserTeamNone = ""
|
||||
//UserRole
|
||||
UserRoleMime = "mime"
|
||||
UserRoleGuesser = "guesser"
|
||||
UserRoleNone = ""
|
||||
)
|
||||
|
||||
func StrToUserTeam(s string) UserTeam {
|
||||
switch s {
|
||||
case "blue":
|
||||
return UserTeamBlue
|
||||
case "red":
|
||||
return UserTeamRed
|
||||
default:
|
||||
return UserTeamNone
|
||||
}
|
||||
}
|
||||
|
||||
func StrToUserRole(s string) UserRole {
|
||||
switch s {
|
||||
case "mime":
|
||||
return UserRoleMime
|
||||
case "guesser":
|
||||
return UserRoleGuesser
|
||||
default:
|
||||
return UserRoleNone
|
||||
}
|
||||
}
|
||||
|
||||
type UserState struct {
|
||||
Username string
|
||||
RoomID string
|
||||
Team UserTeam
|
||||
Role UserRole
|
||||
}
|
||||
|
||||
func (u *UserState) ExitRoom() {
|
||||
u.RoomID = ""
|
||||
u.Team = UserTeamNone
|
||||
u.Role = UserRoleNone
|
||||
}
|
||||
|
||||
func MakeTestState(creatorName string) *FullInfo {
|
||||
cards := []WordCard{
|
||||
{Word: "hamster", Color: "blue"},
|
||||
{Word: "child", Color: "red"},
|
||||
{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"},
|
||||
{Word: "guitar", Color: "blue"},
|
||||
{Word: "ocean", Color: "blue"},
|
||||
{Word: "moon", Color: "blue"},
|
||||
{Word: "coffee", Color: "blue"},
|
||||
{Word: "mountain", Color: "blue"},
|
||||
{Word: "book", Color: "blue"},
|
||||
{Word: "camera", Color: "blue"},
|
||||
{Word: "apple", Color: "red"},
|
||||
{Word: "fire", Color: "red"},
|
||||
{Word: "rose", Color: "red"},
|
||||
{Word: "sun", Color: "red"},
|
||||
{Word: "cherry", Color: "red"},
|
||||
{Word: "heart", Color: "red"},
|
||||
{Word: "tomato", Color: "red"},
|
||||
{Word: "cloud", Color: "white"},
|
||||
}
|
||||
redTeam := Team{Guessers: []string{"Adam", "Eve"}, Mime: "Serpent", Color: "red"}
|
||||
blueTeam := Team{Guessers: []string{"Abel", "Kain"}, Color: "blue"}
|
||||
room := &Room{
|
||||
ID: "test-id",
|
||||
CreatedAt: time.Now(),
|
||||
CreatorName: creatorName,
|
||||
Cards: cards,
|
||||
RedTeam: redTeam,
|
||||
BlueTeam: blueTeam,
|
||||
TeamTurn: "blue",
|
||||
}
|
||||
us := &UserState{
|
||||
Username: creatorName,
|
||||
Team: UserTeamNone,
|
||||
Role: UserRoleNone,
|
||||
RoomID: "test-id",
|
||||
}
|
||||
return &FullInfo{
|
||||
State: us,
|
||||
Room: room,
|
||||
}
|
||||
}
|
||||
|
||||
func InitState(username string) *UserState {
|
||||
return &UserState{
|
||||
Username: username,
|
||||
Team: UserTeamNone,
|
||||
Role: UserRoleNone,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user