diff --git a/CHANGELOG.md b/CHANGELOG.md index 49eb3c89..a4d33c2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/listener/dispatch.go b/listener/dispatch.go index 6ebbee74..a493750a 100644 --- a/listener/dispatch.go +++ b/listener/dispatch.go @@ -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. diff --git a/listener/dispatch_test.go b/listener/dispatch_test.go index e04d4880..85c375e9 100644 --- a/listener/dispatch_test.go +++ b/listener/dispatch_test.go @@ -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() @@ -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) {