| | 1 | | using DCL.ECS7; |
| | 2 | | using DCL.ECS7.InternalComponents; |
| | 3 | | using System.Collections.Generic; |
| | 4 | |
|
| | 5 | | namespace ECSSystems.UIInputSenderSystem |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// Handles sending unique events from UI Elements to the scene |
| | 9 | | /// </summary> |
| | 10 | | public class ECSUIInputSenderSystem |
| | 11 | | { |
| 2 | 12 | | internal IInternalECSComponent<InternalUIInputResults> inputResultComponent { get; } |
| | 13 | | private readonly IReadOnlyDictionary<int, ComponentWriter> componentsWriter; |
| | 14 | |
|
| 3 | 15 | | public ECSUIInputSenderSystem(IInternalECSComponent<InternalUIInputResults> inputResultComponent, IReadOnlyDicti |
| | 16 | | { |
| 3 | 17 | | this.inputResultComponent = inputResultComponent; |
| 3 | 18 | | this.componentsWriter = componentsWriter; |
| 3 | 19 | | } |
| | 20 | |
|
| | 21 | | public void Update() |
| | 22 | | { |
| 2 | 23 | | var inputResults = inputResultComponent.GetForAll(); |
| | 24 | |
|
| 8 | 25 | | for (var i = 0; i < inputResults.Count; i++) |
| | 26 | | { |
| 2 | 27 | | var model = inputResults[i].value.model; |
| | 28 | |
|
| 2 | 29 | | if (!model.dirty) |
| | 30 | | continue; |
| | 31 | |
|
| 1 | 32 | | var scene = inputResults[i].value.scene; |
| 1 | 33 | | var entity = inputResults[i].value.entity; |
| | 34 | |
|
| 1 | 35 | | if (!componentsWriter.TryGetValue(scene.sceneData.sceneNumber, out var writer)) |
| | 36 | | continue; |
| | 37 | |
|
| | 38 | | // Results are already prepared in its final form by the UI Components themselves |
| | 39 | |
|
| 5 | 40 | | while (model.Results.TryDequeue(out var result)) |
| | 41 | | { |
| 4 | 42 | | writer.Put(entity.entityId, result.ComponentId, result.Message); |
| 4 | 43 | | } |
| | 44 | | } |
| 2 | 45 | | } |
| | 46 | | } |
| | 47 | | } |