Skip to content

Commit 6df859c

Browse files
authored
common: expose CCSPlayerResource via Player.ResourceEntity() (#212)
1 parent f2b59fb commit 6df859c

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

pkg/demoinfocs/common/player.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -292,49 +292,54 @@ func (p *Player) entityIDStr() string {
292292
return fmt.Sprintf("%03d", p.EntityID)
293293
}
294294

295+
// ResourceEntity returns the player's CCSPlayerResource entity.
296+
func (p *Player) ResourceEntity() st.Entity {
297+
return p.demoInfoProvider.PlayerResourceEntity()
298+
}
299+
295300
// ClanTag returns the player's individual clan tag (Steam Groups etc.).
296301
func (p *Player) ClanTag() string {
297-
return getString(p.demoInfoProvider.PlayerResourceEntity(), "m_szClan."+p.entityIDStr())
302+
return getString(p.ResourceEntity(), "m_szClan."+p.entityIDStr())
298303
}
299304

300305
// Ping returns the players latency to the game server.
301306
func (p *Player) Ping() int {
302-
return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iPing."+p.entityIDStr())
307+
return getInt(p.ResourceEntity(), "m_iPing."+p.entityIDStr())
303308
}
304309

305310
// Score returns the players score as shown on the scoreboard.
306311
func (p *Player) Score() int {
307-
return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iScore."+p.entityIDStr())
312+
return getInt(p.ResourceEntity(), "m_iScore."+p.entityIDStr())
308313
}
309314

310315
// Kills returns the amount of kills the player has as shown on the scoreboard.
311316
func (p *Player) Kills() int {
312-
return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iKills."+p.entityIDStr())
317+
return getInt(p.ResourceEntity(), "m_iKills."+p.entityIDStr())
313318
}
314319

315320
// Deaths returns the amount of deaths the player has as shown on the scoreboard.
316321
func (p *Player) Deaths() int {
317-
return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iDeaths."+p.entityIDStr())
322+
return getInt(p.ResourceEntity(), "m_iDeaths."+p.entityIDStr())
318323
}
319324

320325
// Assists returns the amount of assists the player has as shown on the scoreboard.
321326
func (p *Player) Assists() int {
322-
return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iAssists."+p.entityIDStr())
327+
return getInt(p.ResourceEntity(), "m_iAssists."+p.entityIDStr())
323328
}
324329

325330
// MVPs returns the amount of Most-Valuable-Player awards the player has as shown on the scoreboard.
326331
func (p *Player) MVPs() int {
327-
return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iMVPs."+p.entityIDStr())
332+
return getInt(p.ResourceEntity(), "m_iMVPs."+p.entityIDStr())
328333
}
329334

330335
// MoneySpentTotal returns the total amount of money the player has spent in the current match.
331336
func (p *Player) MoneySpentTotal() int {
332-
return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iTotalCashSpent."+p.entityIDStr())
337+
return getInt(p.ResourceEntity(), "m_iTotalCashSpent."+p.entityIDStr())
333338
}
334339

335340
// MoneySpentThisRound returns the amount of money the player has spent in the current round.
336341
func (p *Player) MoneySpentThisRound() int {
337-
return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iCashSpentThisRound."+p.entityIDStr())
342+
return getInt(p.ResourceEntity(), "m_iCashSpentThisRound."+p.entityIDStr())
338343
}
339344

340345
type demoInfoProvider interface {

pkg/demoinfocs/common/player_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,17 @@ func TestPlayer_MVPs(t *testing.T) {
383383
assert.Equal(t, 4, pl.MVPs())
384384
}
385385

386+
func TestPlayer_ResourceEntity(t *testing.T) {
387+
resourceEntity := entityWithID(1)
388+
pl := &Player{
389+
demoInfoProvider: demoInfoProviderMock{
390+
playerResourceEntity: resourceEntity,
391+
},
392+
}
393+
394+
assert.Same(t, resourceEntity, pl.ResourceEntity())
395+
}
396+
386397
func TestPlayer_SteamID32(t *testing.T) {
387398
pl := &Player{SteamID64: 76561198012952267}
388399

0 commit comments

Comments
 (0)