Skip to content

Commit fe49f0b

Browse files
authored
events: Clean up naming (fixes #45)
- Remove stuttery 'Event' suffixes - Improve grouping when lexographically ordered - Use more appropriate tenses PR #46
1 parent 5cd809a commit fe49f0b

File tree

15 files changed

+239
-236
lines changed

15 files changed

+239
-236
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ You can use gitter to ask questions and discuss ideas about this project.
2020

2121
## Example
2222

23-
This is a simple example on how to use the library. It collects all positions where weapons were fired from (using `events.WeaponFiredEvent`) and creates a heatmap using [go-heatmap](https://github.com/dustin/go-heatmap).
23+
This is a simple example on how to use the library. It collects all positions where weapons were fired from (using `events.WeaponFire`) and creates a heatmap using [go-heatmap](https://github.com/dustin/go-heatmap).
2424

2525
Check out the [examples](examples) folder for more examples and the [godoc of the `events` package](https://godoc.org/github.com/markus-wa/demoinfocs-golang/events) for some information about the other available events and their purpose.
2626

@@ -58,10 +58,10 @@ func main() {
5858
// Get metadata for the map that's being played
5959
m := metadata.MapNameToMap[header.MapName]
6060

61-
// Register handler for WeaponFiredEvent, triggered every time a shot is fired
61+
// Register handler for WeaponFire, triggered every time a shot is fired
6262
points := []heatmap.DataPoint{}
6363
var bounds image.Rectangle
64-
p.RegisterEventHandler(func(e events.WeaponFiredEvent) {
64+
p.RegisterEventHandler(func(e events.WeaponFire) {
6565
// Translate positions from in-game coordinates to radar overview
6666
x, y := m.TranslateScale(e.Shooter.Position.X, e.Shooter.Position.Y)
6767

@@ -139,7 +139,7 @@ Running the above code (`go run heatmap.go > heatmap.png`) will create a JPEG of
139139
* Grenade projectiles / trajectories - [docs](https://godoc.org/github.com/markus-wa/demoinfocs-golang#GameState.GrenadeProjectiles) / [example](https://github.com/markus-wa/demoinfocs-golang/tree/master/examples/nade-trajectories)
140140
* Access to entities, server-classes & data-tables - [docs](https://godoc.org/github.com/markus-wa/demoinfocs-golang/sendtables#ServerClasses) / [example](https://github.com/markus-wa/demoinfocs-golang/tree/master/examples/entities)
141141
* Access to all net-messages - [docs](https://godoc.org/github.com/markus-wa/demoinfocs-golang#NetMessageCreator) / [example](https://github.com/markus-wa/demoinfocs-golang/tree/master/examples/net-messages)
142-
* Chat & console messages <sup id="achat1">1</sup> - [docs](https://godoc.org/github.com/markus-wa/demoinfocs-golang/events#ChatMessageEvent) / [example](https://github.com/markus-wa/demoinfocs-golang/tree/master/examples/print-events)
142+
* Chat & console messages <sup id="achat1">1</sup> - [docs](https://godoc.org/github.com/markus-wa/demoinfocs-golang/events#ChatMessage) / [example](https://github.com/markus-wa/demoinfocs-golang/tree/master/examples/print-events)
143143
* [Easy debugging via build-flags](#debugging)
144144
* Built with performance & concurrency in mind
145145

datatables.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func (p *Parser) bindGrenadeProjectiles(entity *st.Entity) {
308308
p.gameState.grenadeProjectiles[entityID] = proj
309309

310310
entity.OnCreateFinished(func() {
311-
p.eventDispatcher.Dispatch(events.NadeProjectileThrownEvent{
311+
p.eventDispatcher.Dispatch(events.GrenadeProjectileThrow{
312312
Projectile: proj,
313313
})
314314
})
@@ -342,7 +342,7 @@ func (p *Parser) bindGrenadeProjectiles(entity *st.Entity) {
342342
if bounceProp != nil {
343343
bounceProp.OnUpdate(func(val st.PropertyValue) {
344344
if val.IntVal != 0 {
345-
p.eventDispatcher.Dispatch(events.NadeProjectileBouncedEvent{
345+
p.eventDispatcher.Dispatch(events.GrenadeProjectileBounce{
346346
Projectile: proj,
347347
BounceNr: val.IntVal,
348348
})
@@ -359,7 +359,7 @@ func (p *Parser) nadeProjectileDestroyed(proj *common.GrenadeProjectile) {
359359
return
360360
}
361361

362-
p.eventDispatcher.Dispatch(events.NadeProjectileDestroyedEvent{
362+
p.eventDispatcher.Dispatch(events.GrenadeProjectileDestroy{
363363
Projectile: proj,
364364
})
365365

@@ -412,7 +412,7 @@ func (p *Parser) bindNewInferno(entity *st.Entity) {
412412
p.gameState.infernos[entityID] = inf
413413

414414
entity.OnCreateFinished(func() {
415-
p.eventDispatcher.Dispatch(events.InfernoStartedEvent{
415+
p.eventDispatcher.Dispatch(events.InfernoStart{
416416
Inferno: inf,
417417
})
418418
})
@@ -449,7 +449,7 @@ func (p *Parser) infernoExpired(inf *common.Inferno) {
449449
return
450450
}
451451

452-
p.eventDispatcher.Dispatch(events.InfernoExpiredEvent{
452+
p.eventDispatcher.Dispatch(events.InfernoExpired{
453453
Inferno: inf,
454454
})
455455

demoinfocs_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestDemoInfoCs(t *testing.T) {
6767

6868
fmt.Println("Registering handlers")
6969
gs := p.GameState()
70-
p.RegisterEventHandler(func(e events.RoundEndedEvent) {
70+
p.RegisterEventHandler(func(e events.RoundEnd) {
7171
var winner *dem.TeamState
7272
var loser *dem.TeamState
7373
var winnerSide string
@@ -100,7 +100,7 @@ func TestDemoInfoCs(t *testing.T) {
100100
})
101101

102102
// Check some things at match start
103-
p.RegisterEventHandler(func(events.MatchStartedEvent) {
103+
p.RegisterEventHandler(func(events.MatchStart) {
104104
participants := gs.Participants()
105105
all := participants.All()
106106
players := participants.Playing()
@@ -123,7 +123,7 @@ func TestDemoInfoCs(t *testing.T) {
123123
})
124124

125125
// Regression test for grenade projectiles not being deleted at the end of the round (issue #42)
126-
p.RegisterEventHandler(func(events.RoundStartedEvent) {
126+
p.RegisterEventHandler(func(events.RoundStart) {
127127
if nProjectiles := len(p.GameState().GrenadeProjectiles()); nProjectiles > 0 {
128128
t.Error("Expected 0 GrenadeProjectiles at the start of the round, got", nProjectiles)
129129
}
@@ -214,7 +214,7 @@ func TestValveMatchmakingFuzzyEmitters(t *testing.T) {
214214

215215
teamSwitchDone := false
216216
tScoreBeforeSwap, ctScoreBeforeSwap := -1, -1
217-
p.RegisterEventHandler(func(ev events.RoundEndedEvent) {
217+
p.RegisterEventHandler(func(ev events.RoundEnd) {
218218
switch ev.Winner {
219219
case common.TeamTerrorists:
220220
tScoreBeforeSwap = p.GameState().TeamTerrorists().Score() + 1
@@ -261,7 +261,7 @@ func TestCancelParseToEnd(t *testing.T) {
261261
var tix int
262262

263263
var handlerID dispatch.HandlerIdentifier
264-
handlerID = p.RegisterEventHandler(func(events.TickDoneEvent) {
264+
handlerID = p.RegisterEventHandler(func(events.TickDone) {
265265
tix++
266266
if tix == maxTicks {
267267
p.Cancel()

demopacket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (p *Parser) parsePacket() {
8080
} else {
8181
// Send a warning if the command is unknown
8282
// This might mean our proto files are out of date
83-
p.eventDispatcher.Dispatch(events.ParserWarnEvent{Message: fmt.Sprintf("Unknown message command %q", cmd)})
83+
p.eventDispatcher.Dispatch(events.ParserWarn{Message: fmt.Sprintf("Unknown message command %q", cmd)})
8484
}
8585

8686
// On to the next one

0 commit comments

Comments
 (0)