Skip to content

Commit 3b47622

Browse files
add color function for common.Player (#250)
see #248 Co-authored-by: Markus <m.walther97@gmail.com>
1 parent f795d03 commit 3b47622

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

pkg/demoinfocs/common/common.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,33 @@ func ConvertSteamID32To64(steamID32 uint32) uint64 {
239239
func ConvertSteamID64To32(steamID64 uint64) uint32 {
240240
return uint32(steamID64 - steamID64IndividualIdentifier)
241241
}
242+
243+
// Color is the type for the various colors constants.
244+
type Color int
245+
246+
// Color constants give information about which color a player has.
247+
const (
248+
Grey Color = iota - 1
249+
Yellow
250+
Purple
251+
Green
252+
Blue
253+
Orange
254+
)
255+
256+
var strColors = map[Color]string{
257+
Grey: "Grey",
258+
Yellow: "Yellow",
259+
Purple: "Purple",
260+
Green: "Green",
261+
Blue: "Blue",
262+
Orange: "Orange",
263+
}
264+
265+
func (c Color) String() string {
266+
if _, exists := strColors[c]; !exists {
267+
return "Unknown-Color"
268+
}
269+
270+
return strColors[c]
271+
}

pkg/demoinfocs/common/player.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ func (p *Player) Score() int {
376376
return getInt(p.ResourceEntity(), "m_iScore."+p.entityIDStr())
377377
}
378378

379+
// Color returns the players color as shown on the match.
380+
func (p *Player) Color() Color {
381+
return Color(getInt(p.ResourceEntity(), "m_iCompTeammateColor."+p.entityIDStr()))
382+
}
383+
379384
// Kills returns the amount of kills the player has as shown on the scoreboard.
380385
func (p *Player) Kills() int {
381386
return getInt(p.ResourceEntity(), "m_iKills."+p.entityIDStr())

pkg/demoinfocs/common/player_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,12 @@ func TestPlayer_Score(t *testing.T) {
389389
assert.Equal(t, 10, pl.Score())
390390
}
391391

392+
func TestPlayer_Color(t *testing.T) {
393+
pl := playerWithResourceProperty("m_iCompTeammateColor", st.PropertyValue{IntVal: int(Yellow)})
394+
395+
assert.Equal(t, Yellow, pl.Color())
396+
}
397+
392398
func TestPlayer_Kills(t *testing.T) {
393399
pl := playerWithResourceProperty("m_iKills", st.PropertyValue{IntVal: 5})
394400

0 commit comments

Comments
 (0)