Skip to content

Commit 9470913

Browse files
committed
Add MixedEventComponent
1 parent 81e2ece commit 9470913

12 files changed

+419
-44
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by Entitas.CodeGeneration.Plugins.EventListenerComponentGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
[Entitas.CodeGeneration.Attributes.DontGenerate(false)]
10+
public sealed class AnyMixedEventListenerComponent : Entitas.IComponent {
11+
public System.Collections.Generic.List<IAnyMixedEventListener> value;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by Entitas.CodeGeneration.Plugins.EventListenerComponentGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
[Entitas.CodeGeneration.Attributes.DontGenerate(false)]
10+
public sealed class MixedEventListenerComponent : Entitas.IComponent {
11+
public System.Collections.Generic.List<IMixedEventListener> value;
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by Entitas.CodeGeneration.Plugins.EventListenertInterfaceGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
public interface IAnyMixedEventListener {
10+
void OnAnyMixedEvent(TestEntity entity, string value);
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by Entitas.CodeGeneration.Plugins.EventListenertInterfaceGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
public interface IMixedEventListener {
10+
void OnMixedEvent(TestEntity entity, string value);
11+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by Entitas.CodeGeneration.Plugins.EventSystemGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
public sealed class AnyMixedEventEventSystem : Entitas.ReactiveSystem<TestEntity> {
10+
11+
readonly Entitas.IGroup<TestEntity> _listeners;
12+
readonly System.Collections.Generic.List<TestEntity> _entityBuffer;
13+
readonly System.Collections.Generic.List<IAnyMixedEventListener> _listenerBuffer;
14+
15+
public AnyMixedEventEventSystem(Contexts contexts) : base(contexts.test) {
16+
_listeners = contexts.test.GetGroup(TestMatcher.AnyMixedEventListener);
17+
_entityBuffer = new System.Collections.Generic.List<TestEntity>();
18+
_listenerBuffer = new System.Collections.Generic.List<IAnyMixedEventListener>();
19+
}
20+
21+
protected override Entitas.ICollector<TestEntity> GetTrigger(Entitas.IContext<TestEntity> context) {
22+
return Entitas.CollectorContextExtension.CreateCollector(
23+
context, Entitas.TriggerOnEventMatcherExtension.Added(TestMatcher.MixedEvent)
24+
);
25+
}
26+
27+
protected override bool Filter(TestEntity entity) {
28+
return entity.hasMixedEvent;
29+
}
30+
31+
protected override void Execute(System.Collections.Generic.List<TestEntity> entities) {
32+
foreach (var e in entities) {
33+
var component = e.mixedEvent;
34+
foreach (var listenerEntity in _listeners.GetEntities(_entityBuffer)) {
35+
_listenerBuffer.Clear();
36+
_listenerBuffer.AddRange(listenerEntity.anyMixedEventListener.value);
37+
foreach (var listener in _listenerBuffer) {
38+
listener.OnAnyMixedEvent(e, component.value);
39+
}
40+
}
41+
}
42+
}
43+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by Entitas.CodeGeneration.Plugins.EventSystemGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
public sealed class MixedEventEventSystem : Entitas.ReactiveSystem<TestEntity> {
10+
11+
readonly System.Collections.Generic.List<IMixedEventListener> _listenerBuffer;
12+
13+
public MixedEventEventSystem(Contexts contexts) : base(contexts.test) {
14+
_listenerBuffer = new System.Collections.Generic.List<IMixedEventListener>();
15+
}
16+
17+
protected override Entitas.ICollector<TestEntity> GetTrigger(Entitas.IContext<TestEntity> context) {
18+
return Entitas.CollectorContextExtension.CreateCollector(
19+
context, Entitas.TriggerOnEventMatcherExtension.Added(TestMatcher.MixedEvent)
20+
);
21+
}
22+
23+
protected override bool Filter(TestEntity entity) {
24+
return entity.hasMixedEvent && entity.hasMixedEventListener;
25+
}
26+
27+
protected override void Execute(System.Collections.Generic.List<TestEntity> entities) {
28+
foreach (var e in entities) {
29+
var component = e.mixedEvent;
30+
_listenerBuffer.Clear();
31+
_listenerBuffer.AddRange(e.mixedEventListener.value);
32+
foreach (var listener in _listenerBuffer) {
33+
listener.OnMixedEvent(e, component.value);
34+
}
35+
}
36+
}
37+
}

Tests/TestFixtures/Generated/Events/TestEventSystems.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public TestEventSystems(Contexts contexts) {
1212
Add(new AnyBaseEventSystem(contexts)); // priority: 0
1313
Add(new TestAnyEventToGenerateEventSystem(contexts)); // priority: 0
1414
Add(new AnyFlagEventRemovedEventSystem(contexts)); // priority: 0
15+
Add(new AnyMixedEventEventSystem(contexts)); // priority: 0
16+
Add(new MixedEventEventSystem(contexts)); // priority: 0
1517
Add(new TestAnyMultipleContextStandardEventEventSystem(contexts)); // priority: 0
1618
Add(new AnyStandardEventEventSystem(contexts)); // priority: 0
1719
Add(new AnyUniqueEventEventSystem(contexts)); // priority: 0
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by Entitas.CodeGeneration.Plugins.ComponentEntityApiGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
public partial class TestEntity {
10+
11+
public AnyMixedEventListenerComponent anyMixedEventListener { get { return (AnyMixedEventListenerComponent)GetComponent(TestComponentsLookup.AnyMixedEventListener); } }
12+
public bool hasAnyMixedEventListener { get { return HasComponent(TestComponentsLookup.AnyMixedEventListener); } }
13+
14+
public void AddAnyMixedEventListener(System.Collections.Generic.List<IAnyMixedEventListener> newValue) {
15+
var index = TestComponentsLookup.AnyMixedEventListener;
16+
var component = (AnyMixedEventListenerComponent)CreateComponent(index, typeof(AnyMixedEventListenerComponent));
17+
component.value = newValue;
18+
AddComponent(index, component);
19+
}
20+
21+
public void ReplaceAnyMixedEventListener(System.Collections.Generic.List<IAnyMixedEventListener> newValue) {
22+
var index = TestComponentsLookup.AnyMixedEventListener;
23+
var component = (AnyMixedEventListenerComponent)CreateComponent(index, typeof(AnyMixedEventListenerComponent));
24+
component.value = newValue;
25+
ReplaceComponent(index, component);
26+
}
27+
28+
public void RemoveAnyMixedEventListener() {
29+
RemoveComponent(TestComponentsLookup.AnyMixedEventListener);
30+
}
31+
}
32+
33+
//------------------------------------------------------------------------------
34+
// <auto-generated>
35+
// This code was generated by Entitas.CodeGeneration.Plugins.ComponentMatcherApiGenerator.
36+
//
37+
// Changes to this file may cause incorrect behavior and will be lost if
38+
// the code is regenerated.
39+
// </auto-generated>
40+
//------------------------------------------------------------------------------
41+
public sealed partial class TestMatcher {
42+
43+
static Entitas.IMatcher<TestEntity> _matcherAnyMixedEventListener;
44+
45+
public static Entitas.IMatcher<TestEntity> AnyMixedEventListener {
46+
get {
47+
if (_matcherAnyMixedEventListener == null) {
48+
var matcher = (Entitas.Matcher<TestEntity>)Entitas.Matcher<TestEntity>.AllOf(TestComponentsLookup.AnyMixedEventListener);
49+
matcher.componentNames = TestComponentsLookup.componentNames;
50+
_matcherAnyMixedEventListener = matcher;
51+
}
52+
53+
return _matcherAnyMixedEventListener;
54+
}
55+
}
56+
}
57+
58+
//------------------------------------------------------------------------------
59+
// <auto-generated>
60+
// This code was generated by Entitas.CodeGeneration.Plugins.EventEntityApiGenerator.
61+
//
62+
// Changes to this file may cause incorrect behavior and will be lost if
63+
// the code is regenerated.
64+
// </auto-generated>
65+
//------------------------------------------------------------------------------
66+
public partial class TestEntity {
67+
68+
public void AddAnyMixedEventListener(IAnyMixedEventListener value) {
69+
var listeners = hasAnyMixedEventListener
70+
? anyMixedEventListener.value
71+
: new System.Collections.Generic.List<IAnyMixedEventListener>();
72+
listeners.Add(value);
73+
ReplaceAnyMixedEventListener(listeners);
74+
}
75+
76+
public void RemoveAnyMixedEventListener(IAnyMixedEventListener value, bool removeComponentWhenEmpty = true) {
77+
var listeners = anyMixedEventListener.value;
78+
listeners.Remove(value);
79+
if (removeComponentWhenEmpty && listeners.Count == 0) {
80+
RemoveAnyMixedEventListener();
81+
} else {
82+
ReplaceAnyMixedEventListener(listeners);
83+
}
84+
}
85+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by Entitas.CodeGeneration.Plugins.ComponentEntityApiGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
public partial class TestEntity {
10+
11+
public MixedEventComponent mixedEvent { get { return (MixedEventComponent)GetComponent(TestComponentsLookup.MixedEvent); } }
12+
public bool hasMixedEvent { get { return HasComponent(TestComponentsLookup.MixedEvent); } }
13+
14+
public void AddMixedEvent(string newValue) {
15+
var index = TestComponentsLookup.MixedEvent;
16+
var component = (MixedEventComponent)CreateComponent(index, typeof(MixedEventComponent));
17+
component.value = newValue;
18+
AddComponent(index, component);
19+
}
20+
21+
public void ReplaceMixedEvent(string newValue) {
22+
var index = TestComponentsLookup.MixedEvent;
23+
var component = (MixedEventComponent)CreateComponent(index, typeof(MixedEventComponent));
24+
component.value = newValue;
25+
ReplaceComponent(index, component);
26+
}
27+
28+
public void RemoveMixedEvent() {
29+
RemoveComponent(TestComponentsLookup.MixedEvent);
30+
}
31+
}
32+
33+
//------------------------------------------------------------------------------
34+
// <auto-generated>
35+
// This code was generated by Entitas.CodeGeneration.Plugins.ComponentMatcherApiGenerator.
36+
//
37+
// Changes to this file may cause incorrect behavior and will be lost if
38+
// the code is regenerated.
39+
// </auto-generated>
40+
//------------------------------------------------------------------------------
41+
public sealed partial class TestMatcher {
42+
43+
static Entitas.IMatcher<TestEntity> _matcherMixedEvent;
44+
45+
public static Entitas.IMatcher<TestEntity> MixedEvent {
46+
get {
47+
if (_matcherMixedEvent == null) {
48+
var matcher = (Entitas.Matcher<TestEntity>)Entitas.Matcher<TestEntity>.AllOf(TestComponentsLookup.MixedEvent);
49+
matcher.componentNames = TestComponentsLookup.componentNames;
50+
_matcherMixedEvent = matcher;
51+
}
52+
53+
return _matcherMixedEvent;
54+
}
55+
}
56+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by Entitas.CodeGeneration.Plugins.ComponentEntityApiGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
public partial class TestEntity {
10+
11+
public MixedEventListenerComponent mixedEventListener { get { return (MixedEventListenerComponent)GetComponent(TestComponentsLookup.MixedEventListener); } }
12+
public bool hasMixedEventListener { get { return HasComponent(TestComponentsLookup.MixedEventListener); } }
13+
14+
public void AddMixedEventListener(System.Collections.Generic.List<IMixedEventListener> newValue) {
15+
var index = TestComponentsLookup.MixedEventListener;
16+
var component = (MixedEventListenerComponent)CreateComponent(index, typeof(MixedEventListenerComponent));
17+
component.value = newValue;
18+
AddComponent(index, component);
19+
}
20+
21+
public void ReplaceMixedEventListener(System.Collections.Generic.List<IMixedEventListener> newValue) {
22+
var index = TestComponentsLookup.MixedEventListener;
23+
var component = (MixedEventListenerComponent)CreateComponent(index, typeof(MixedEventListenerComponent));
24+
component.value = newValue;
25+
ReplaceComponent(index, component);
26+
}
27+
28+
public void RemoveMixedEventListener() {
29+
RemoveComponent(TestComponentsLookup.MixedEventListener);
30+
}
31+
}
32+
33+
//------------------------------------------------------------------------------
34+
// <auto-generated>
35+
// This code was generated by Entitas.CodeGeneration.Plugins.ComponentMatcherApiGenerator.
36+
//
37+
// Changes to this file may cause incorrect behavior and will be lost if
38+
// the code is regenerated.
39+
// </auto-generated>
40+
//------------------------------------------------------------------------------
41+
public sealed partial class TestMatcher {
42+
43+
static Entitas.IMatcher<TestEntity> _matcherMixedEventListener;
44+
45+
public static Entitas.IMatcher<TestEntity> MixedEventListener {
46+
get {
47+
if (_matcherMixedEventListener == null) {
48+
var matcher = (Entitas.Matcher<TestEntity>)Entitas.Matcher<TestEntity>.AllOf(TestComponentsLookup.MixedEventListener);
49+
matcher.componentNames = TestComponentsLookup.componentNames;
50+
_matcherMixedEventListener = matcher;
51+
}
52+
53+
return _matcherMixedEventListener;
54+
}
55+
}
56+
}
57+
58+
//------------------------------------------------------------------------------
59+
// <auto-generated>
60+
// This code was generated by Entitas.CodeGeneration.Plugins.EventEntityApiGenerator.
61+
//
62+
// Changes to this file may cause incorrect behavior and will be lost if
63+
// the code is regenerated.
64+
// </auto-generated>
65+
//------------------------------------------------------------------------------
66+
public partial class TestEntity {
67+
68+
public void AddMixedEventListener(IMixedEventListener value) {
69+
var listeners = hasMixedEventListener
70+
? mixedEventListener.value
71+
: new System.Collections.Generic.List<IMixedEventListener>();
72+
listeners.Add(value);
73+
ReplaceMixedEventListener(listeners);
74+
}
75+
76+
public void RemoveMixedEventListener(IMixedEventListener value, bool removeComponentWhenEmpty = true) {
77+
var listeners = mixedEventListener.value;
78+
listeners.Remove(value);
79+
if (removeComponentWhenEmpty && listeners.Count == 0) {
80+
RemoveMixedEventListener();
81+
} else {
82+
ReplaceMixedEventListener(listeners);
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)