Skip to content

Commit 39d42b1

Browse files
committed
common: add helper methods to Player around ducking
1 parent 0b5a3f0 commit 39d42b1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

pkg/demoinfocs/common/player.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,30 @@ func (p *Player) IsScoped() bool {
186186
return getBool(p.Entity, "m_bIsScoped")
187187
}
188188

189-
// IsDucking returns true if the player is currently crouching.
189+
// IsDucking returns true if the player is currently fully crouching.
190190
// See also: Flags().Ducking() & Flags().DuckingKeyPressed()
191191
func (p *Player) IsDucking() bool {
192192
return p.Flags().Ducking() && p.Flags().DuckingKeyPressed()
193193
}
194194

195+
// IsDuckingInProgress returns true if the player is currently in the progress of going from standing to crouched.
196+
// See also: Flags().Ducking() & Flags().DuckingKeyPressed()
197+
func (p *Player) IsDuckingInProgress() bool {
198+
return !p.Flags().Ducking() && p.Flags().DuckingKeyPressed()
199+
}
200+
201+
// IsUnDuckingInProgress returns true if the player is currently in the progress of going from crouched to standing.
202+
// See also: Flags().Ducking() & Flags().DuckingKeyPressed()
203+
func (p *Player) IsUnDuckingInProgress() bool {
204+
return p.Flags().Ducking() && !p.Flags().DuckingKeyPressed()
205+
}
206+
207+
// IsStaning returns true if the player is currently fully standing upright.
208+
// See also: Flags().Ducking() & Flags().DuckingKeyPressed()
209+
func (p *Player) IsStanding() bool {
210+
return !p.Flags().Ducking() && !p.Flags().DuckingKeyPressed()
211+
}
212+
195213
// HasDefuseKit returns true if the player currently has a defuse kit in his inventory.
196214
func (p *Player) HasDefuseKit() bool {
197215
return getBool(p.Entity, "m_bHasDefuser")

pkg/demoinfocs/common/player_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,30 @@ func TestPlayer_IsDucking(t *testing.T) {
212212
pl := playerWithProperty("m_fFlags", st.PropertyValue{IntVal: 0})
213213

214214
assert.False(t, pl.IsDucking())
215+
assert.True(t, pl.IsStanding())
216+
assert.False(t, pl.IsDuckingInProgress())
217+
assert.False(t, pl.IsUnDuckingInProgress())
215218

216219
pl = playerWithProperty("m_fFlags", st.PropertyValue{IntVal: 1 << 1})
217220

218221
assert.False(t, pl.IsDucking())
222+
assert.False(t, pl.IsStanding())
223+
assert.False(t, pl.IsDuckingInProgress())
224+
assert.True(t, pl.IsUnDuckingInProgress())
219225

220226
pl = playerWithProperty("m_fFlags", st.PropertyValue{IntVal: 1 << 2})
221227

222228
assert.False(t, pl.IsDucking())
229+
assert.False(t, pl.IsStanding())
230+
assert.True(t, pl.IsDuckingInProgress())
231+
assert.False(t, pl.IsUnDuckingInProgress())
223232

224233
pl = playerWithProperty("m_fFlags", st.PropertyValue{IntVal: 1<<1 | 1<<2})
225234

226235
assert.True(t, pl.IsDucking())
236+
assert.False(t, pl.IsStanding())
237+
assert.False(t, pl.IsDuckingInProgress())
238+
assert.False(t, pl.IsUnDuckingInProgress())
227239
}
228240

229241
func TestPlayerFlags_OnGround(t *testing.T) {

0 commit comments

Comments
 (0)