-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ecs & di & composition root
- Needs refactoring yet & docs update
- Loading branch information
Showing
16 changed files
with
221 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using Components.Sprites; | ||
using Entitas; | ||
using Features; | ||
using LightInject; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using MonoGame.Aseprite.Sprites; | ||
using Serilog; | ||
using Services; | ||
using Services.Factories; | ||
using Services.Input; | ||
using Services.Movement; | ||
using Stateless; | ||
using Systems; | ||
|
||
namespace GameDesktop; | ||
|
||
public class RootFeatureCompositionRoot : ICompositionRoot | ||
{ | ||
public void Compose(IServiceRegistry serviceRegistry) | ||
{ | ||
serviceRegistry.Register<IInputScanner, KeyboardScanner>(new PerContainerLifetime()); | ||
|
||
serviceRegistry.Register<IMovement, SimpleMovement>(new PerContainerLifetime()); | ||
|
||
serviceRegistry.Register(factory => | ||
{ | ||
Contexts contexts = factory.GetInstance<Contexts>(); | ||
IAllOfMatcher<GameEntity> inputMovableMatcher = GameMatcher.AllOf(GameMatcher.Transform, | ||
GameMatcher.Movable, | ||
GameMatcher.Player); | ||
IGroup<GameEntity> inputMovableGroup = contexts.game.GetGroup(inputMovableMatcher); | ||
|
||
var inputScanner = factory.GetInstance<IInputScanner>(); | ||
var logger = factory.GetInstance<ILogger>(); | ||
|
||
return new InputSystem(inputScanner, inputMovableGroup, logger); | ||
}, new PerContainerLifetime()); | ||
|
||
serviceRegistry.Register(factory => | ||
{ | ||
Contexts contexts = factory.GetInstance<Contexts>(); | ||
IAllOfMatcher<GameEntity> movableMatcher = GameMatcher.AllOf(GameMatcher.Transform, | ||
GameMatcher.Movable); | ||
IGroup<GameEntity> movableGroup = contexts.game.GetGroup(movableMatcher); | ||
|
||
var movement = factory.GetInstance<IMovement>(); | ||
var logger = factory.GetInstance<ILogger>(); | ||
|
||
return new MovementSystem(movement, movableGroup, logger); | ||
}, new PerContainerLifetime()); | ||
|
||
serviceRegistry.Register(factory => | ||
{ | ||
GraphicsDevice graphicsDevice = factory.GetInstance<SpriteBatch>().GraphicsDevice; | ||
SpriteSheet spriteSheet = | ||
AnimatedCharactersFactory.LoadSpriteSheet(graphicsDevice, "Content/SpriteSheets/Player.aseprite"); | ||
|
||
var idleDirAnimations = AnimatedCharactersFactory.CreateAnimations(spriteSheet, "Idle"); | ||
var walkingDirAnimations = AnimatedCharactersFactory.CreateAnimations(spriteSheet, "Walking"); | ||
|
||
return new AnimatedMovementComponent( | ||
new StateMachine<PlayerState, PlayerTrigger>(PlayerState.Idle), | ||
idleDirAnimations, | ||
walkingDirAnimations); | ||
}); | ||
|
||
serviceRegistry.Register(factory => new CreatePlayerEntitySystem(factory.GetInstance<Contexts>(), | ||
factory.GetInstance<AnimatedMovementComponent>())); | ||
|
||
serviceRegistry.Register(factory => | ||
{ | ||
Contexts contexts = factory.GetInstance<Contexts>(); | ||
IAllOfMatcher<GameEntity> animatedMovableMatcher = GameMatcher.AllOf(GameMatcher.Movable, | ||
GameMatcher.AnimatedMovement); | ||
IGroup<GameEntity> animatedMovableGroup = contexts.game.GetGroup(animatedMovableMatcher); | ||
|
||
var logger = factory.GetInstance<ILogger>(); | ||
|
||
return new AnimatedMovementSystem(animatedMovableGroup, logger); | ||
}); | ||
|
||
serviceRegistry.Register<RootFeature>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Systems; | ||
|
||
namespace Features; | ||
|
||
public sealed class RootFeature : Entitas.Extended.Feature | ||
{ | ||
public RootFeature(InputSystem inputSystem, | ||
MovementSystem movementSystem, | ||
CreatePlayerEntitySystem createPlayerEntitySystem, | ||
AnimatedMovementSystem animatedMovementSystem | ||
) | ||
{ | ||
Add(inputSystem); | ||
Add(movementSystem); | ||
Add(createPlayerEntitySystem); | ||
Add(animatedMovementSystem); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.