Skip to content

Commit 3aeb632

Browse files
committed
common: add Player.FlashDurationTime() utility
Returns the flash duration as time.Duration
1 parent 3deab79 commit 3aeb632

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

common/player.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package common
22

33
import (
4+
"time"
5+
46
r3 "github.com/golang/geo/r3"
57
st "github.com/markus-wa/demoinfocs-golang/sendtables"
68
)
@@ -45,6 +47,11 @@ func (p *Player) IsBlinded() bool {
4547
return p.FlashDuration > 0
4648
}
4749

50+
// FlashDurationTime returns the duration of the blinding effect as time.Duration instead of float32 in seconds.
51+
func (p *Player) FlashDurationTime() time.Duration {
52+
return time.Duration(float32(time.Second) * p.FlashDuration)
53+
}
54+
4855
/*
4956
Some interesting data regarding flashes.
5057

common/player_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package common
22

33
import (
44
"testing"
5+
"time"
56

67
assert "github.com/stretchr/testify/assert"
78
)
@@ -57,3 +58,13 @@ func TestPlayerFlashed(t *testing.T) {
5758
pl.FlashDuration = 2.3
5859
assert.True(t, pl.IsBlinded(), "Should be flashed")
5960
}
61+
62+
func TestPlayer_FlashDurationTime(t *testing.T) {
63+
p := NewPlayer()
64+
65+
assert.Equal(t, time.Duration(0), p.FlashDurationTime())
66+
67+
p.FlashDuration = 2.3
68+
69+
assert.Equal(t, 2300*time.Millisecond, p.FlashDurationTime())
70+
}

0 commit comments

Comments
 (0)