Skip to content

Commit

Permalink
Updated to use the new GroupBinding plugin
Browse files Browse the repository at this point in the history
This has removed the need for injecting in all the IObservableGroupManagers everywhere.
  • Loading branch information
grofit committed May 2, 2021
1 parent dda6b70 commit 2ab4a6d
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 51 deletions.
Binary file modified Assets/EcsRx/EcsRx.Infrastructure.dll
Binary file not shown.
Binary file modified Assets/EcsRx/EcsRx.Plugins.Batching.dll
Binary file not shown.
Binary file modified Assets/EcsRx/EcsRx.Plugins.Computeds.dll
Binary file not shown.
Binary file added Assets/EcsRx/EcsRx.Plugins.GroupBinding.dll
Binary file not shown.
33 changes: 33 additions & 0 deletions Assets/EcsRx/EcsRx.Plugins.GroupBinding.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/EcsRx/EcsRx.Plugins.ReactiveSystems.dll
Binary file not shown.
Binary file modified Assets/EcsRx/EcsRx.Plugins.Views.dll
Binary file not shown.
Binary file modified Assets/EcsRx/EcsRx.dll
Binary file not shown.
Binary file modified Assets/EcsRx/SystemsRx.Infrastructure.dll
Binary file not shown.
Binary file modified Assets/EcsRx/SystemsRx.dll
Binary file not shown.
7 changes: 7 additions & 0 deletions Assets/Game/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using SystemsRx.Infrastructure.Extensions;
using EcsRx.Collections.Entity;
using EcsRx.Extensions;
using EcsRx.Plugins.GroupBinding;
using EcsRx.Plugins.Views.Components;
using EcsRx.Zenject;
using Game.Blueprints;
Expand Down Expand Up @@ -30,6 +31,12 @@ protected override void LoadModules()
Container.LoadModule<ComputedModule>();
}

protected override void LoadPlugins()
{
base.LoadPlugins();
RegisterPlugin(new GroupBindingsPlugin());
}

