File tree Expand file tree Collapse file tree 5 files changed +25
-7
lines changed Expand file tree Collapse file tree 5 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ func TestParser_BindNewPlayer_Issue98(t *testing.T) {
4242 player := fakePlayerEntity (2 )
4343 p .bindNewPlayer (player )
4444
45- assert .Len (t , p .GameState ().Participants ().All (), 1 )
45+ assert .Len (t , p .GameState ().Participants ().Connected (), 1 )
4646}
4747
4848func TestParser_BindNewPlayer_Issue98_Reconnect (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -26,6 +26,11 @@ func (ptcp *Participants) All() []*common.Player {
2626 return ptcp .Called ().Get (0 ).([]* common.Player )
2727}
2828
29+ // Connected is a mock-implementation of IParticipants.Connected().
30+ func (ptcp * Participants ) Connected () []* common.Player {
31+ return ptcp .Called ().Get (0 ).([]* common.Player )
32+ }
33+
2934// Playing is a mock-implementation of IParticipants.Playing().
3035func (ptcp * Participants ) Playing () []* common.Player {
3136 return ptcp .Called ().Get (0 ).([]* common.Player )
Original file line number Diff line number Diff line change @@ -168,9 +168,19 @@ func (ptcp Participants) ByEntityID() map[int]*common.Player {
168168 return res
169169}
170170
171- // All returns all currently connected players & spectators.
171+ // All returns all currently known players & spectators, including disconnected ones, of the demo .
172172// The returned slice is a snapshot and is not updated on changes.
173173func (ptcp Participants ) All () []* common.Player {
174+ res := make ([]* common.Player , 0 , len (ptcp .playersByUserID ))
175+ for _ , p := range ptcp .playersByUserID {
176+ res = append (res , p )
177+ }
178+ return res
179+ }
180+
181+ // Connected returns all currently connected players & spectators.
182+ // The returned slice is a snapshot and is not updated on changes.
183+ func (ptcp Participants ) Connected () []* common.Player {
174184 res , original := ptcp .initalizeSliceFromByUserID ()
175185 for _ , p := range original {
176186 res = append (res , p )
Original file line number Diff line number Diff line change @@ -134,28 +134,28 @@ func TestParticipants_FindByHandle_InvalidEntityHandle(t *testing.T) {
134134 assert .Nil (t , found )
135135}
136136
137- func TestParticipants_SuppressNoEntity (t * testing.T ) {
137+ func TestParticipants_Connected_SuppressNoEntity (t * testing.T ) {
138138 gs := newGameState ()
139139 pl := newPlayer ()
140140 gs .playersByUserID [0 ] = pl
141141 pl2 := common .NewPlayer (0 , func () int { return 0 })
142142 pl2 .IsConnected = true
143143 gs .playersByUserID [1 ] = pl2
144144
145- allPlayers := gs .Participants ().All ()
145+ allPlayers := gs .Participants ().Connected ()
146146
147147 assert .ElementsMatch (t , []* common.Player {pl }, allPlayers )
148148}
149149
150- func TestParticipants_SuppressNotConnected (t * testing.T ) {
150+ func TestParticipants_Connected_SuppressNotConnected (t * testing.T ) {
151151 gs := newGameState ()
152152 pl := newPlayer ()
153153 gs .playersByUserID [0 ] = pl
154154 pl2 := newPlayer ()
155155 pl2 .IsConnected = false
156156 gs .playersByUserID [1 ] = pl2
157157
158- allPlayers := gs .Participants ().All ()
158+ allPlayers := gs .Participants ().Connected ()
159159
160160 assert .ElementsMatch (t , []* common.Player {pl }, allPlayers )
161161}
Original file line number Diff line number Diff line change @@ -20,9 +20,12 @@ type IParticipants interface {
2020 // The returned map is a snapshot and is not updated on changes (not a reference to the actual, underlying map).
2121 // Includes spectators.
2222 ByEntityID () map [int ]* common.Player
23- // All returns all currently connected players & spectators.
23+ // All returns all currently known players & spectators, including disconnected ones, of the demo .
2424 // The returned slice is a snapshot and is not updated on changes.
2525 All () []* common.Player
26+ // Connected returns all currently connected players & spectators.
27+ // The returned slice is a snapshot and is not updated on changes.
28+ Connected () []* common.Player
2629 // Playing returns all players that aren't spectating or unassigned.
2730 // The returned slice is a snapshot and is not updated on changes.
2831 Playing () []* common.Player
You can’t perform that action at this time.
0 commit comments