Skip to content

Commit

Permalink
store: Fixed the store tests
Browse files Browse the repository at this point in the history
And renamed the actions that are meant to synchronize information Sync
instead of Update
  • Loading branch information
xescugc committed Jan 18, 2024
1 parent 0f9fcdf commit 6d62286
Show file tree
Hide file tree
Showing 16 changed files with 338 additions and 179 deletions.
44 changes: 22 additions & 22 deletions action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ type Action struct {
RemovePlayer *RemovePlayerPayload `json:"remove_player, omitempty"`
JoinWaitingRoom *JoinWaitingRoomPayload `json:"join_waiting_room, omitempty"`
ExitWaitingRoom *ExitWaitingRoomPayload `json:"exit_waiting_room, omitempty"`
UpdateState *UpdateStatePayload `json:"update_state, omitempty"`
UpdateUsers *UpdateUsersPayload `json:"update_users, omitempty"`
SyncState *SyncStatePayload `json:"sync_state, omitempty"`
SyncUsers *SyncUsersPayload `json:"sync_users, omitempty"`
SyncWaitingRoom *SyncWaitingRoomPayload `json:"sync_waiting_room, omitempty"`
}

Expand Down Expand Up @@ -472,18 +472,18 @@ func NewSyncWaitingRoom(tp, s, cd int) *Action {
}
}

type UpdateStatePayload struct {
Players *UpdateStatePlayersPayload
Towers *UpdateStateTowersPayload
Units *UpdateStateUnitsPayload
type SyncStatePayload struct {
Players *SyncStatePlayersPayload
Towers *SyncStateTowersPayload
Units *SyncStateUnitsPayload
}

type UpdateStatePlayersPayload struct {
Players map[string]*UpdateStatePlayerPayload
type SyncStatePlayersPayload struct {
Players map[string]*SyncStatePlayerPayload
IncomeTimer int
}

type UpdateStatePlayerPayload struct {
type SyncStatePlayerPayload struct {
ID string
Name string
Lives int
Expand All @@ -494,11 +494,11 @@ type UpdateStatePlayerPayload struct {
Winner bool
}

type UpdateStateTowersPayload struct {
Towers map[string]*UpdateStateTowerPayload
type SyncStateTowersPayload struct {
Towers map[string]*SyncStateTowerPayload
}

type UpdateStateTowerPayload struct {
type SyncStateTowerPayload struct {
utils.Object

ID string
Expand All @@ -507,11 +507,11 @@ type UpdateStateTowerPayload struct {
PlayerID string
}

type UpdateStateUnitsPayload struct {
Units map[string]*UpdateStateUnitPayload
type SyncStateUnitsPayload struct {
Units map[string]*SyncStateUnitPayload
}

type UpdateStateUnitPayload struct {
type SyncStateUnitPayload struct {
utils.MovingObject

ID string
Expand All @@ -527,25 +527,25 @@ type UpdateStateUnitPayload struct {
}

// TODO: or make the action.Action separated or make the store.Player separated
func NewUpdateState(players *UpdateStatePlayersPayload, towers *UpdateStateTowersPayload, units *UpdateStateUnitsPayload) *Action {
func NewSyncState(players *SyncStatePlayersPayload, towers *SyncStateTowersPayload, units *SyncStateUnitsPayload) *Action {
return &Action{
Type: UpdateState,
UpdateState: &UpdateStatePayload{
Type: SyncState,
SyncState: &SyncStatePayload{
Players: players,
Towers: towers,
Units: units,
},
}
}

type UpdateUsersPayload struct {
type SyncUsersPayload struct {
TotalUsers int
}

func NewUpdateUsers(totalUsers int) *Action {
func NewSyncUsers(totalUsers int) *Action {
return &Action{
Type: UpdateUsers,
UpdateUsers: &UpdateUsersPayload{
Type: SyncUsers,
SyncUsers: &SyncUsersPayload{
TotalUsers: totalUsers,
},
}
Expand Down
5 changes: 2 additions & 3 deletions action/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const (
TowerAttack
UnitKilled
WindowResizing
PlayerReady
NavigateTo
StartGame
OpenTowerMenu
Expand All @@ -40,8 +39,8 @@ const (
// Specific to WS
AddPlayer
RemovePlayer
UpdateState
UpdateUsers
SyncState
SyncUsers
WaitRoomCountdownTick
SyncWaitingRoom
)
170 changes: 83 additions & 87 deletions action/type_string.go

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

4 changes: 2 additions & 2 deletions client/lobby.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func (ls *LobbyStore) Reduce(state, a interface{}) interface{} {
}

switch act.Type {
case action.UpdateUsers:
lstate.TotalUsers = act.UpdateUsers.TotalUsers
case action.SyncUsers:
lstate.TotalUsers = act.SyncUsers.TotalUsers
}

return lstate
Expand Down
2 changes: 1 addition & 1 deletion integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestRun(t *testing.T) {
sd := flux.NewDispatcher()
sad := server.NewActionDispatcher(sd, ss)
rooms := server.NewRoomsStore(sd, ss)
users := server.NewUsersStore(sd)
users := server.NewUsersStore(sd, ss)

ss.Rooms = rooms
ss.Users = users
Expand Down
Loading

0 comments on commit 6d62286

Please sign in to comment.