Skip to content

Commit 2344dc7

Browse files
committed
Replace RegisterPropertyUpdateHandler with OnUpdate
1 parent 1e7e284 commit 2344dc7

File tree

2 files changed

+37
-32
lines changed

2 files changed

+37
-32
lines changed

datatables.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,20 @@ func (p *Parser) bindTeamScores() {
7070
var flagImage string
7171
score := 0
7272

73-
event.Entity.FindProperty("m_iTeamNum").RegisterPropertyUpdateHandler(func(val st.PropValue) {
73+
event.Entity.FindProperty("m_iTeamNum").OnUpdate(func(val st.PropValue) {
7474
teamID = val.IntVal
7575
})
76-
event.Entity.FindProperty("m_szClanTeamname").RegisterPropertyUpdateHandler(func(val st.PropValue) {
76+
event.Entity.FindProperty("m_szClanTeamname").OnUpdate(func(val st.PropValue) {
7777
clanName = val.StringVal
7878
})
79-
event.Entity.FindProperty("m_szTeamFlagImage").RegisterPropertyUpdateHandler(func(val st.PropValue) {
79+
event.Entity.FindProperty("m_szTeamFlagImage").OnUpdate(func(val st.PropValue) {
8080
flagImage = val.StringVal
8181
})
82-
event.Entity.FindProperty("m_scoreTotal").RegisterPropertyUpdateHandler(func(val st.PropValue) {
82+
event.Entity.FindProperty("m_scoreTotal").OnUpdate(func(val st.PropValue) {
8383
score = val.IntVal
8484
})
8585

86-
event.Entity.FindProperty("m_szTeamname").RegisterPropertyUpdateHandler(func(val st.PropValue) {
86+
event.Entity.FindProperty("m_szTeamname").OnUpdate(func(val st.PropValue) {
8787
team := val.StringVal
8888

8989
var s *TeamState
@@ -111,13 +111,13 @@ func (p *Parser) bindTeamScores() {
111111

112112
// Register direct updates for the future
113113
// Except for teamId, it doesn't change; players swap teams instead
114-
event.Entity.FindProperty("m_szClanTeamname").RegisterPropertyUpdateHandler(func(val st.PropValue) {
114+
event.Entity.FindProperty("m_szClanTeamname").OnUpdate(func(val st.PropValue) {
115115
s.clanName = val.StringVal
116116
})
117-
event.Entity.FindProperty("m_szTeamFlagImage").RegisterPropertyUpdateHandler(func(val st.PropValue) {
117+
event.Entity.FindProperty("m_szTeamFlagImage").OnUpdate(func(val st.PropValue) {
118118
s.flag = val.StringVal
119119
})
120-
event.Entity.FindProperty("m_scoreTotal").RegisterPropertyUpdateHandler(func(val st.PropValue) {
120+
event.Entity.FindProperty("m_scoreTotal").OnUpdate(func(val st.PropValue) {
121121
s.score = val.IntVal
122122
})
123123
}
@@ -127,10 +127,10 @@ func (p *Parser) bindTeamScores() {
127127

128128
func (p *Parser) bindBombSites() {
129129
p.stParser.FindServerClassByName("CCSPlayerResource").RegisterEntityCreatedHandler(func(playerResource st.EntityCreatedEvent) {
130-
playerResource.Entity.FindProperty("m_bombsiteCenterA").RegisterPropertyUpdateHandler(func(center st.PropValue) {
130+
playerResource.Entity.FindProperty("m_bombsiteCenterA").OnUpdate(func(center st.PropValue) {
131131
p.bombsiteA.center = center.VectorVal
132132
})
133-
playerResource.Entity.FindProperty("m_bombsiteCenterB").RegisterPropertyUpdateHandler(func(center st.PropValue) {
133+
playerResource.Entity.FindProperty("m_bombsiteCenterB").OnUpdate(func(center st.PropValue) {
134134
p.bombsiteB.center = center.VectorVal
135135
})
136136
})
@@ -139,10 +139,10 @@ func (p *Parser) bindBombSites() {
139139
t := new(boundingBoxInformation)
140140
p.triggers[baseTrigger.Entity.ID] = t
141141

142-
baseTrigger.Entity.FindProperty("m_Collision.m_vecMins").RegisterPropertyUpdateHandler(func(vec st.PropValue) {
142+
baseTrigger.Entity.FindProperty("m_Collision.m_vecMins").OnUpdate(func(vec st.PropValue) {
143143
t.min = vec.VectorVal
144144
})
145-
baseTrigger.Entity.FindProperty("m_Collision.m_vecMaxs").RegisterPropertyUpdateHandler(func(vec st.PropValue) {
145+
baseTrigger.Entity.FindProperty("m_Collision.m_vecMaxs").OnUpdate(func(vec st.PropValue) {
146146
t.max = vec.VectorVal
147147
})
148148
})
@@ -158,12 +158,12 @@ func (p *Parser) bindPlayers() {
158158
i2 := i // Copy so it stays the same (for passing to handlers)
159159
iStr := fmt.Sprintf("%03d", i)
160160

161-
pr.Entity.FindProperty("m_szClan." + iStr).RegisterPropertyUpdateHandler(func(val st.PropValue) {
161+
pr.Entity.FindProperty("m_szClan." + iStr).OnUpdate(func(val st.PropValue) {
162162
p.additionalPlayerInfo[i2].ClanTag = val.StringVal
163163
})
164164

165165
setIntLazy := func(prop string, setter func(int)) {
166-
pr.Entity.FindProperty(prop).RegisterPropertyUpdateHandler(func(val st.PropValue) {
166+
pr.Entity.FindProperty(prop).OnUpdate(func(val st.PropValue) {
167167
setter(val.IntVal)
168168
})
169169
}
@@ -194,34 +194,34 @@ func (p *Parser) bindNewPlayer(playerEntity *st.Entity) {
194194
pl.EntityID = playerEntity.ID
195195
pl.Entity = playerEntity
196196

197-
playerEntity.FindProperty("cslocaldata.m_vecOrigin").RegisterPropertyUpdateHandler(func(val st.PropValue) {
197+
playerEntity.FindProperty("cslocaldata.m_vecOrigin").OnUpdate(func(val st.PropValue) {
198198
pl.Position.X = val.VectorVal.X
199199
pl.Position.Y = val.VectorVal.Y
200200
})
201201

202-
playerEntity.FindProperty("cslocaldata.m_vecOrigin[2]").RegisterPropertyUpdateHandler(func(val st.PropValue) {
202+
playerEntity.FindProperty("cslocaldata.m_vecOrigin[2]").OnUpdate(func(val st.PropValue) {
203203
pl.Position.Z = float64(val.FloatVal)
204204
})
205205

206-
playerEntity.FindProperty("m_iTeamNum").RegisterPropertyUpdateHandler(func(val st.PropValue) {
206+
playerEntity.FindProperty("m_iTeamNum").OnUpdate(func(val st.PropValue) {
207207
pl.Team = common.Team(val.IntVal)
208208
})
209209

210210
// Some helpers because I cant be arsed
211211
setIntLazy := func(prop string, setter func(int)) {
212-
playerEntity.FindProperty(prop).RegisterPropertyUpdateHandler(func(val st.PropValue) {
212+
playerEntity.FindProperty(prop).OnUpdate(func(val st.PropValue) {
213213
setter(val.IntVal)
214214
})
215215
}
216216

217217
setFloatLazy := func(prop string, setter func(float32)) {
218-
playerEntity.FindProperty(prop).RegisterPropertyUpdateHandler(func(val st.PropValue) {
218+
playerEntity.FindProperty(prop).OnUpdate(func(val st.PropValue) {
219219
setter(val.FloatVal)
220220
})
221221
}
222222

223223
setFloat64Lazy := func(prop string, setter func(float64)) {
224-
playerEntity.FindProperty(prop).RegisterPropertyUpdateHandler(func(val st.PropValue) {
224+
playerEntity.FindProperty(prop).OnUpdate(func(val st.PropValue) {
225225
setter(float64(val.FloatVal))
226226
})
227227
}
@@ -258,7 +258,7 @@ func (p *Parser) bindNewPlayer(playerEntity *st.Entity) {
258258

259259
for i := range cache {
260260
i2 := i // Copy for passing to handler
261-
playerEntity.FindProperty(wepPrefix + fmt.Sprintf("%03d", i)).RegisterPropertyUpdateHandler(func(val st.PropValue) {
261+
playerEntity.FindProperty(wepPrefix + fmt.Sprintf("%03d", i)).OnUpdate(func(val st.PropValue) {
262262
entityID := val.IntVal & indexMask
263263
if entityID != indexMask {
264264
if cache[i2] != 0 {
@@ -319,12 +319,12 @@ func (p *Parser) bindGrenadeProjectiles(event st.EntityCreatedEvent) {
319319
proj := p.gameState.grenadeProjectiles[event.Entity.ID]
320320
proj.EntityID = event.Entity.ID
321321

322-
event.Entity.FindProperty("m_nModelIndex").RegisterPropertyUpdateHandler(func(val st.PropValue) {
322+
event.Entity.FindProperty("m_nModelIndex").OnUpdate(func(val st.PropValue) {
323323
proj.Weapon = p.grenadeModelIndices[val.IntVal]
324324
})
325325

326326
// @micvbang: not quite sure what the difference between Thrower and Owner is.
327-
event.Entity.FindProperty("m_hThrower").RegisterPropertyUpdateHandler(func(val st.PropValue) {
327+
event.Entity.FindProperty("m_hThrower").OnUpdate(func(val st.PropValue) {
328328
throwerID := val.IntVal & indexMask
329329
throwerIndex := throwerID - 1
330330

@@ -336,22 +336,22 @@ func (p *Parser) bindGrenadeProjectiles(event st.EntityCreatedEvent) {
336336
}
337337
})
338338

339-
event.Entity.FindProperty("m_hOwnerEntity").RegisterPropertyUpdateHandler(func(val st.PropValue) {
339+
event.Entity.FindProperty("m_hOwnerEntity").OnUpdate(func(val st.PropValue) {
340340
ownerID := val.IntVal & indexMask
341341
ownerIndex := ownerID - 1
342342
player := p.entityIDToPlayers[ownerIndex]
343343
proj.Owner = player
344344
})
345345

346-
event.Entity.FindProperty("m_vecOrigin").RegisterPropertyUpdateHandler(func(st.PropValue) {
346+
event.Entity.FindProperty("m_vecOrigin").OnUpdate(func(st.PropValue) {
347347
proj.Position = event.Entity.Position()
348348
})
349349

350350
// Some demos don't have this property as it seems
351351
// So we need to check for nil and can't send out bounce events if it's missing
352352
bounceProp := event.Entity.FindProperty("m_nBounces")
353353
if bounceProp != nil {
354-
bounceProp.RegisterPropertyUpdateHandler(func(val st.PropValue) {
354+
bounceProp.OnUpdate(func(val st.PropValue) {
355355
if val.IntVal != 0 {
356356
p.eventDispatcher.Dispatch(events.NadeProjectileBouncedEvent{
357357
Projectile: proj,
@@ -375,16 +375,16 @@ func (p *Parser) bindWeapon(event st.EntityCreatedEvent) {
375375
eq.Weapon = p.equipmentMapping[event.ServerClass]
376376
eq.AmmoInMagazine = -1
377377

378-
event.Entity.FindProperty("m_iClip1").RegisterPropertyUpdateHandler(func(val st.PropValue) {
378+
event.Entity.FindProperty("m_iClip1").OnUpdate(func(val st.PropValue) {
379379
eq.AmmoInMagazine = val.IntVal - 1
380380
})
381381

382-
event.Entity.FindProperty("LocalWeaponData.m_iPrimaryAmmoType").RegisterPropertyUpdateHandler(func(val st.PropValue) {
382+
event.Entity.FindProperty("LocalWeaponData.m_iPrimaryAmmoType").OnUpdate(func(val st.PropValue) {
383383
eq.AmmoType = val.IntVal
384384
})
385385

386386
wepFix := func(ok string, change string, changer func()) {
387-
event.Entity.FindProperty("m_nModelIndex").RegisterPropertyUpdateHandler(func(val st.PropValue) {
387+
event.Entity.FindProperty("m_nModelIndex").OnUpdate(func(val st.PropValue) {
388388
eq.OriginalString = p.modelPreCache[val.IntVal]
389389
// Check 'change' first because otherwise the m4a1_s is recognized as m4a4
390390
if strings.Contains(eq.OriginalString, change) {

sendtables/entity.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (e *Entity) InitializeBaseline(r *bit.BitReader) map[int]PropValue {
109109
baseline[i2] = val
110110
}
111111

112-
e.props[i].RegisterPropertyUpdateHandler(adder)
112+
e.props[i].OnUpdate(adder)
113113
}
114114

115115
e.ApplyUpdate(r)
@@ -208,9 +208,14 @@ func (pe *PropertyEntry) firePropertyUpdate() {
208208
}
209209
}
210210

211-
// RegisterPropertyUpdateHandler registers a PropertyUpdateHandler.
212-
// The handler will be triggered on every FirePropertyUpdate call.
211+
// RegisterPropertyUpdateHandler registers a handler for updates of the PropertyEntry's value.
212+
// Deprecated: Use OnUpdate instead.
213213
func (pe *PropertyEntry) RegisterPropertyUpdateHandler(handler PropertyUpdateHandler) {
214+
pe.OnUpdate(handler)
215+
}
216+
217+
// OnUpdate registers a handler for updates of the PropertyEntry's value.
218+
func (pe *PropertyEntry) OnUpdate(handler PropertyUpdateHandler) {
214219
pe.updateHandlers = append(pe.updateHandlers, handler)
215220
}
216221

0 commit comments

Comments
 (0)