Skip to content

Commit 78d6704

Browse files
committed
implement Stringer interface for Player and Equipment
1 parent 686ed74 commit 78d6704

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func main() {
6464
if e.PenetratedObjects > 0 {
6565
wallBang = " (WB)"
6666
}
67-
fmt.Printf("%s <%v%s%s> %s\n", e.Killer.Name, e.Weapon.Weapon, hs, wallBang, e.Victim.Name)
67+
fmt.Printf("%s <%v%s%s> %s\n", e.Killer, e.Weapon, hs, wallBang, e.Victim)
6868
})
6969

7070
// Parse to end

common/equipment.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,12 @@ type Equipment struct {
282282
uniqueID int64
283283
}
284284

285+
// String returns a human readable name for the equipment.
286+
// E.g. 'AK-47', 'UMP-45', 'Smoke Grenade' etc.
287+
func (e Equipment) String() string {
288+
return e.Weapon.String()
289+
}
290+
285291
// Class returns the class of the equipment.
286292
// E.g. pistol, smg, heavy etc.
287293
func (e Equipment) Class() EquipmentClass {

common/player.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ type Player struct {
4444
HasHelmet bool
4545
}
4646

47+
// String returns the player's name.
48+
// Implements fmt.Stringer.
49+
func (p *Player) String() string {
50+
if p == nil {
51+
return "(nil)"
52+
}
53+
54+
return p.Name
55+
}
56+
4757
// IsAlive returns true if the Hp of the player are > 0.
4858
func (p *Player) IsAlive() bool {
4959
return p.Hp > 0

examples_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
/*
1313
This will print all kills of a demo in the format '[[killer]] <[[weapon]] [(HS)] [(WB)]> [[victim]]'
1414
*/
15+
//noinspection GoUnhandledErrorResult
1516
func ExampleParser() {
1617
f, err := os.Open("test/cs-demos/default.dem")
1718
if err != nil {
@@ -31,7 +32,7 @@ func ExampleParser() {
3132
if e.PenetratedObjects > 0 {
3233
wallBang = " (WB)"
3334
}
34-
fmt.Printf("%s <%v%s%s> %s\n", e.Killer.Name, e.Weapon.Weapon, hs, wallBang, e.Victim.Name)
35+
fmt.Printf("%s <%v%s%s> %s\n", e.Killer, e.Weapon, hs, wallBang, e.Victim)
3536
})
3637

3738
// Parse to end

0 commit comments

Comments
 (0)