Skip to content

Commit

Permalink
Add a test for the listener bug fixed in #424 (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 authored Aug 29, 2024
1 parent ae3d7cf commit e31be0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [[v0.13.1]](https://github.com/mlange-42/arche/compare/v0.13.0...v0.13.1)

### Bugfixes

* Fixes dispatch listener bug that did not clear component restriction (#424, [g-getsov](https://github.com/g-getsov))

## [[v0.13.0]](https://github.com/mlange-42/arche/compare/v0.12.0...v0.13.0)

### Features
Expand Down
8 changes: 4 additions & 4 deletions listener/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
//
// To make it possible for systems to add listeners, Dispatch can be added to the [ecs.World] as a resource.
type Dispatch struct {
listeners []ecs.Listener
events event.Subscription
components ecs.Mask
hasComponents bool
listeners []ecs.Listener // Sub-listeners to dispatch events to.
events event.Subscription // Subscribed event types.
components ecs.Mask // Subscribed components.
hasComponents bool // Whether there is a restriction to components.
}

// NewDispatch returns a new [Dispatch] listener with the given sub-listeners.
Expand Down
11 changes: 11 additions & 0 deletions listener/dispatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ func TestDispatch(t *testing.T) {
event.Components,
posID,
)
h3 := EventHandler{}
l3 := listener.NewCallback(
h3.Notify,
event.Entities,
)

ls := listener.NewDispatch(&l1)
ls.AddListener(&l2)
world.SetListener(&ls)

assert.Equal(t, event.Entities|event.Components, ls.Subscriptions())
assert.NotNil(t, ls.Components())

world.NewEntity(posID, velID)
e := world.NewEntity()
Expand All @@ -55,6 +61,11 @@ func TestDispatch(t *testing.T) {

assert.Equal(t, 1, len(h1.events))
assert.Equal(t, 2, len(h2.events))

ls.AddListener(&l3)

assert.Equal(t, event.Entities|event.Components, ls.Subscriptions())
assert.Nil(t, ls.Components())
}

func TestDispatchRelations(t *testing.T) {
Expand Down

0 comments on commit e31be0a

Please sign in to comment.