Skip to content

Commit 200ee23

Browse files
committed
feat: add RoundFreezetimeChanged event
1 parent 9bc3001 commit 200ee23

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-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/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

0 commit comments

Comments
 (0)