Skip to content

Commit

Permalink
store/lobbies: Added the Lobbies logic
Browse files Browse the repository at this point in the history
To be able to create/list/show/delte lobbies and Join/Leave them too
and also once the owner decides a new game can start with the people on the lobby.

Test where skipped for now
  • Loading branch information
xescugc committed May 9, 2024
1 parent bd35a1d commit 6d71aaa
Show file tree
Hide file tree
Showing 26 changed files with 1,824 additions and 131 deletions.
145 changes: 145 additions & 0 deletions action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ type Action struct {
OpenTowerMenu *OpenTowerMenuPayload `json:"open_tower_menu,omitempty"`
CloseTowerMenu *CloseTowerMenuPayload `json:"close_tower_menu,omitempty"`

CreateLobby *CreateLobbyPayload `json:"create_lobby,omitempty"`
DeleteLobby *DeleteLobbyPayload `json:"delete_lobby,omitempty"`
JoinLobby *JoinLobbyPayload `json:"join_lobby,omitempty"`
AddLobbies *AddLobbiesPayload `json:"add_lobbies,omitempty"`
SelectLobby *SelectLobbyPayload `json:"select_lobby,omitempty"`
LeaveLobby *LeaveLobbyPayload `json:"leave_lobby,omitempty"`
UpdateLobby *UpdateLobbyPayload `json:"update_lobby,omitempty"`
StartLobby *StartLobbyPayload `json:"start_lobby,omitempty"`

UserSignUp *UserSignUpPayload `json:"user_sign_up,omitempty"`
SignUpError *SignUpErrorPayload `json:"sign_in_error,omitempty"`
UserSignIn *UserSignInPayload `json:"user_sign_in,omitempty"`
Expand All @@ -48,6 +57,7 @@ type Action struct {
RemovePlayer *RemovePlayerPayload `json:"remove_player,omitempty"`
JoinWaitingRoom *JoinWaitingRoomPayload `json:"join_waiting_room,omitempty"`
ExitWaitingRoom *ExitWaitingRoomPayload `json:"exit_waiting_room,omitempty"`
StartRoom *StartRoomPayload `json:"start_room,omitempty"`
SyncState *SyncStatePayload `json:"sync_state,omitempty"`
SyncUsers *SyncUsersPayload `json:"sync_users,omitempty"`
SyncWaitingRoom *SyncWaitingRoomPayload `json:"sync_waiting_room,omitempty"`
Expand Down Expand Up @@ -332,6 +342,19 @@ func NewStartGame() *Action {
}
}

type StartRoomPayload struct {
RoomID string
}

func NewStartRoom(rid string) *Action {
return &Action{
Type: StartRoom,
StartRoom: &StartRoomPayload{
RoomID: rid,
},
}
}

type OpenTowerMenuPayload struct {
TowerID string
}
Expand Down Expand Up @@ -606,3 +629,125 @@ func NewUpdateTower(pid, tid string) *Action {
},
}
}

type CreateLobbyPayload struct {
LobbyID string
Owner string
LobbyName string
LobbyMaxPlayers int
}

func NewCreateLobby(lid, o, ln string, lmp int) *Action {
return &Action{
Type: CreateLobby,
CreateLobby: &CreateLobbyPayload{
LobbyID: lid,
Owner: o,
LobbyName: ln,
LobbyMaxPlayers: lmp,
},
}
}

type DeleteLobbyPayload struct {
LobbyID string
}

func NewDeleteLobby(lid string) *Action {
return &Action{
Type: DeleteLobby,
DeleteLobby: &DeleteLobbyPayload{
LobbyID: lid,
},
}
}

type JoinLobbyPayload struct {
LobbyID string
Username string
}

func NewJoinLobby(lid, un string) *Action {
return &Action{
Type: JoinLobby,
JoinLobby: &JoinLobbyPayload{
LobbyID: lid,
Username: un,
},
}
}

type AddLobbiesPayload struct {
Lobbies []*LobbyPayload
}

type LobbyPayload struct {
ID string
Name string
MaxPlayers int

Players []string

Owner string
}

func NewAddLobbies(lbs *AddLobbiesPayload) *Action {
return &Action{
Type: AddLobbies,
AddLobbies: lbs,
}
}

type SelectLobbyPayload struct {
LobbyID string
}

func NewSelectLobby(lbi string) *Action {
return &Action{
Type: SelectLobby,
SelectLobby: &SelectLobbyPayload{
LobbyID: lbi,
},
}
}

type LeaveLobbyPayload struct {
LobbyID string
Username string
}

func NewLeaveLobby(lbi, un string) *Action {
return &Action{
Type: LeaveLobby,
LeaveLobby: &LeaveLobbyPayload{
LobbyID: lbi,
Username: un,
},
}
}

type UpdateLobbyPayload struct {
Lobby LobbyPayload
}

func NewUpdateLobby(l LobbyPayload) *Action {
return &Action{
Type: UpdateLobby,
UpdateLobby: &UpdateLobbyPayload{
Lobby: l,
},
}
}

type StartLobbyPayload struct {
LobbyID string
}

func NewStartLobby(lid string) *Action {
return &Action{
Type: StartLobby,
StartLobby: &StartLobbyPayload{
LobbyID: lid,
},
}
}
10 changes: 10 additions & 0 deletions action/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,19 @@ const (
UserSignOut
JoinWaitingRoom
ExitWaitingRoom
StartRoom
ToggleStats
VersionError

CreateLobby
DeleteLobby
JoinLobby
AddLobbies
SelectLobby
LeaveLobby
UpdateLobby
StartLobby

// Specific to WS
AddPlayer
RemovePlayer
Expand Down
108 changes: 72 additions & 36 deletions action/type_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6d71aaa

Please sign in to comment.