protected override void ApplicationStarted()
{
defaultCollection = EntityDatabase.GetCollection();
Expand Down
1 change: 0 additions & 1 deletion Assets/Game/Computeds/ComputedPlayerPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public override Vector3 Transform(IObservableGroup observableGroup)
if(player == null)
{ return Vector3.zero; }

Debug.Log("Have Player");
var gameObject = player.GetGameObject();
return gameObject.transform.position;
}
Expand Down
15 changes: 7 additions & 8 deletions Assets/Game/Systems/ExitReachedSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using EcsRx.Extensions;
using EcsRx.Groups;
using EcsRx.Groups.Observable;
using EcsRx.Plugins.GroupBinding.Attributes;
using EcsRx.Systems;
using EcsRx.Unity.Extensions;
using Game.Blueprints;
Expand All @@ -16,18 +17,16 @@ namespace Game.Systems
{
public class ExitReachedSystem : IReactToEventSystem<ExitReachedEvent>, IManualSystem, IGroupSystem
{
private IEntity _level;
private IObservableGroup _observableGroup;

public IGroup Group { get; } = new Group(typeof(LevelComponent));

public ExitReachedSystem(IObservableGroupManager observableGroupManager)
{
_observableGroup = observableGroupManager.GetObservableGroup(Group);
}
[FromGroup]
public IObservableGroup ObservableGroup;

private IEntity _level;


public void StartSystem()
{ this.WaitForScene().Subscribe(x => _level = _observableGroup.First()); }
{ this.WaitForScene().Subscribe(x => _level = ObservableGroup.First()); }

public void StopSystem()
{}
Expand Down
13 changes: 7 additions & 6 deletions Assets/Game/Systems/FoodTextUpdateSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using EcsRx.Collections;
using EcsRx.Extensions;
using EcsRx.Groups;
using EcsRx.Groups.Observable;
using EcsRx.Plugins.GroupBinding.Attributes;
using EcsRx.Systems;
using EcsRx.Unity.Extensions;
using Game.Components;
Expand All @@ -23,27 +25,26 @@ public class FoodTextUpdateSystem : IManualSystem, IGroupSystem
{
public IGroup Group { get; } = new Group(typeof(PlayerComponent));

private readonly IEventSystem _eventSystem;
private IObservableGroupManager _observableGroupManager;
[FromGroup]
public IObservableGroup ObservableGroup;

private readonly IEventSystem _eventSystem;
private PlayerComponent _playerComponent;
private Text _foodText;
private readonly IList<IDisposable> _subscriptions = new List<IDisposable>();

public FoodTextUpdateSystem(IEventSystem eventSystem, IObservableGroupManager observableGroupManager)
public FoodTextUpdateSystem(IEventSystem eventSystem)
{
_eventSystem = eventSystem;
_observableGroupManager = observableGroupManager;
}

public void StartSystem()
{
this.WaitForScene().Subscribe(x =>
{
var player = _observableGroupManager.GetObservableGroup(Group).First();
var player = ObservableGroup.First();
_playerComponent = player.GetComponent<PlayerComponent>();
_foodText = GameObject.Find("FoodText").GetComponent<Text>();

SetupSubscriptions();
});
}
Expand Down
16 changes: 9 additions & 7 deletions Assets/Game/Systems/LevelScreenVisibilitySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using EcsRx.Collections;
using EcsRx.Extensions;
using EcsRx.Groups;
using EcsRx.Groups.Observable;
using EcsRx.Plugins.GroupBinding.Attributes;
using EcsRx.Systems;
using EcsRx.Unity.Extensions;
using Game.Components;
Expand All @@ -18,27 +20,27 @@ namespace Game.Systems
{
public class LevelScreenVisibilitySystem : IManualSystem, IGroupSystem
{
private IEventSystem _eventSystem;
private IObservableGroupManager _observableGroupManager;

public IGroup Group { get; } = new Group(typeof(LevelComponent));


[FromGroup]
public IObservableGroup ObservableGroup;

private IEventSystem _eventSystem;
private GameObject _levelImage;
private LevelComponent _levelComponent;
private IList<IDisposable> _subscriptions = new List<IDisposable>();

public LevelScreenVisibilitySystem(IEventSystem eventSystem, IObservableGroupManager observableGroupManager)
public LevelScreenVisibilitySystem(IEventSystem eventSystem)
{
_eventSystem = eventSystem;
_observableGroupManager = observableGroupManager;
}

public void StartSystem()
{
this.WaitForScene()
.Subscribe(x =>
{
var level = _observableGroupManager.GetObservableGroup(Group).First();
var level = ObservableGroup.First();
_levelComponent = level.GetComponent<LevelComponent>();
_levelImage = GameObject.Find("LevelImage");
SetupSubscriptions();
Expand Down
11 changes: 7 additions & 4 deletions Assets/Game/Systems/LevelTextUpdateSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using EcsRx.Collections;
using EcsRx.Extensions;
using EcsRx.Groups;
using EcsRx.Groups.Observable;
using EcsRx.Plugins.GroupBinding.Attributes;
using EcsRx.Systems;
using EcsRx.Unity.Extensions;
using Game.Components;
Expand All @@ -21,24 +23,25 @@ public class LevelTextUpdateSystem : IManualSystem, IGroupSystem
{
public IGroup Group { get; } = new Group(typeof(LevelComponent));

[FromGroup]
public IObservableGroup ObservableGroup;

private Text _levelText;
private LevelComponent _levelComponent;
private readonly IEventSystem _eventSystem;
private readonly IObservableGroupManager _observableGroupManager;
private readonly IList<IDisposable> _subscriptions = new List<IDisposable>();

public LevelTextUpdateSystem(IEventSystem eventSystem, IObservableGroupManager observableGroupManager)
public LevelTextUpdateSystem(IEventSystem eventSystem)
{
_eventSystem = eventSystem;
_observableGroupManager = observableGroupManager;
}

public void StartSystem()
{
this.WaitForScene()
.Subscribe(x =>
{
var level = _observableGroupManager.GetObservableGroup(Group).First();
var level = ObservableGroup.First();
_levelComponent = level.GetComponent<LevelComponent>();
_levelText = GameObject.Find("LevelText").GetComponent<Text>();
SetupSubscriptions();
Expand Down
13 changes: 7 additions & 6 deletions Assets/Game/Systems/MusicSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
using SystemsRx.Events;
using SystemsRx.Systems.Conventional;
using SystemsRx.Extensions;
using EcsRx.Collections;
using EcsRx.Extensions;
using EcsRx.Groups;
using EcsRx.Groups.Observable;
using EcsRx.Plugins.GroupBinding.Attributes;
using EcsRx.Systems;
using EcsRx.Unity.Extensions;
using Game.Components;
Expand All @@ -20,27 +21,27 @@ public class MusicSystem : IManualSystem, IGroupSystem
{
public IGroup Group { get; } = new Group(typeof(LevelComponent));

private readonly IEventSystem _eventSystem;
private readonly IObservableGroupManager _observableGroupManager;
[FromGroup]
public IObservableGroup ObservableGroup;

private readonly IEventSystem _eventSystem;
private readonly AudioSource _musicSource;
private LevelComponent _levelComponent;
private readonly IList<IDisposable> _subscriptions = new List<IDisposable>();

public MusicSystem(IEventSystem eventSystem, IObservableGroupManager observableGroupManager)
public MusicSystem(IEventSystem eventSystem)
{
var soundEffectObject = GameObject.Find("MusicSource");
_musicSource = soundEffectObject.GetComponent<AudioSource>();
_eventSystem = eventSystem;
_observableGroupManager = observableGroupManager;
}

public void StartSystem()
{
this.WaitForScene()
.Subscribe(x =>
{
var level = _observableGroupManager.GetObservableGroup(Group).First();
var level = ObservableGroup.First();
_levelComponent = level.GetComponent<LevelComponent>();
SetupSubscriptions();
});
Expand Down
12 changes: 7 additions & 5 deletions Assets/Game/Systems/PlayerInteractionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using EcsRx.Collections;
using EcsRx.Entities;
using EcsRx.Groups;
using EcsRx.Groups.Observable;
using EcsRx.Plugins.GroupBinding.Attributes;
using EcsRx.Systems;
using EcsRx.Unity.Extensions;
using EcsRx.Unity.MonoBehaviours;
Expand All @@ -20,24 +22,24 @@ namespace Game.Systems
public class PlayerInteractionSystem : IManualSystem, IGroupSystem
{
public IGroup Group { get; } = new Group(typeof (PlayerComponent), typeof (ViewComponent));

[FromGroup]
public IObservableGroup ObservableGroup;

private readonly IList<IDisposable> _foodTriggers = new List<IDisposable>();
private readonly IList<IDisposable> _exitTriggers = new List<IDisposable>();
private readonly IEventSystem _eventSystem;
private readonly IObservableGroupManager _observableGroupManager;

public PlayerInteractionSystem(IEventSystem eventSystem, IObservableGroupManager observableGroupManager)
public PlayerInteractionSystem(IEventSystem eventSystem)
{
_eventSystem = eventSystem;
_observableGroupManager = observableGroupManager;
}

public void StartSystem()
{
this.WaitForScene().Subscribe(x =>
{
var observableGroup = _observableGroupManager.GetObservableGroup(Group);
foreach(var player in observableGroup)
foreach(var player in ObservableGroup)
{ CheckForInteractions(player); }
});
}
Expand Down
4 changes: 1 addition & 3 deletions Assets/Game/Systems/StandardInputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public class StandardInputSystem : IReactToGroupSystem
public IGroup Group { get; } = new Group(typeof(MovementComponent), typeof(StandardInputComponent));

public IObservable<IObservableGroup> ReactToGroup(IObservableGroup group)
{
return Observable.EveryUpdate().Select(x => group);
}
{ return Observable.EveryUpdate().Select(x => group); }

public void Process(IEntity entity)
{
Expand Down
24 changes: 13 additions & 11 deletions Assets/Game/Systems/TurnsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using EcsRx.Extensions;
using EcsRx.Groups;
using EcsRx.Groups.Observable;
using EcsRx.Plugins.GroupBinding.Attributes;
using EcsRx.Systems;
using EcsRx.Unity.Extensions;
using Game.Components;
Expand All @@ -18,36 +19,37 @@

namespace Game.Systems
{
public class TurnsSystem : IManualSystem, IGroupSystem
public class TurnsSystem : IManualSystem
{
private readonly GameConfiguration _gameConfiguration;
private readonly IEventSystem _eventSystem;

private IDisposable _updateSubscription;
private bool _isProcessing;
private readonly IObservableGroup _levelAccessor, _enemyAccessor;

[FromComponents(typeof (LevelComponent))]
public IObservableGroup LevelAccessor;

[FromComponents(typeof(EnemyComponent))]
public IObservableGroup EnemyAccessor;

private IEntity _level;

public IGroup Group { get; } = new Group(typeof(EnemyComponent));

public TurnsSystem(GameConfiguration gameConfiguration, IEventSystem eventSystem, IObservableGroupManager observableGroupManager)
public TurnsSystem(GameConfiguration gameConfiguration, IEventSystem eventSystem)
{
_gameConfiguration = gameConfiguration;
_eventSystem = eventSystem;

_levelAccessor = observableGroupManager.GetObservableGroup(new Group(typeof (LevelComponent)));
_enemyAccessor = observableGroupManager.GetObservableGroup(Group);
}

private IEnumerator CarryOutTurns()
{
_isProcessing = true;
yield return new WaitForSeconds(_gameConfiguration.TurnDelay);

if(!_enemyAccessor.Any())
if(!EnemyAccessor.Any())
{ yield return new WaitForSeconds(_gameConfiguration.TurnDelay); }

foreach (var enemy in _enemyAccessor)
foreach (var enemy in EnemyAccessor)
{
_eventSystem.Publish(new EnemyTurnEvent(enemy));
yield return new WaitForSeconds(_gameConfiguration.MovementTime);
Expand All @@ -66,7 +68,7 @@ private bool IsLevelLoaded()

public void StartSystem()
{
this.WaitForScene().Subscribe(x => _level = _levelAccessor.First());
this.WaitForScene().Subscribe(x => _level = LevelAccessor.First());

_updateSubscription = Observable.EveryUpdate().Where(x => IsLevelLoaded())
.Subscribe(x => {
Expand Down

0 comments on commit 2ab4a6d

Please sign in to comment.