Skip to content

Commit 7c65c04

Browse files
authored
Merge pull request #413 from akiver/freezetime
feat: add RoundFreezetimeChanged event
2 parents 9bc3001 + 475812e commit 7c65c04

File tree

7 files changed

+34
-0
lines changed

7 files changed

+34
-0
lines changed

pkg/demoinfocs/datatables.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,15 @@ func (p *parser) bindGameRules() {
10711071
roundTime = val.Int()
10721072
})
10731073

1074+
entity.Property(grPrefix("m_bFreezePeriod")).OnUpdate(func(val st.PropertyValue) {
1075+
newIsFreezetime := val.BoolVal()
1076+
p.eventDispatcher.Dispatch(events.RoundFreezetimeChanged{
1077+
OldIsFreezetime: p.gameState.isFreezetime,
1078+
NewIsFreezetime: newIsFreezetime,
1079+
})
1080+
p.gameState.isFreezetime = newIsFreezetime
1081+
})
1082+
10741083
entity.Property(grPrefix("m_gamePhase")).OnUpdate(func(val st.PropertyValue) {
10751084
oldGamePhase := p.gameState.gamePhase
10761085
p.gameState.gamePhase = common.GamePhase(val.Int())

pkg/demoinfocs/events/events.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ type RoundStart struct {
3838
// RoundFreezetimeEnd signals that the freeze time is over.
3939
type RoundFreezetimeEnd struct{}
4040

41+
// RoundFreezetimeChanged signals that the freeze time period has changed.
42+
type RoundFreezetimeChanged struct {
43+
OldIsFreezetime bool
44+
NewIsFreezetime bool
45+
}
46+
4147
// RoundEndReason is the type for the various RoundEndReasonXYZ constants.
4248
//
4349
// See RoundEnd.

pkg/demoinfocs/fake/game_state.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func (gs *GameState) IsWarmupPeriod() bool {
8585
return gs.Called().Bool(0)
8686
}
8787

88+
// IsFreezetimePeriod is a mock-implementation of GameState.IsFreezetimePeriod().
89+
func (gs *GameState) IsFreezetimePeriod() bool {
90+
return gs.Called().Bool(0)
91+
}
92+
8893
// IsMatchStarted is a mock-implementation of GameState.IsMatchStarted().
8994
func (gs *GameState) IsMatchStarted() bool {
9095
return gs.Called().Bool(0)

pkg/demoinfocs/game_state.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type gameState struct {
3333
totalRoundsPlayed int
3434
gamePhase common.GamePhase
3535
isWarmupPeriod bool
36+
isFreezetime bool
3637
isMatchStarted bool
3738
overtimeCount int
3839
lastFlash lastFlash // Information about the last flash that exploded, used to find the attacker and projectile for player_blind events
@@ -192,6 +193,11 @@ func (gs gameState) IsWarmupPeriod() bool {
192193
return gs.isWarmupPeriod
193194
}
194195

196+
// IsFreezetimePeriod returns whether the game is currently in freezetime period according to CCSGameRulesProxy.
197+
func (gs gameState) IsFreezetimePeriod() bool {
198+
return gs.isFreezetime
199+
}
200+
195201
// IsMatchStarted returns whether the match has started according to CCSGameRulesProxy.
196202
func (gs gameState) IsMatchStarted() bool {
197203
return gs.isMatchStarted

pkg/demoinfocs/game_state_interface.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ type GameState interface {
5555
GamePhase() common.GamePhase
5656
// IsWarmupPeriod returns whether the game is currently in warmup period according to CCSGameRulesProxy.
5757
IsWarmupPeriod() bool
58+
// IsFreezetimePeriod returns whether the game is currently in freezetime period according to CCSGameRulesProxy.
59+
IsFreezetimePeriod() bool
5860
// IsMatchStarted returns whether the match has started according to CCSGameRulesProxy.
5961
IsMatchStarted() bool
6062
// OvertimeCount returns the number of overtime according to CCSGameRulesProxy.

pkg/demoinfocs/game_state_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,12 @@ func TestGameRules(t *testing.T) {
353353
assert.Equal(t, ErrFailedToRetrieveGameRule, err)
354354
}
355355

356+
func TestGameRules_IsFreezetimePeriod(t *testing.T) {
357+
gs := gameState{isFreezetime: true}
358+
359+
assert.Equal(t, true, gs.IsFreezetimePeriod())
360+
}
361+
356362
func newPlayerS1() *common.Player {
357363
pl := newPlayerWithEntityIDS1(1)
358364
return pl

test/default.golden

1.12 KB
Binary file not shown.

0 commit comments

Comments
 (0)