Repository: markus-wa/demoinfocs-golang
Pull request #212 (2020-05-17 11:10:45)

common: expose CCSPlayerResource via Player.ResourceEntity()

codecov[bot]: # [Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/212?src=pr&el=h1) Report
> Merging [#212](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/212?src=pr&el=desc) into [master](https://codecov.io/gh/markus-wa/demoinfocs-golang/commit/f2b59fb3da177e0981274f05b86ff5ab9037c6ed&el=desc) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/212/graphs/tree.svg?width=650&height=150&src=pr&token=20emCaZRHz)](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/212?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #212   +/-   ##
=======================================
  Coverage   92.45%   92.45%           
=======================================
  Files          29       29           
  Lines        2796     2798    +2     
=======================================
+ Hits         2585     2587    +2     
  Misses        155      155           
  Partials       56       56           
```


| [Impacted Files](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/212?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pkg/demoinfocs/common/player.go](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/212/diff?src=pr&el=tree#diff-cGtnL2RlbW9pbmZvY3MvY29tbW9uL3BsYXllci5nbw==) | `98.42% <100.00%> (+0.02%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/212?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/212?src=pr&el=footer). Last update [f2b59fb...d472907](https://codecov.io/gh/markus-wa/demoinfocs-golang/pull/212?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/pkg/demoinfocs/common/player.go b/pkg/demoinfocs/common/player.go
index 9c1c7ee..dda7aed 100644
--- a/pkg/demoinfocs/common/player.go
+++ b/pkg/demoinfocs/common/player.go
@@ -292,49 +292,54 @@ func (p *Player) entityIDStr() string {
 	return fmt.Sprintf("%03d", p.EntityID)
 }
 
+// ResourceEntity returns the player's CCSPlayerResource entity.
+func (p *Player) ResourceEntity() st.Entity {
+	return p.demoInfoProvider.PlayerResourceEntity()
+}
+
 // ClanTag returns the player's individual clan tag (Steam Groups etc.).
 func (p *Player) ClanTag() string {
-	return getString(p.demoInfoProvider.PlayerResourceEntity(), "m_szClan."+p.entityIDStr())
+	return getString(p.ResourceEntity(), "m_szClan."+p.entityIDStr())
 }
 
 // Ping returns the players latency to the game server.
 func (p *Player) Ping() int {
-	return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iPing."+p.entityIDStr())
+	return getInt(p.ResourceEntity(), "m_iPing."+p.entityIDStr())
 }
 
 // Score returns the players score as shown on the scoreboard.
 func (p *Player) Score() int {
-	return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iScore."+p.entityIDStr())
+	return getInt(p.ResourceEntity(), "m_iScore."+p.entityIDStr())
 }
 
 // Kills returns the amount of kills the player has as shown on the scoreboard.
 func (p *Player) Kills() int {
-	return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iKills."+p.entityIDStr())
+	return getInt(p.ResourceEntity(), "m_iKills."+p.entityIDStr())
 }
 
 // Deaths returns the amount of deaths the player has as shown on the scoreboard.
 func (p *Player) Deaths() int {
-	return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iDeaths."+p.entityIDStr())
+	return getInt(p.ResourceEntity(), "m_iDeaths."+p.entityIDStr())
 }
 
 // Assists returns the amount of assists the player has as shown on the scoreboard.
 func (p *Player) Assists() int {
-	return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iAssists."+p.entityIDStr())
+	return getInt(p.ResourceEntity(), "m_iAssists."+p.entityIDStr())
 }
 
 // MVPs returns the amount of Most-Valuable-Player awards the player has as shown on the scoreboard.
 func (p *Player) MVPs() int {
-	return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iMVPs."+p.entityIDStr())
+	return getInt(p.ResourceEntity(), "m_iMVPs."+p.entityIDStr())
 }
 
 // MoneySpentTotal returns the total amount of money the player has spent in the current match.
 func (p *Player) MoneySpentTotal() int {
-	return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iTotalCashSpent."+p.entityIDStr())
+	return getInt(p.ResourceEntity(), "m_iTotalCashSpent."+p.entityIDStr())
 }
 
 // MoneySpentThisRound returns the amount of money the player has spent in the current round.
 func (p *Player) MoneySpentThisRound() int {
-	return getInt(p.demoInfoProvider.PlayerResourceEntity(), "m_iCashSpentThisRound."+p.entityIDStr())
+	return getInt(p.ResourceEntity(), "m_iCashSpentThisRound."+p.entityIDStr())
 }
 
 type demoInfoProvider interface {


Test patch:
diff --git a/pkg/demoinfocs/common/player_test.go b/pkg/demoinfocs/common/player_test.go
index 2adab01..9a41861 100644
--- a/pkg/demoinfocs/common/player_test.go
+++ b/pkg/demoinfocs/common/player_test.go
@@ -383,6 +383,17 @@ func TestPlayer_MVPs(t *testing.T) {
 	assert.Equal(t, 4, pl.MVPs())
 }
 
+func TestPlayer_ResourceEntity(t *testing.T) {
+	resourceEntity := entityWithID(1)
+	pl := &Player{
+		demoInfoProvider: demoInfoProviderMock{
+			playerResourceEntity: resourceEntity,
+		},
+	}
+
+	assert.Same(t, resourceEntity, pl.ResourceEntity())
+}
+
 func TestPlayer_SteamID32(t *testing.T) {
 	pl := &Player{SteamID64: 76561198012952267}