From 32b0f0f140fb8259bdd8d34983168a08b0e2df45 Mon Sep 17 00:00:00 2001 From: Joanna May Date: Sat, 23 Dec 2023 12:57:29 -0600 Subject: [PATCH] refactor: update to logicblocks 4 --- .editorconfig | 2 + GameDemo.csproj | 6 ++- src/app/state/AppLogic.State.cs | 9 ++-- src/app/state/AppLogic.cs | 3 +- src/app/state/states/LeavingMenu.cs | 4 +- src/app/state/states/MainMenu.cs | 7 ++- src/app/state/states/RestartingGame.cs | 6 +-- src/app/state/states/SplashScreen.cs | 19 +++---- src/app/state/states/in_game/GamePaused.cs | 7 ++- src/app/state/states/in_game/InGame.cs | 18 +++---- src/app/state/states/in_game/LeavingGame.cs | 2 +- src/app/state/states/in_game/LostGame.cs | 4 +- src/app/state/states/in_game/PlayingGame.cs | 4 +- src/app/state/states/in_game/ResumingGame.cs | 7 ++- src/app/state/states/in_game/WonGame.cs | 2 +- src/coin/state/CoinLogic.State.cs | 3 +- src/coin/state/CoinLogic.cs | 3 +- .../states/CoinLogic.State.Collecting.cs | 10 ++-- src/coin/state/states/CoinLogic.State.Idle.cs | 6 +-- src/game/state/GameLogic.State.cs | 15 +++--- src/game/state/GameLogic.cs | 3 +- .../state/InGameAudioLogic.State.cs | 10 ++-- src/in_game_audio/state/InGameAudioLogic.cs | 3 +- src/in_game_ui/state/InGameUILogic.State.cs | 10 ++-- src/in_game_ui/state/InGameUILogic.cs | 5 +- src/jumpshroom/state/JumpshroomLogic.State.cs | 3 +- src/jumpshroom/state/JumpshroomLogic.cs | 3 +- .../states/JumpshroomLogic.State.Cooldown.cs | 4 +- .../states/JumpshroomLogic.State.Idle.cs | 5 +- .../states/JumpshroomLogic.State.Launching.cs | 16 +++--- .../states/JumpshroomLogic.State.Loading.cs | 8 ++- src/player/state/PlayerLogic.State.cs | 4 +- src/player/state/PlayerLogic.cs | 3 +- ...layerLogic.State.Alive.Airborne.Falling.cs | 2 +- ...layerLogic.State.Alive.Airborne.Jumping.cs | 6 +-- ...layerLogic.State.Alive.Airborne.Liftoff.cs | 2 +- .../PlayerLogic.State.Alive.Airborne.cs | 8 ++- .../PlayerLogic.State.Alive.Grounded.Idle.cs | 5 +- ...PlayerLogic.State.Alive.Grounded.Moving.cs | 5 +- .../PlayerLogic.State.Alive.Grounded.cs | 11 ++-- .../state/states/PlayerLogic.State.Alive.cs | 4 +- .../state/states/PlayerLogic.State.Dead.cs | 4 +- .../states/PlayerLogic.State.Disabled.cs | 16 ++---- .../State/PlayerCameraLogic.State.cs | 21 ++++---- src/player_camera/State/PlayerCameraLogic.cs | 3 +- .../PlayerCameraLogic.State.InputDisabled.cs | 5 +- .../PlayerCameraLogic.State.InputEnabled.cs | 7 ++- ...ogic.StateTest.cs => AppLogicStateTest.cs} | 13 ++--- test/src/app/state/AppLogicTest.cs | 4 +- test/src/app/state/states/LeavingMenuTest.cs | 9 ++-- test/src/app/state/states/MainMenuTest.cs | 9 ++-- .../app/state/states/RestartingGameTest.cs | 9 ++-- test/src/app/state/states/SplashScreenTest.cs | 25 +++++---- .../state/states/in_game/GamePausedTest.cs | 9 ++-- .../app/state/states/in_game/InGameTest.cs | 27 +++++++--- .../state/states/in_game/LeavingGameTest.cs | 9 ++-- .../app/state/states/in_game/LostGameTest.cs | 9 ++-- .../state/states/in_game/PlayingGameTest.cs | 7 +-- .../state/states/in_game/ResumingGameTest.cs | 9 ++-- .../app/state/states/in_game/WonGameTest.cs | 9 ++-- test/src/coin/state/CoinLogicTest.cs | 5 +- .../states/CoinLogic.State.CollectingTest.cs | 12 ++--- .../state/states/CoinLogic.State.IdleTest.cs | 10 ++-- test/src/game/state/GameLogic.StateTest.cs | 13 ++--- test/src/game/state/GameLogicTest.cs | 4 +- .../state/InGameAudioLogic.StateTest.cs | 13 ++--- .../state/InGameAudioLogicTest.cs | 4 +- ...StateTest.cs => InGameUILogicStateTest.cs} | 14 ++--- .../src/in_game_ui/state/InGameUILogicTest.cs | 7 +-- .../jumpshroom/state/JumpshroomLogicTest.cs | 7 +-- .../JumpshroomLogic.State.CooldownTest.cs | 8 +-- .../states/JumpshroomLogic.State.IdleTest.cs | 8 +-- .../JumpshroomLogic.State.LaunchingTest.cs | 10 ++-- .../JumpshroomLogic.State.LoadingTest.cs | 10 ++-- test/src/player/state/PlayerLogicTest.cs | 6 +-- ...rLogic.State.Alive.Airborne.FallingTest.cs | 11 ++-- ...rLogic.State.Alive.Airborne.JumpingTest.cs | 13 +++-- ...rLogic.State.Alive.Airborne.LiftoffTest.cs | 11 ++-- .../PlayerLogic.State.Alive.AirborneTest.cs | 4 +- ...ayerLogic.State.Alive.Grounded.IdleTest.cs | 10 ++-- ...erLogic.State.Alive.Grounded.MovingTest.cs | 10 ++-- .../PlayerLogic.State.Alive.GroundedTest.cs | 12 ++--- .../states/PlayerLogic.State.AliveTest.cs | 10 ++-- .../states/PlayerLogic.State.DeadTest.cs | 3 +- .../states/PlayerLogic.State.DisabledTest.cs | 20 ++++--- ...ayerCameraLogic.State.InputDisabledTest.cs | 4 +- ...layerCameraLogic.State.InputEnabledTest.cs | 16 +++--- .../state/PlayerCameraLogic.StateTest.cs | 52 +++++++------------ .../state/PlayerCameraLogicTest.cs | 5 +- 89 files changed, 354 insertions(+), 419 deletions(-) rename test/src/app/state/{AppLogic.StateTest.cs => AppLogicStateTest.cs} (83%) rename test/src/in_game_ui/state/{InGameUILogic.StateTest.cs => InGameUILogicStateTest.cs} (89%) diff --git a/.editorconfig b/.editorconfig index 2f9c60a..5778cc5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -468,3 +468,5 @@ dotnet_diagnostic.RCS1181.severity = none dotnet_diagnostic.IDE0046.severity = none # Don't make me use expression bodies for methods dotnet_diagnostic.IDE0022.severity = none +# Don't use collection shorhand. +dotnet_diagnostic.IDE0300.severity = none diff --git a/GameDemo.csproj b/GameDemo.csproj index beb3d66..ef74298 100644 --- a/GameDemo.csproj +++ b/GameDemo.csproj @@ -41,8 +41,10 @@ - - + + + + diff --git a/src/app/state/AppLogic.State.cs b/src/app/state/AppLogic.State.cs index 1c52249..fb78084 100644 --- a/src/app/state/AppLogic.State.cs +++ b/src/app/state/AppLogic.State.cs @@ -3,12 +3,11 @@ public partial class AppLogic { public interface IState : IStateLogic { } public partial record State : StateLogic, IState { - public State(IContext context) : base(context) { - var appRepo = Context.Get(); - OnEnter( - (previous) => appRepo.IsMouseCaptured.Sync += OnMouseCaptured + public State() { + OnAttach( + () => Get().IsMouseCaptured.Sync += OnMouseCaptured ); - OnExit((next) => appRepo.IsMouseCaptured.Sync -= OnMouseCaptured); + OnDetach(() => Get().IsMouseCaptured.Sync -= OnMouseCaptured); } public void OnMouseCaptured(bool isMouseCaptured) => diff --git a/src/app/state/AppLogic.cs b/src/app/state/AppLogic.cs index f0925d4..03c2d5c 100644 --- a/src/app/state/AppLogic.cs +++ b/src/app/state/AppLogic.cs @@ -7,8 +7,7 @@ public interface IAppLogic : ILogicBlock { } [StateMachine] public partial class AppLogic : LogicBlock, IAppLogic { - public override IState GetInitialState(IContext context) - => new State.SplashScreen(context); + public override IState GetInitialState() => new State.SplashScreen(); public AppLogic(IAppRepo appRepo) { Set(appRepo); diff --git a/src/app/state/states/LeavingMenu.cs b/src/app/state/states/LeavingMenu.cs index 89e02ef..c48faa6 100644 --- a/src/app/state/states/LeavingMenu.cs +++ b/src/app/state/states/LeavingMenu.cs @@ -3,14 +3,14 @@ namespace GameDemo; public partial class AppLogic { public partial record State { public record LeavingMenu : State, IGet { - public LeavingMenu(IContext context) : base(context) { + public LeavingMenu() { OnEnter( (previous) => Context.Output(new Output.FadeOut()) ); } public IState On(Input.FadeOutFinished input) => - new PlayingGame(Context); + new PlayingGame(); } } } diff --git a/src/app/state/states/MainMenu.cs b/src/app/state/states/MainMenu.cs index 73d6a7c..6511eae 100644 --- a/src/app/state/states/MainMenu.cs +++ b/src/app/state/states/MainMenu.cs @@ -3,18 +3,17 @@ namespace GameDemo; public partial class AppLogic { public partial record State { public record MainMenu : State, IGet { - public MainMenu(IContext context) : base(context) { - var appRepo = Context.Get(); + public MainMenu() { OnEnter( (previous) => { - appRepo.OnMainMenuEntered(); + Get().OnMainMenuEntered(); Context.Output(new Output.LoadGame()); Context.Output(new Output.ShowMainMenu()); } ); } - public IState On(Input.StartGame input) => new LeavingMenu(Context); + public IState On(Input.StartGame input) => new LeavingMenu(); } } } diff --git a/src/app/state/states/RestartingGame.cs b/src/app/state/states/RestartingGame.cs index 6e5cdff..c725ab3 100644 --- a/src/app/state/states/RestartingGame.cs +++ b/src/app/state/states/RestartingGame.cs @@ -2,9 +2,7 @@ namespace GameDemo; public partial class AppLogic { public partial record State { public record RestartingGame : State, IGet { - public RestartingGame(IContext context) : base(context) { - var appRepo = Context.Get(); - + public RestartingGame() { OnEnter( (previous) => Context.Output(new Output.FadeOut()) ); @@ -17,7 +15,7 @@ public RestartingGame(IContext context) : base(context) { } public IState On(Input.FadeOutFinished input) => - new PlayingGame(Context); + new PlayingGame(); } } } diff --git a/src/app/state/states/SplashScreen.cs b/src/app/state/states/SplashScreen.cs index e1b02e7..1146a40 100644 --- a/src/app/state/states/SplashScreen.cs +++ b/src/app/state/states/SplashScreen.cs @@ -3,20 +3,21 @@ namespace GameDemo; public partial class AppLogic { public partial record State { public record SplashScreen : State, IGet { - public SplashScreen(IContext context) : base(context) { - var appRepo = Context.Get(); + public SplashScreen() { OnEnter( - (previous) => { - Context.Output(new Output.ShowSplashScreen()); - appRepo.SplashScreenSkipped += OnSplashScreenSkipped; - } + (previous) => Context.Output(new Output.ShowSplashScreen()) ); - OnExit( - (next) => appRepo.SplashScreenSkipped -= OnSplashScreenSkipped + + OnAttach( + () => Get().SplashScreenSkipped += OnSplashScreenSkipped + ); + + OnDetach( + () => Get().SplashScreenSkipped -= OnSplashScreenSkipped ); } - public IState On(Input.FadeOutFinished input) => new MainMenu(Context); + public IState On(Input.FadeOutFinished input) => new MainMenu(); public void OnSplashScreenSkipped() => Context.Output(new Output.HideSplashScreen()); diff --git a/src/app/state/states/in_game/GamePaused.cs b/src/app/state/states/in_game/GamePaused.cs index 36b9808..81372f1 100644 --- a/src/app/state/states/in_game/GamePaused.cs +++ b/src/app/state/states/in_game/GamePaused.cs @@ -2,12 +2,11 @@ namespace GameDemo; public partial class AppLogic { public partial record State { public record GamePaused : InGame, IGet { - public GamePaused(IContext context) : base(context) { - var appRepo = Context.Get(); + public GamePaused() { OnEnter( (previous) => { Context.Output(new Output.ShowPauseMenu()); - appRepo.Pause(); + Get().Pause(); } ); OnExit( @@ -16,7 +15,7 @@ public GamePaused(IContext context) : base(context) { } public IState On(Input.PauseButtonPressed input) - => new ResumingGame(Context); + => new ResumingGame(); } } } diff --git a/src/app/state/states/in_game/InGame.cs b/src/app/state/states/in_game/InGame.cs index 9769d94..4a7db0c 100644 --- a/src/app/state/states/in_game/InGame.cs +++ b/src/app/state/states/in_game/InGame.cs @@ -6,16 +6,14 @@ public partial class AppLogic { public partial record State { public record InGame : State, IGet, IGet { - public InGame(IContext context) : base(context) { - var appRepo = Context.Get(); - + public InGame() { OnEnter((previous) => { - appRepo.OnStartGame(); - appRepo.GameEnded += OnGameOver; + Get().OnStartGame(); Context.Output(new Output.ShowGame()); }); - OnExit((next) => appRepo.GameEnded -= OnGameOver); + OnAttach(() => Get().GameEnded += OnGameOver); + OnDetach(() => Get().GameEnded -= OnGameOver); } public void OnGameOver(GameOverReason reason) { @@ -27,14 +25,14 @@ public IState On(Input.GameOver input) { appRepo.Pause(); return input.Reason switch { - GameOverReason.PlayerWon => new WonGame(Context), - GameOverReason.PlayerDied => new LostGame(Context), - GameOverReason.Exited => new MainMenu(Context), + GameOverReason.PlayerWon => new WonGame(), + GameOverReason.PlayerDied => new LostGame(), + GameOverReason.Exited => new MainMenu(), _ => throw new InvalidOperationException() }; } - public IState On(Input.GoToMainMenu input) => new LeavingGame(Context); + public IState On(Input.GoToMainMenu input) => new LeavingGame(); } } } diff --git a/src/app/state/states/in_game/LeavingGame.cs b/src/app/state/states/in_game/LeavingGame.cs index cb48511..45a75eb 100644 --- a/src/app/state/states/in_game/LeavingGame.cs +++ b/src/app/state/states/in_game/LeavingGame.cs @@ -2,7 +2,7 @@ namespace GameDemo; public partial class AppLogic { public partial record State { public record LeavingGame : InGame, IGet { - public LeavingGame(IContext context) : base(context) { + public LeavingGame() { OnEnter( (previous) => Context.Output(new Output.FadeOut()) ); diff --git a/src/app/state/states/in_game/LostGame.cs b/src/app/state/states/in_game/LostGame.cs index 93b66cf..77969fa 100644 --- a/src/app/state/states/in_game/LostGame.cs +++ b/src/app/state/states/in_game/LostGame.cs @@ -2,14 +2,14 @@ namespace GameDemo; public partial class AppLogic { public partial record State { public record LostGame : InGame, IGet { - public LostGame(IContext context) : base(context) { + public LostGame() { OnEnter( (previous) => Context.Output(new Output.ShowPlayerDied()) ); } public IState On(Input.StartGame input) => - new RestartingGame(Context); + new RestartingGame(); } } } diff --git a/src/app/state/states/in_game/PlayingGame.cs b/src/app/state/states/in_game/PlayingGame.cs index 0295556..83180d2 100644 --- a/src/app/state/states/in_game/PlayingGame.cs +++ b/src/app/state/states/in_game/PlayingGame.cs @@ -2,10 +2,10 @@ namespace GameDemo; public partial class AppLogic { public partial record State { public record PlayingGame : InGame, IGet { - public PlayingGame(IContext context) : base(context) { } + public PlayingGame() { } public IState On(Input.PauseButtonPressed input) - => new GamePaused(Context); + => new GamePaused(); } } } diff --git a/src/app/state/states/in_game/ResumingGame.cs b/src/app/state/states/in_game/ResumingGame.cs index 518b86e..3ce9610 100644 --- a/src/app/state/states/in_game/ResumingGame.cs +++ b/src/app/state/states/in_game/ResumingGame.cs @@ -2,16 +2,15 @@ namespace GameDemo; public partial class AppLogic { public partial record State { public record ResumingGame : InGame, IGet { - public ResumingGame(IContext context) : base(context) { - var appRepo = Context.Get(); - OnEnter((previous) => appRepo.Resume()); + public ResumingGame() { + OnEnter((previous) => Get().Resume()); OnExit( (next) => Context.Output(new Output.DisablePauseMenu()) ); } public IState On(Input.PauseMenuTransitioned input) => - new PlayingGame(Context); + new PlayingGame(); } } } diff --git a/src/app/state/states/in_game/WonGame.cs b/src/app/state/states/in_game/WonGame.cs index d04d654..e943a9f 100644 --- a/src/app/state/states/in_game/WonGame.cs +++ b/src/app/state/states/in_game/WonGame.cs @@ -2,7 +2,7 @@ namespace GameDemo; public partial class AppLogic { public partial record State { public record WonGame : InGame { - public WonGame(IContext context) : base(context) { + public WonGame() { OnEnter( (previous) => Context.Output(new Output.ShowPlayerWon()) ); diff --git a/src/coin/state/CoinLogic.State.cs b/src/coin/state/CoinLogic.State.cs index 8cf8de6..1b6414e 100644 --- a/src/coin/state/CoinLogic.State.cs +++ b/src/coin/state/CoinLogic.State.cs @@ -3,6 +3,5 @@ namespace GameDemo; public partial class CoinLogic { public interface IState : IStateLogic { } - public abstract partial record State(IContext Context) : - StateLogic(Context), IState; + public abstract partial record State : StateLogic, IState; } diff --git a/src/coin/state/CoinLogic.cs b/src/coin/state/CoinLogic.cs index 92b5298..75583d9 100644 --- a/src/coin/state/CoinLogic.cs +++ b/src/coin/state/CoinLogic.cs @@ -7,8 +7,7 @@ public interface ICoinLogic : ILogicBlock { } [StateMachine] public partial class CoinLogic : LogicBlock, ICoinLogic { - public override IState GetInitialState(IContext context) => - new State.Idle(context); + public override IState GetInitialState() => new State.Idle(); public record Settings(double CollectionTimeInSeconds); diff --git a/src/coin/state/states/CoinLogic.State.Collecting.cs b/src/coin/state/states/CoinLogic.State.Collecting.cs index 14ac9a0..13b76a4 100644 --- a/src/coin/state/states/CoinLogic.State.Collecting.cs +++ b/src/coin/state/states/CoinLogic.State.Collecting.cs @@ -8,14 +8,12 @@ public record Collecting : State, ICollecting, IGet { public ICoinCollector Target { get; } private double _elapsedTime; - public Collecting(IContext context, ICoinCollector target) : - base(context) { - var coin = Context.Get(); - var appRepo = Context.Get(); - + public Collecting(ICoinCollector target) { Target = target; - OnEnter((previous) => appRepo.StartCoinCollection(coin)); + OnEnter( + (previous) => Get().StartCoinCollection(Get()) + ); } public IState On(Input.PhysicsProcess input) { diff --git a/src/coin/state/states/CoinLogic.State.Idle.cs b/src/coin/state/states/CoinLogic.State.Idle.cs index b673075..c4a3229 100644 --- a/src/coin/state/states/CoinLogic.State.Idle.cs +++ b/src/coin/state/states/CoinLogic.State.Idle.cs @@ -4,11 +4,9 @@ public partial class CoinLogic { public partial record State { public interface IIdle : IState { } - public record Idle( - IContext Context - ) : State(Context), IIdle, IGet { + public record Idle : State, IIdle, IGet { public IState On(Input.StartCollection input) => new Collecting( - Context, input.Target + input.Target ); } } diff --git a/src/game/state/GameLogic.State.cs b/src/game/state/GameLogic.State.cs index 2d95b40..3cb99b4 100644 --- a/src/game/state/GameLogic.State.cs +++ b/src/game/state/GameLogic.State.cs @@ -2,20 +2,19 @@ namespace GameDemo; public partial class GameLogic { public interface IState : IStateLogic { } - public record State : - StateLogic, IState, IGet { - public State(IContext context) : base(context) { - var appRepo = context.Get(); - - OnEnter( - (previous) => { + public record State : StateLogic, IState, IGet { + public State() { + OnAttach( + () => { + var appRepo = Context.Get(); appRepo.GameStarting += GameAboutToStart; appRepo.GamePaused += GamePaused; appRepo.GameResumed += GameResumed; } ); - OnExit((next) => { + OnDetach(() => { + var appRepo = Context.Get(); appRepo.GameStarting -= GameAboutToStart; appRepo.GamePaused -= GamePaused; appRepo.GameResumed -= GameResumed; diff --git a/src/game/state/GameLogic.cs b/src/game/state/GameLogic.cs index daf69c1..d8665f0 100644 --- a/src/game/state/GameLogic.cs +++ b/src/game/state/GameLogic.cs @@ -6,8 +6,7 @@ public interface IGameLogic : ILogicBlock { } [StateMachine] public partial class GameLogic : LogicBlock, IGameLogic { - public override IState GetInitialState(IContext context) => - new State(context); + public override IState GetInitialState() => new State(); public GameLogic(IAppRepo appRepo) { Set(appRepo); diff --git a/src/in_game_audio/state/InGameAudioLogic.State.cs b/src/in_game_audio/state/InGameAudioLogic.State.cs index 7a6370e..ce881f6 100644 --- a/src/in_game_audio/state/InGameAudioLogic.State.cs +++ b/src/in_game_audio/state/InGameAudioLogic.State.cs @@ -7,10 +7,9 @@ public partial class InGameAudioLogic : public interface IState : IStateLogic { } public record State : StateLogic, IState { - public State(IContext context) : base(context) { - var appRepo = context.Get(); - - OnEnter((previous) => { + public State() { + OnAttach(() => { + var appRepo = Context.Get(); appRepo.CoinCollected += OnCoinCollected; appRepo.JumpshroomUsed += OnJumpshroomUsed; appRepo.GameEnded += OnGameEnded; @@ -19,7 +18,8 @@ public State(IContext context) : base(context) { appRepo.GameStarting += OnGameStarting; }); - OnExit((previous) => { + OnDetach(() => { + var appRepo = Context.Get(); appRepo.CoinCollected -= OnCoinCollected; appRepo.JumpshroomUsed -= OnJumpshroomUsed; appRepo.GameEnded -= OnGameEnded; diff --git a/src/in_game_audio/state/InGameAudioLogic.cs b/src/in_game_audio/state/InGameAudioLogic.cs index 6338990..4c2519a 100644 --- a/src/in_game_audio/state/InGameAudioLogic.cs +++ b/src/in_game_audio/state/InGameAudioLogic.cs @@ -8,8 +8,7 @@ public interface IInGameAudioLogic : ILogicBlock { } [StateMachine] public partial class InGameAudioLogic : LogicBlock, IInGameAudioLogic { - public override IState GetInitialState(IContext context) => - new State(context); + public override IState GetInitialState() => new State(); public InGameAudioLogic(IAppRepo appRepo) { Set(appRepo); diff --git a/src/in_game_ui/state/InGameUILogic.State.cs b/src/in_game_ui/state/InGameUILogic.State.cs index 87a8d90..f32237b 100644 --- a/src/in_game_ui/state/InGameUILogic.State.cs +++ b/src/in_game_ui/state/InGameUILogic.State.cs @@ -4,15 +4,15 @@ public partial class InGameUILogic { public interface IState : IStateLogic { } public record State : StateLogic, IState { - public State(IContext context) : base(context) { - var appRepo = context.Get(); - - OnEnter((previous) => { + public State() { + OnAttach(() => { + var appRepo = Context.Get(); appRepo.NumCoinsCollected.Sync += OnNumCoinsCollected; appRepo.NumCoinsAtStart.Sync += OnNumCoinsAtStart; }); - OnExit((next) => { + OnDetach(() => { + var appRepo = Context.Get(); appRepo.NumCoinsCollected.Sync -= OnNumCoinsCollected; appRepo.NumCoinsAtStart.Sync -= OnNumCoinsAtStart; }); diff --git a/src/in_game_ui/state/InGameUILogic.cs b/src/in_game_ui/state/InGameUILogic.cs index e5fa7b7..0640ba9 100644 --- a/src/in_game_ui/state/InGameUILogic.cs +++ b/src/in_game_ui/state/InGameUILogic.cs @@ -10,11 +10,10 @@ public interface IInGameUILogic : ILogicBlock { } [StateMachine] public partial class InGameUILogic : LogicBlock, IInGameUILogic { + public override IState GetInitialState() => new State(); + public InGameUILogic(IInGameUI inGameUi, IAppRepo appRepo) { Set(inGameUi); Set(appRepo); } - - public override IState GetInitialState(IContext context) => - new State(context); } diff --git a/src/jumpshroom/state/JumpshroomLogic.State.cs b/src/jumpshroom/state/JumpshroomLogic.State.cs index d9e8f73..3f08c14 100644 --- a/src/jumpshroom/state/JumpshroomLogic.State.cs +++ b/src/jumpshroom/state/JumpshroomLogic.State.cs @@ -5,6 +5,5 @@ namespace GameDemo; public partial class JumpshroomLogic : LogicBlock { public interface IState : IStateLogic { } - public abstract partial record State(IContext Context) : - StateLogic(Context), IState; + public abstract partial record State : StateLogic, IState; } diff --git a/src/jumpshroom/state/JumpshroomLogic.cs b/src/jumpshroom/state/JumpshroomLogic.cs index 57a79de..0326085 100644 --- a/src/jumpshroom/state/JumpshroomLogic.cs +++ b/src/jumpshroom/state/JumpshroomLogic.cs @@ -7,8 +7,7 @@ public interface IJumpshroomLogic : ILogicBlock { } [StateMachine] public partial class JumpshroomLogic : LogicBlock, IJumpshroomLogic { - public override State GetInitialState(IContext context) => - new State.Idle(context); + public override State GetInitialState() => new State.Idle(); public JumpshroomLogic(Data data, IAppRepo appRepo) { Set(data); diff --git a/src/jumpshroom/state/states/JumpshroomLogic.State.Cooldown.cs b/src/jumpshroom/state/states/JumpshroomLogic.State.Cooldown.cs index 575b13b..0c74c55 100644 --- a/src/jumpshroom/state/states/JumpshroomLogic.State.Cooldown.cs +++ b/src/jumpshroom/state/states/JumpshroomLogic.State.Cooldown.cs @@ -5,13 +5,13 @@ namespace GameDemo; public partial class JumpshroomLogic : LogicBlock { public partial record State { public record Cooldown : State, IGet { - public Cooldown(IContext context) : base(context) { + public Cooldown() { OnEnter( (previous) => Context.Output(new Output.StartCooldownTimer()) ); } - public IState On(Input.CooldownCompleted input) => new Idle(Context); + public IState On(Input.CooldownCompleted input) => new Idle(); } } } diff --git a/src/jumpshroom/state/states/JumpshroomLogic.State.Idle.cs b/src/jumpshroom/state/states/JumpshroomLogic.State.Idle.cs index 497e297..b98d642 100644 --- a/src/jumpshroom/state/states/JumpshroomLogic.State.Idle.cs +++ b/src/jumpshroom/state/states/JumpshroomLogic.State.Idle.cs @@ -4,10 +4,9 @@ namespace GameDemo; public partial class JumpshroomLogic : LogicBlock { public partial record State { - public record Idle(IContext Context) : State(Context), - IGet { + public record Idle : State, IGet { public IState On(Input.Hit input) { - return new Loading(Context, input.Target); + return new Loading(input.Target); } } } diff --git a/src/jumpshroom/state/states/JumpshroomLogic.State.Launching.cs b/src/jumpshroom/state/states/JumpshroomLogic.State.Launching.cs index 157dd90..12cf32e 100644 --- a/src/jumpshroom/state/states/JumpshroomLogic.State.Launching.cs +++ b/src/jumpshroom/state/states/JumpshroomLogic.State.Launching.cs @@ -7,17 +7,17 @@ public partial class JumpshroomLogic : LogicBlock { public partial record State { public record Launching : State, IGet { public IPushEnabled Target { get; } - public Launching(IContext context, IPushEnabled target) : base(context) { + public Launching(IPushEnabled target) { Target = target; - OnEnter((previous) => { - var data = Context.Get(); - // We are colliding with something we can push at the moment of - // launch, so push it. - Target.Push(Vector3.Up * data.ImpulseStrength); - }); + + // We are colliding with something we can push at the moment of + // launch, so push it. + OnEnter( + (previous) => Target.Push(Vector3.Up * Get().ImpulseStrength) + ); } - public IState On(Input.LaunchCompleted input) => new Cooldown(Context); + public IState On(Input.LaunchCompleted input) => new Cooldown(); } } } diff --git a/src/jumpshroom/state/states/JumpshroomLogic.State.Loading.cs b/src/jumpshroom/state/states/JumpshroomLogic.State.Loading.cs index c2b9ad2..5499d25 100644 --- a/src/jumpshroom/state/states/JumpshroomLogic.State.Loading.cs +++ b/src/jumpshroom/state/states/JumpshroomLogic.State.Loading.cs @@ -6,20 +6,18 @@ public partial class JumpshroomLogic : LogicBlock { public partial record State { public record Loading : State, IGet { public IPushEnabled Target { get; } - public Loading(IContext context, IPushEnabled target) : base(context) { + public Loading(IPushEnabled target) { Target = target; - var appRepo = context.Get(); - OnEnter((previous) => { - appRepo.OnJumpshroomUsed(); + Get().OnJumpshroomUsed(); Context.Output(new Output.Animate()); }); } public IState On(Input.Launch input) { // Springy top is fully compressed, so it is ready to launch. - return new Launching(Context, Target); + return new Launching(Target); } } } diff --git a/src/player/state/PlayerLogic.State.cs b/src/player/state/PlayerLogic.State.cs index cdbff5f..1d00706 100644 --- a/src/player/state/PlayerLogic.State.cs +++ b/src/player/state/PlayerLogic.State.cs @@ -3,7 +3,5 @@ namespace GameDemo; public partial class PlayerLogic { public interface IState : IStateLogic { } - public abstract partial record State : StateLogic, IState { - public State(IContext context) : base(context) { } - } + public abstract partial record State : StateLogic, IState { } } diff --git a/src/player/state/PlayerLogic.cs b/src/player/state/PlayerLogic.cs index 01c7d2d..67be215 100644 --- a/src/player/state/PlayerLogic.cs +++ b/src/player/state/PlayerLogic.cs @@ -7,8 +7,7 @@ public interface IPlayerLogic : ILogicBlock { } [StateMachine] public partial class PlayerLogic : LogicBlock, IPlayerLogic { - public override IState GetInitialState(IContext context) => - new State.Disabled(Context); + public override IState GetInitialState() => new State.Disabled(); public PlayerLogic( IPlayer player, Settings settings, IAppRepo appRepo, IGameRepo gameRepo diff --git a/src/player/state/states/PlayerLogic.State.Alive.Airborne.Falling.cs b/src/player/state/states/PlayerLogic.State.Alive.Airborne.Falling.cs index 4a388c5..8e3c7fe 100644 --- a/src/player/state/states/PlayerLogic.State.Alive.Airborne.Falling.cs +++ b/src/player/state/states/PlayerLogic.State.Alive.Airborne.Falling.cs @@ -3,7 +3,7 @@ namespace GameDemo; public partial class PlayerLogic { public abstract partial record State { public record Falling : Airborne { - public Falling(IContext context) : base(context) { + public Falling() { OnEnter( (previous) => Context.Output(new Output.Animations.Fall()) ); diff --git a/src/player/state/states/PlayerLogic.State.Alive.Airborne.Jumping.cs b/src/player/state/states/PlayerLogic.State.Alive.Airborne.Jumping.cs index 0380288..15c687d 100644 --- a/src/player/state/states/PlayerLogic.State.Alive.Airborne.Jumping.cs +++ b/src/player/state/states/PlayerLogic.State.Alive.Airborne.Jumping.cs @@ -3,13 +3,11 @@ namespace GameDemo; public partial class PlayerLogic { public abstract partial record State { public record Jumping : Airborne, IGet { - public Jumping(IContext context) : base(context) { - var appRepo = context.Get(); - + public Jumping() { OnEnter( (previous) => { Context.Output(new Output.Animations.Jump()); - appRepo.Jump(); + Get().Jump(); } ); } diff --git a/src/player/state/states/PlayerLogic.State.Alive.Airborne.Liftoff.cs b/src/player/state/states/PlayerLogic.State.Alive.Airborne.Liftoff.cs index d405c0b..fcb807c 100644 --- a/src/player/state/states/PlayerLogic.State.Alive.Airborne.Liftoff.cs +++ b/src/player/state/states/PlayerLogic.State.Alive.Airborne.Liftoff.cs @@ -9,7 +9,7 @@ public abstract partial record State { /// jump. /// public record Liftoff : Airborne { - public Liftoff(IContext context) : base(context) { + public Liftoff() { OnEnter( (previous) => Context.Output(new Output.Animations.Jump()) ); diff --git a/src/player/state/states/PlayerLogic.State.Alive.Airborne.cs b/src/player/state/states/PlayerLogic.State.Alive.Airborne.cs index 7286263..7d0dd7b 100644 --- a/src/player/state/states/PlayerLogic.State.Alive.Airborne.cs +++ b/src/player/state/states/PlayerLogic.State.Alive.Airborne.cs @@ -4,16 +4,14 @@ public partial class PlayerLogic { public abstract partial record State { public record Airborne : Alive, IGet, IGet { - public Airborne(IContext context) : base(context) { } - public IState On(Input.HitFloor input) { if (input.IsMovingHorizontally) { - return new Moving(Context); + return new Moving(); } - return new Idle(Context); + return new Idle(); } - public IState On(Input.StartedFalling input) => new Falling(Context); + public IState On(Input.StartedFalling input) => new Falling(); } } } diff --git a/src/player/state/states/PlayerLogic.State.Alive.Grounded.Idle.cs b/src/player/state/states/PlayerLogic.State.Alive.Grounded.Idle.cs index 4eaebc5..60d949b 100644 --- a/src/player/state/states/PlayerLogic.State.Alive.Grounded.Idle.cs +++ b/src/player/state/states/PlayerLogic.State.Alive.Grounded.Idle.cs @@ -3,14 +3,13 @@ namespace GameDemo; public partial class PlayerLogic { public abstract partial record State { public record Idle : Grounded, IGet { - public Idle(IContext context) : base(context) { + public Idle() { OnEnter( (previous) => Context.Output(new Output.Animations.Idle()) ); } - public IState On(Input.StartedMovingHorizontally input) => - new Moving(Context); + public IState On(Input.StartedMovingHorizontally input) => new Moving(); } } } diff --git a/src/player/state/states/PlayerLogic.State.Alive.Grounded.Moving.cs b/src/player/state/states/PlayerLogic.State.Alive.Grounded.Moving.cs index 36ac54b..d82a2bc 100644 --- a/src/player/state/states/PlayerLogic.State.Alive.Grounded.Moving.cs +++ b/src/player/state/states/PlayerLogic.State.Alive.Grounded.Moving.cs @@ -3,14 +3,13 @@ namespace GameDemo; public partial class PlayerLogic { public abstract partial record State { public record Moving : Grounded, IGet { - public Moving(IContext context) : base(context) { + public Moving() { OnEnter( (previous) => Context.Output(new Output.Animations.Move()) ); } - public IState On(Input.StoppedMovingHorizontally input) => - new Idle(Context); + public IState On(Input.StoppedMovingHorizontally input) => new Idle(); } } } diff --git a/src/player/state/states/PlayerLogic.State.Alive.Grounded.cs b/src/player/state/states/PlayerLogic.State.Alive.Grounded.cs index 00ec9e5..5f5d127 100644 --- a/src/player/state/states/PlayerLogic.State.Alive.Grounded.cs +++ b/src/player/state/states/PlayerLogic.State.Alive.Grounded.cs @@ -2,10 +2,7 @@ namespace GameDemo; public partial class PlayerLogic { public abstract partial record State { - public record Grounded : Alive, - IGet, IGet { - public Grounded(IContext context) : base(context) { } - + public record Grounded : Alive, IGet, IGet { public virtual IState On(Input.Jump input) { // We can jump from any grounded state if the jump button was just // pressed. @@ -18,16 +15,16 @@ public virtual IState On(Input.Jump input) { velocity.Y += settings.JumpImpulseForce; Context.Output(new Output.VelocityChanged(velocity)); - return new Jumping(Context); + return new Jumping(); } public IState On(Input.LeftFloor input) { if (input.IsFalling) { - return new Falling(Context); + return new Falling(); } // We got pushed into the air by something that isn't the player's jump // input, so we have a separate state for that. - return new Liftoff(Context); + return new Liftoff(); } } } diff --git a/src/player/state/states/PlayerLogic.State.Alive.cs b/src/player/state/states/PlayerLogic.State.Alive.cs index 0639346..e5b8d57 100644 --- a/src/player/state/states/PlayerLogic.State.Alive.cs +++ b/src/player/state/states/PlayerLogic.State.Alive.cs @@ -8,8 +8,6 @@ public record Alive : State, IGet, IGet, IGet { - public Alive(IContext context) : base(context) { } - // Movement is allowed in any state (even in the air), so these inputs // handle movement for each substate unless overridden. // @@ -22,7 +20,7 @@ public virtual IState On(Input.Killed input) { appRepo.OnGameEnded(GameOverReason.PlayerDied); - return new Dead(Context); + return new Dead(); } public virtual IState On(Input.PhysicsTick input) { diff --git a/src/player/state/states/PlayerLogic.State.Dead.cs b/src/player/state/states/PlayerLogic.State.Dead.cs index 34c1862..c3348aa 100644 --- a/src/player/state/states/PlayerLogic.State.Dead.cs +++ b/src/player/state/states/PlayerLogic.State.Dead.cs @@ -2,8 +2,6 @@ namespace GameDemo; public partial class PlayerLogic { public abstract partial record State { - public record Dead : State { - public Dead(IContext context) : base(context) { } - } + public record Dead : State; } } diff --git a/src/player/state/states/PlayerLogic.State.Disabled.cs b/src/player/state/states/PlayerLogic.State.Disabled.cs index 03025da..d1f2144 100644 --- a/src/player/state/states/PlayerLogic.State.Disabled.cs +++ b/src/player/state/states/PlayerLogic.State.Disabled.cs @@ -3,22 +3,16 @@ namespace GameDemo; public partial class PlayerLogic { public abstract partial record State : StateLogic, IState { public record Disabled : State, IGet { - public Disabled(IContext context) : base(context) { - var appRepo = Context.Get(); - + public Disabled() { OnEnter( - (previous) => { - Context.Output(new Output.Animations.Idle()); - appRepo.GameStarting += OnGameAboutToStart; - } + (previous) => Context.Output(new Output.Animations.Idle()) ); - OnExit( - (next) => appRepo.GameStarting -= OnGameAboutToStart - ); + OnAttach(() => Get().GameStarting += OnGameAboutToStart); + OnDetach(() => Get().GameStarting -= OnGameAboutToStart); } - public IState On(Input.Enable input) => new Idle(Context); + public IState On(Input.Enable input) => new Idle(); } public void OnGameAboutToStart() => Context.Input(new Input.Enable()); diff --git a/src/player_camera/State/PlayerCameraLogic.State.cs b/src/player_camera/State/PlayerCameraLogic.State.cs index 94caa97..bc4a948 100644 --- a/src/player_camera/State/PlayerCameraLogic.State.cs +++ b/src/player_camera/State/PlayerCameraLogic.State.cs @@ -13,21 +13,18 @@ public partial record State IGet, IGet, IGet { - public State(IContext context) : base(context) { - var gameRepo = Context.Get(); - var appRepo = Context.Get(); - - OnEnter( - (previous) => { - appRepo.IsMouseCaptured.Sync += OnMouseCaptured; - gameRepo.PlayerGlobalPosition.Sync += OnPlayerGlobalPositionChanged; + public State() { + OnAttach( + () => { + Get().IsMouseCaptured.Sync += OnMouseCaptured; + Get().PlayerGlobalPosition.Sync += OnPlayerGlobalPositionChanged; } ); - OnExit( - (next) => { - appRepo.IsMouseCaptured.Sync -= OnMouseCaptured; - gameRepo.PlayerGlobalPosition.Sync -= OnPlayerGlobalPositionChanged; + OnDetach( + () => { + Get().IsMouseCaptured.Sync -= OnMouseCaptured; + Get().PlayerGlobalPosition.Sync -= OnPlayerGlobalPositionChanged; } ); } diff --git a/src/player_camera/State/PlayerCameraLogic.cs b/src/player_camera/State/PlayerCameraLogic.cs index 5ee307a..e3849d9 100644 --- a/src/player_camera/State/PlayerCameraLogic.cs +++ b/src/player_camera/State/PlayerCameraLogic.cs @@ -9,8 +9,7 @@ public interface IPlayerCameraLogic : ILogicBlock { } [StateMachine] public partial class PlayerCameraLogic : LogicBlock, IPlayerCameraLogic { - public override IState GetInitialState(IContext context) => - new State.InputDisabled(context); + public override IState GetInitialState() => new State.InputDisabled(); public PlayerCameraLogic( IPlayerCamera camera, diff --git a/src/player_camera/State/states/PlayerCameraLogic.State.InputDisabled.cs b/src/player_camera/State/states/PlayerCameraLogic.State.InputDisabled.cs index eb15c1e..4e31f42 100644 --- a/src/player_camera/State/states/PlayerCameraLogic.State.InputDisabled.cs +++ b/src/player_camera/State/states/PlayerCameraLogic.State.InputDisabled.cs @@ -2,9 +2,8 @@ namespace GameDemo; public partial class PlayerCameraLogic { public partial record State { - public record InputDisabled(IContext Context) : State(Context), - IGet { - public IState On(Input.EnableInput input) => new InputEnabled(Context); + public record InputDisabled : State, IGet { + public IState On(Input.EnableInput input) => new InputEnabled(); } } } diff --git a/src/player_camera/State/states/PlayerCameraLogic.State.InputEnabled.cs b/src/player_camera/State/states/PlayerCameraLogic.State.InputEnabled.cs index da743a5..f20b9ed 100644 --- a/src/player_camera/State/states/PlayerCameraLogic.State.InputEnabled.cs +++ b/src/player_camera/State/states/PlayerCameraLogic.State.InputEnabled.cs @@ -5,10 +5,9 @@ namespace GameDemo; public partial class PlayerCameraLogic { public partial record State { /// The state of the player camera. - /// Logic block context. - public record InputEnabled(IContext Context) : State(Context), - IGet, IGet { - public IState On(Input.DisableInput input) => new InputDisabled(Context); + public record InputEnabled : State, + IGet, IGet { + public IState On(Input.DisableInput input) => new InputDisabled(); public IState On(Input.MouseInputOccurred input) { var settings = Context.Get(); diff --git a/test/src/app/state/AppLogic.StateTest.cs b/test/src/app/state/AppLogicStateTest.cs similarity index 83% rename from test/src/app/state/AppLogic.StateTest.cs rename to test/src/app/state/AppLogicStateTest.cs index b8950bc..a0f2ce1 100644 --- a/test/src/app/state/AppLogic.StateTest.cs +++ b/test/src/app/state/AppLogicStateTest.cs @@ -2,12 +2,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotCollections; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class AppLogicStateTest : TestClass { - private AppLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private AppLogic.State _state = default!; @@ -15,26 +16,26 @@ public AppLogicStateTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = AppLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] - public void EntersAndExits() { + public void Subscribes() { var isMouseCaptured = new Mock>(); _appRepo.Setup(repo => repo.IsMouseCaptured) .Returns(isMouseCaptured.Object); - _state.Enter(); + _state.Attach(_context); _appRepo.VerifyAdd( repo => repo.IsMouseCaptured.Sync += _state.OnMouseCaptured ); - _state.Exit(); + _state.Detach(); _appRepo.VerifyRemove( repo => repo.IsMouseCaptured.Sync -= _state.OnMouseCaptured diff --git a/test/src/app/state/AppLogicTest.cs b/test/src/app/state/AppLogicTest.cs index 45a5990..79833d1 100644 --- a/test/src/app/state/AppLogicTest.cs +++ b/test/src/app/state/AppLogicTest.cs @@ -19,11 +19,9 @@ public void Setup() { [Test] public void Initializes() { _logic.Get().ShouldBe(_appRepo.Object); - var context = AppLogic.CreateFakeContext(); - context.Set(_appRepo.Object); _logic - .GetInitialState(context) + .GetInitialState() .ShouldBeAssignableTo(); } } diff --git a/test/src/app/state/states/LeavingMenuTest.cs b/test/src/app/state/states/LeavingMenuTest.cs index c743091..e11ab31 100644 --- a/test/src/app/state/states/LeavingMenuTest.cs +++ b/test/src/app/state/states/LeavingMenuTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class LeavingMenuTest : TestClass { - private AppLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private AppLogic.State.LeavingMenu _state = default!; @@ -14,16 +15,16 @@ public LeavingMenuTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = AppLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] public void Enters() { - var parent = new AppLogic.State(_context); + var parent = new AppLogic.State(); _state.Enter(parent); diff --git a/test/src/app/state/states/MainMenuTest.cs b/test/src/app/state/states/MainMenuTest.cs index 5f343ca..7a7eb6b 100644 --- a/test/src/app/state/states/MainMenuTest.cs +++ b/test/src/app/state/states/MainMenuTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class MainMenuTest : TestClass { - private AppLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private AppLogic.State.MainMenu _state = default!; @@ -14,16 +15,16 @@ public MainMenuTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = AppLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] public void Enters() { - var parent = new AppLogic.State(_context); + var parent = new AppLogic.State(); _state.Enter(parent); diff --git a/test/src/app/state/states/RestartingGameTest.cs b/test/src/app/state/states/RestartingGameTest.cs index c38a3f1..23aa2ba 100644 --- a/test/src/app/state/states/RestartingGameTest.cs +++ b/test/src/app/state/states/RestartingGameTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class RestartingGameTest : TestClass { - private AppLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private AppLogic.State.RestartingGame _state = default!; @@ -14,16 +15,16 @@ public RestartingGameTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = AppLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] public void EntersAndExits() { - var parent = new AppLogic.State(_context); + var parent = new AppLogic.State(); _state.Enter(parent); diff --git a/test/src/app/state/states/SplashScreenTest.cs b/test/src/app/state/states/SplashScreenTest.cs index 7eeddbf..52e9cd0 100644 --- a/test/src/app/state/states/SplashScreenTest.cs +++ b/test/src/app/state/states/SplashScreenTest.cs @@ -1,36 +1,35 @@ namespace GameDemo.Tests; +using Chickensoft.GoDotCollections; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class SplashScreenTest : TestClass { - private AppLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private AppLogic.State.SplashScreen _state = default!; + private AutoProp _isMouseCaptured = default!; public SplashScreenTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = AppLogic.CreateFakeContext(); _appRepo = new(); + _isMouseCaptured = new(false); + _appRepo.Setup(repo => repo.IsMouseCaptured) + .Returns(_isMouseCaptured); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] - public void EntersAndExits() { - // We pass an instance of our parent class to the enter method as the - // previous state so that we don't have to run its entrance callbacks - // (that class has its own unit tests). Telling LogicBlocks that it was the - // previous state means that we've already "entered" that part of the state - // hierarchy. - var parent = new AppLogic.State(_context); - - _state.Enter(parent); + public void Subscribes() { + _state.Attach(_context); _appRepo.VerifyAdd( repo => repo.SplashScreenSkipped += _state.OnSplashScreenSkipped @@ -39,7 +38,7 @@ public void EntersAndExits() { // Likewise, we pass the parent class to the exit method as the next state // to prevent us from "leaving" the current state, which prevents the parent // exit callbacks from running. - _state.Exit(parent); + _state.Detach(); _appRepo.VerifyRemove( repo => repo.SplashScreenSkipped -= _state.OnSplashScreenSkipped diff --git a/test/src/app/state/states/in_game/GamePausedTest.cs b/test/src/app/state/states/in_game/GamePausedTest.cs index 7dbe250..6f0ced5 100644 --- a/test/src/app/state/states/in_game/GamePausedTest.cs +++ b/test/src/app/state/states/in_game/GamePausedTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class GamePausedTest : TestClass { - private AppLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private AppLogic.State.GamePaused _state = default!; @@ -14,16 +15,16 @@ public GamePausedTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = AppLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] public void EntersAndExits() { - var parent = new AppLogic.State.InGame(_context); + var parent = new AppLogic.State.InGame(); _appRepo.Setup((repo) => repo.Pause()); diff --git a/test/src/app/state/states/in_game/InGameTest.cs b/test/src/app/state/states/in_game/InGameTest.cs index 9614f4a..c04216b 100644 --- a/test/src/app/state/states/in_game/InGameTest.cs +++ b/test/src/app/state/states/in_game/InGameTest.cs @@ -1,44 +1,55 @@ namespace GameDemo.Tests; using System; +using Chickensoft.GoDotCollections; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class InGameTest : TestClass { - private AppLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private AppLogic.State.InGame _state = default!; + private AutoProp _isMouseCaptured = default!; public InGameTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = AppLogic.CreateFakeContext(); _appRepo = new(); + _isMouseCaptured = new(false); + _appRepo.Setup(repo => repo.IsMouseCaptured) + .Returns(_isMouseCaptured); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] public void EntersAndExits() { - var parent = new AppLogic.State(_context); + _appRepo.Reset(); _appRepo.Setup(repo => repo.OnStartGame()); + var parent = new AppLogic.State(); _state.Enter(parent); + _appRepo.VerifyAll(); + _context.Outputs.ShouldBe( new object[] { new AppLogic.Output.ShowGame() } ); - _appRepo.VerifyAdd(repo => repo.GameEnded += _state.OnGameOver); - - _context.Reset(); + } - _state.Exit(parent); + [Test] + public void Subscribes() { + _state.Attach(_context); + _appRepo.VerifyAdd(repo => repo.GameEnded += _state.OnGameOver); + _state.Detach(); _appRepo.VerifyRemove(repo => repo.GameEnded -= _state.OnGameOver); } diff --git a/test/src/app/state/states/in_game/LeavingGameTest.cs b/test/src/app/state/states/in_game/LeavingGameTest.cs index 7d035c4..2b37887 100644 --- a/test/src/app/state/states/in_game/LeavingGameTest.cs +++ b/test/src/app/state/states/in_game/LeavingGameTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class LeavingGameTest : TestClass { - private AppLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private AppLogic.State.LeavingGame _state = default!; @@ -14,16 +15,16 @@ public LeavingGameTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = AppLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] public void EntersAndExits() { - var parent = new AppLogic.State.InGame(_context); + var parent = new AppLogic.State.InGame(); _state.Enter(parent); _context.Outputs.ShouldBe( diff --git a/test/src/app/state/states/in_game/LostGameTest.cs b/test/src/app/state/states/in_game/LostGameTest.cs index 7263b07..818deda 100644 --- a/test/src/app/state/states/in_game/LostGameTest.cs +++ b/test/src/app/state/states/in_game/LostGameTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class LostGameTest : TestClass { - private AppLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private AppLogic.State.LostGame _state = default!; @@ -14,16 +15,16 @@ public LostGameTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = AppLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] public void Enters() { - var parent = new AppLogic.State.InGame(_context); + var parent = new AppLogic.State.InGame(); _state.Enter(parent); diff --git a/test/src/app/state/states/in_game/PlayingGameTest.cs b/test/src/app/state/states/in_game/PlayingGameTest.cs index e1b22d6..f3cfaf8 100644 --- a/test/src/app/state/states/in_game/PlayingGameTest.cs +++ b/test/src/app/state/states/in_game/PlayingGameTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class PlayingGameTest : TestClass { - private AppLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private AppLogic.State.PlayingGame _state = default!; @@ -14,11 +15,11 @@ public PlayingGameTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = AppLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] diff --git a/test/src/app/state/states/in_game/ResumingGameTest.cs b/test/src/app/state/states/in_game/ResumingGameTest.cs index 1bcf7f0..1a9ef6f 100644 --- a/test/src/app/state/states/in_game/ResumingGameTest.cs +++ b/test/src/app/state/states/in_game/ResumingGameTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class ResumingGameTest : TestClass { - private AppLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private AppLogic.State.ResumingGame _state = default!; @@ -14,16 +15,16 @@ public ResumingGameTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = AppLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] public void EntersAndExits() { - var parent = new AppLogic.State.InGame(_context); + var parent = new AppLogic.State.InGame(); _appRepo.Setup((repo) => repo.Resume()); diff --git a/test/src/app/state/states/in_game/WonGameTest.cs b/test/src/app/state/states/in_game/WonGameTest.cs index a334266..06d0239 100644 --- a/test/src/app/state/states/in_game/WonGameTest.cs +++ b/test/src/app/state/states/in_game/WonGameTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class WonGameTest : TestClass { - private AppLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private AppLogic.State.WonGame _state = default!; @@ -14,16 +15,16 @@ public WonGameTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = AppLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] public void Enters() { - var parent = new AppLogic.State.InGame(_context); + var parent = new AppLogic.State.InGame(); _state.Enter(parent); diff --git a/test/src/coin/state/CoinLogicTest.cs b/test/src/coin/state/CoinLogicTest.cs index a6b3a97..f317287 100644 --- a/test/src/coin/state/CoinLogicTest.cs +++ b/test/src/coin/state/CoinLogicTest.cs @@ -26,11 +26,8 @@ public void Initializes() { _logic.Get().ShouldBe(_coin.Object); _logic.Get().ShouldBe(_settings); - var context = CoinLogic.CreateFakeContext(); - context.Set(_appRepo.Object); - _logic - .GetInitialState(context) + .GetInitialState() .ShouldBeAssignableTo(); } } diff --git a/test/src/coin/state/states/CoinLogic.State.CollectingTest.cs b/test/src/coin/state/states/CoinLogic.State.CollectingTest.cs index 3f28f2a..9d70a7e 100644 --- a/test/src/coin/state/states/CoinLogic.State.CollectingTest.cs +++ b/test/src/coin/state/states/CoinLogic.State.CollectingTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class CoinLogicStateCollectingTest : TestClass { - private CoinLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private CoinLogic.Settings _settings = default!; private Mock _coin = default!; @@ -17,18 +18,17 @@ public CoinLogicStateCollectingTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = CoinLogic.CreateFakeContext(); - _appRepo = new(); _settings = new(1.0f); _coin = new(); _target = new(); + _state = new(_target.Object); + _context = _state.CreateFakeContext(); + _context.Set(_settings); _context.Set(_appRepo.Object); _context.Set(_coin.Object); - - _state = new(_context, _target.Object); } [Test] @@ -52,7 +52,7 @@ public void ComputesNextPositionOnPhysicsProcess() { _state.On(input).ShouldBe(_state); - _context.Outputs.ShouldBeOfTypes(new System.Type[] { + _context.Outputs.ShouldBeOfTypes(new[] { typeof(CoinLogic.Output.SelfDestruct), typeof(CoinLogic.Output.Move), }); diff --git a/test/src/coin/state/states/CoinLogic.State.IdleTest.cs b/test/src/coin/state/states/CoinLogic.State.IdleTest.cs index 5d09187..34e6073 100644 --- a/test/src/coin/state/states/CoinLogic.State.IdleTest.cs +++ b/test/src/coin/state/states/CoinLogic.State.IdleTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class CoinLogicStateIdleTest : TestClass { - private CoinLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private CoinLogic.State.Idle _state = default!; private Mock _appRepo = default!; private Mock _coin = default!; @@ -15,15 +16,14 @@ public CoinLogicStateIdleTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = CoinLogic.CreateFakeContext(); - _coin = new(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); + _context.Set(_coin.Object); _context.Set(_appRepo.Object); - - _state = new(_context); } [Test] diff --git a/test/src/game/state/GameLogic.StateTest.cs b/test/src/game/state/GameLogic.StateTest.cs index 5d2dd8a..7f175d0 100644 --- a/test/src/game/state/GameLogic.StateTest.cs +++ b/test/src/game/state/GameLogic.StateTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class GameLogicStateTest : TestClass { - private GameLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private GameLogic.State _state = default!; @@ -14,16 +15,16 @@ public GameLogicStateTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = GameLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] - public void EntersAndExits() { - _state.Enter(); + public void Subscribes() { + _state.Attach(_context); _appRepo.VerifyAdd( (repo) => repo.GameStarting += _state.GameAboutToStart @@ -35,7 +36,7 @@ public void EntersAndExits() { (repo) => repo.GameResumed += _state.GameResumed ); - _state.Exit(); + _state.Detach(); _appRepo.VerifyRemove( (repo) => repo.GameStarting -= _state.GameAboutToStart diff --git a/test/src/game/state/GameLogicTest.cs b/test/src/game/state/GameLogicTest.cs index d676fd8..818113a 100644 --- a/test/src/game/state/GameLogicTest.cs +++ b/test/src/game/state/GameLogicTest.cs @@ -20,11 +20,9 @@ public void Setup() { [Test] public void Initializes() { _logic.Get().ShouldBe(_appRepo.Object); - var context = GameLogic.CreateFakeContext(); - context.Set(_appRepo.Object); _logic - .GetInitialState(context) + .GetInitialState() .ShouldBeAssignableTo(); } } diff --git a/test/src/in_game_audio/state/InGameAudioLogic.StateTest.cs b/test/src/in_game_audio/state/InGameAudioLogic.StateTest.cs index 30b94bd..65ef856 100644 --- a/test/src/in_game_audio/state/InGameAudioLogic.StateTest.cs +++ b/test/src/in_game_audio/state/InGameAudioLogic.StateTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class InGameAudioLogicStateTest : TestClass { - private InGameAudioLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private InGameAudioLogic.State _state = default!; @@ -14,16 +15,16 @@ public InGameAudioLogicStateTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = InGameAudioLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] - public void EntersAndExits() { - _state.Enter(); + public void Subscribes() { + _state.Attach(_context); _appRepo.VerifyAdd( (repo) => repo.CoinCollected += _state.OnCoinCollected @@ -44,7 +45,7 @@ public void EntersAndExits() { (repo) => repo.GameStarting += _state.OnGameStarting ); - _state.Exit(); + _state.Detach(); _appRepo.VerifyRemove( (repo) => repo.CoinCollected -= _state.OnCoinCollected diff --git a/test/src/in_game_audio/state/InGameAudioLogicTest.cs b/test/src/in_game_audio/state/InGameAudioLogicTest.cs index 078ef1f..b8321fb 100644 --- a/test/src/in_game_audio/state/InGameAudioLogicTest.cs +++ b/test/src/in_game_audio/state/InGameAudioLogicTest.cs @@ -20,11 +20,9 @@ public void Setup() { [Test] public void Initializes() { _logic.Get().ShouldBe(_appRepo.Object); - var context = InGameAudioLogic.CreateFakeContext(); - context.Set(_appRepo.Object); _logic - .GetInitialState(context) + .GetInitialState() .ShouldBeAssignableTo(); } } diff --git a/test/src/in_game_ui/state/InGameUILogic.StateTest.cs b/test/src/in_game_ui/state/InGameUILogicStateTest.cs similarity index 89% rename from test/src/in_game_ui/state/InGameUILogic.StateTest.cs rename to test/src/in_game_ui/state/InGameUILogicStateTest.cs index 1c71830..881757f 100644 --- a/test/src/in_game_ui/state/InGameUILogic.StateTest.cs +++ b/test/src/in_game_ui/state/InGameUILogicStateTest.cs @@ -2,12 +2,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotCollections; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class InGameUILogicStateTest : TestClass { - private InGameUILogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _inGameUi = default!; private Mock _appRepo = default!; private InGameUILogic.State _state = default!; @@ -16,15 +17,14 @@ public InGameUILogicStateTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = InGameUILogic.CreateFakeContext(); - _inGameUi = new Mock(); _appRepo = new Mock(); + _state = new InGameUILogic.State(); + _context = _state.CreateFakeContext(); + _context.Set(_inGameUi.Object); _context.Set(_appRepo.Object); - - _state = new InGameUILogic.State(_context); } [Test] @@ -37,14 +37,14 @@ public void EntersAndExits() { _appRepo.Setup(repo => repo.NumCoinsAtStart) .Returns(numCoinsAtStart.Object); - _state.Enter(); + _state.Attach(_context); _appRepo .VerifyAdd(x => x.NumCoinsCollected.Sync += _state.OnNumCoinsCollected); _appRepo .VerifyAdd(x => x.NumCoinsAtStart.Sync += _state.OnNumCoinsAtStart); - _state.Exit(); + _state.Detach(); _appRepo .VerifyRemove(x => x.NumCoinsCollected.Sync -= _state.OnNumCoinsCollected); diff --git a/test/src/in_game_ui/state/InGameUILogicTest.cs b/test/src/in_game_ui/state/InGameUILogicTest.cs index bc7d52d..25ddf5d 100644 --- a/test/src/in_game_ui/state/InGameUILogicTest.cs +++ b/test/src/in_game_ui/state/InGameUILogicTest.cs @@ -25,13 +25,8 @@ public void Initializes() { _logic.Get().ShouldBe(_inGameUi.Object); _logic.Get().ShouldBe(_appRepo.Object); - var context = InGameUILogic.CreateFakeContext(); - - context.Set(_inGameUi.Object); - context.Set(_appRepo.Object); - _logic - .GetInitialState(context) + .GetInitialState() .ShouldBeAssignableTo(); } } diff --git a/test/src/jumpshroom/state/JumpshroomLogicTest.cs b/test/src/jumpshroom/state/JumpshroomLogicTest.cs index f8cab7e..a0833e0 100644 --- a/test/src/jumpshroom/state/JumpshroomLogicTest.cs +++ b/test/src/jumpshroom/state/JumpshroomLogicTest.cs @@ -25,13 +25,8 @@ public void Initializes() { _logic.Get().ShouldBe(_data); _logic.Get().ShouldBe(_appRepo.Object); - var context = JumpshroomLogic.CreateFakeContext(); - - context.Set(_data); - context.Set(_appRepo.Object); - _logic - .GetInitialState(context) + .GetInitialState() .ShouldBeAssignableTo(); } } diff --git a/test/src/jumpshroom/state/states/JumpshroomLogic.State.CooldownTest.cs b/test/src/jumpshroom/state/states/JumpshroomLogic.State.CooldownTest.cs index 1bf6e8e..2f54314 100644 --- a/test/src/jumpshroom/state/states/JumpshroomLogic.State.CooldownTest.cs +++ b/test/src/jumpshroom/state/states/JumpshroomLogic.State.CooldownTest.cs @@ -1,20 +1,20 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Shouldly; public class JumpshroomLogicStateCooldownTest : TestClass { - private JumpshroomLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private JumpshroomLogic.State.Cooldown _state = default!; public JumpshroomLogicStateCooldownTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = JumpshroomLogic.CreateFakeContext(); - - _state = new(_context); + _state = new(); + _context = _state.CreateFakeContext(); } [Test] diff --git a/test/src/jumpshroom/state/states/JumpshroomLogic.State.IdleTest.cs b/test/src/jumpshroom/state/states/JumpshroomLogic.State.IdleTest.cs index 5d75b24..315452e 100644 --- a/test/src/jumpshroom/state/states/JumpshroomLogic.State.IdleTest.cs +++ b/test/src/jumpshroom/state/states/JumpshroomLogic.State.IdleTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class JumpshroomLogicStateIdleTest : TestClass { - private JumpshroomLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private JumpshroomLogic.State.Idle _state = default!; @@ -14,12 +15,11 @@ public JumpshroomLogicStateIdleTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = JumpshroomLogic.CreateFakeContext(); _appRepo = new Mock(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - - _state = new(_context); } [Test] diff --git a/test/src/jumpshroom/state/states/JumpshroomLogic.State.LaunchingTest.cs b/test/src/jumpshroom/state/states/JumpshroomLogic.State.LaunchingTest.cs index d31734f..c69a4d7 100644 --- a/test/src/jumpshroom/state/states/JumpshroomLogic.State.LaunchingTest.cs +++ b/test/src/jumpshroom/state/states/JumpshroomLogic.State.LaunchingTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class JumpshroomLogicStateLaunchingTest : TestClass { - private JumpshroomLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _target = default!; private JumpshroomLogic.Data _data = default!; private JumpshroomLogic.State.Launching _state = default!; @@ -15,14 +16,13 @@ public JumpshroomLogicStateLaunchingTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = JumpshroomLogic.CreateFakeContext(); - _target = new Mock(); _data = new(1.0f); - _context.Set(_data); + _state = new(_target.Object); + _context = _state.CreateFakeContext(); - _state = new(_context, _target.Object); + _context.Set(_data); } [Test] diff --git a/test/src/jumpshroom/state/states/JumpshroomLogic.State.LoadingTest.cs b/test/src/jumpshroom/state/states/JumpshroomLogic.State.LoadingTest.cs index 18c7f96..63eca20 100644 --- a/test/src/jumpshroom/state/states/JumpshroomLogic.State.LoadingTest.cs +++ b/test/src/jumpshroom/state/states/JumpshroomLogic.State.LoadingTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class JumpshroomLogicStateLoadingTest : TestClass { - private JumpshroomLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _target = default!; private Mock _appRepo = default!; private JumpshroomLogic.Data _data = default!; @@ -16,16 +17,15 @@ public JumpshroomLogicStateLoadingTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = JumpshroomLogic.CreateFakeContext(); - _target = new Mock(); _appRepo = new Mock(); _data = new(1.0f); + _state = new(_target.Object); + _context = _state.CreateFakeContext(); + _context.Set(_appRepo.Object); _context.Set(_data); - - _state = new(_context, _target.Object); } [Test] diff --git a/test/src/player/state/PlayerLogicTest.cs b/test/src/player/state/PlayerLogicTest.cs index f7de9d1..fbf7fe1 100644 --- a/test/src/player/state/PlayerLogicTest.cs +++ b/test/src/player/state/PlayerLogicTest.cs @@ -31,12 +31,8 @@ public void Initializes() { _logic.Get().ShouldBe(_gameRepo.Object); _logic.Get().ShouldNotBeNull(); - var context = PlayerLogic.CreateFakeContext(); - - context.Set(_appRepo.Object); - _logic - .GetInitialState(context) + .GetInitialState() .ShouldBeAssignableTo(); } } diff --git a/test/src/player/state/states/PlayerLogic.State.Alive.Airborne.FallingTest.cs b/test/src/player/state/states/PlayerLogic.State.Alive.Airborne.FallingTest.cs index 64fa79e..780c065 100644 --- a/test/src/player/state/states/PlayerLogic.State.Alive.Airborne.FallingTest.cs +++ b/test/src/player/state/states/PlayerLogic.State.Alive.Airborne.FallingTest.cs @@ -1,12 +1,12 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; -using Moq; using Shouldly; public class PlayerLogicStateAliveAirborneFallingTest : TestClass { - private PlayerLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private PlayerLogic.State.Falling _state = default!; public PlayerLogicStateAliveAirborneFallingTest(Node testScene) : @@ -14,14 +14,13 @@ public PlayerLogicStateAliveAirborneFallingTest(Node testScene) : [Setup] public void Setup() { - _context = PlayerLogic.CreateFakeContext(); - _state = new(_context); + _state = new(); + _context = _state.CreateFakeContext(); } [Test] public void Enters() { - var parent = - new PlayerLogic.State.Airborne(new Mock().Object); + var parent = new PlayerLogic.State.Airborne(); _state.Enter(parent); diff --git a/test/src/player/state/states/PlayerLogic.State.Alive.Airborne.JumpingTest.cs b/test/src/player/state/states/PlayerLogic.State.Alive.Airborne.JumpingTest.cs index 03faded..eb020e3 100644 --- a/test/src/player/state/states/PlayerLogic.State.Alive.Airborne.JumpingTest.cs +++ b/test/src/player/state/states/PlayerLogic.State.Alive.Airborne.JumpingTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class PlayerLogicStateAliveAirborneJumpingTest : TestClass { - private PlayerLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _player = default!; private Mock _appRepo = default!; private PlayerLogic.Settings _settings = default!; @@ -17,23 +18,21 @@ public PlayerLogicStateAliveAirborneJumpingTest(Node testScene) : [Setup] public void Setup() { - _context = PlayerLogic.CreateFakeContext(); - _player = new Mock(); _appRepo = new Mock(); _settings = new PlayerLogic.Settings(1, 1, 1, 1, 1, 1, JumpForce: 1); + _state = new(); + _context = _state.CreateFakeContext(); + _context.Set(_player.Object); _context.Set(_appRepo.Object); _context.Set(_settings); - - _state = new(_context); } [Test] public void Enters() { - var parent = - new PlayerLogic.State.Airborne(new Mock().Object); + var parent = new PlayerLogic.State.Airborne(); _appRepo.Setup(repo => repo.Jump()); diff --git a/test/src/player/state/states/PlayerLogic.State.Alive.Airborne.LiftoffTest.cs b/test/src/player/state/states/PlayerLogic.State.Alive.Airborne.LiftoffTest.cs index d527274..cac0740 100644 --- a/test/src/player/state/states/PlayerLogic.State.Alive.Airborne.LiftoffTest.cs +++ b/test/src/player/state/states/PlayerLogic.State.Alive.Airborne.LiftoffTest.cs @@ -1,12 +1,12 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; -using Moq; using Shouldly; public class PlayerLogicStateAliveAirborneLiftoffTest : TestClass { - private PlayerLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private PlayerLogic.State.Liftoff _state = default!; public PlayerLogicStateAliveAirborneLiftoffTest(Node testScene) : @@ -14,14 +14,13 @@ public PlayerLogicStateAliveAirborneLiftoffTest(Node testScene) : [Setup] public void Setup() { - _context = PlayerLogic.CreateFakeContext(); - _state = new(_context); + _state = new(); + _context = _state.CreateFakeContext(); } [Test] public void Enters() { - var parent = - new PlayerLogic.State.Airborne(new Mock().Object); + var parent = new PlayerLogic.State.Airborne(); _state.Enter(parent); diff --git a/test/src/player/state/states/PlayerLogic.State.Alive.AirborneTest.cs b/test/src/player/state/states/PlayerLogic.State.Alive.AirborneTest.cs index 35cf176..72ab90c 100644 --- a/test/src/player/state/states/PlayerLogic.State.Alive.AirborneTest.cs +++ b/test/src/player/state/states/PlayerLogic.State.Alive.AirborneTest.cs @@ -5,7 +5,6 @@ namespace GameDemo.Tests; using Shouldly; public class PlayerLogicStateAliveAirborneTest : TestClass { - private PlayerLogic.IFakeContext _context = default!; private PlayerLogic.State.Falling _state = default!; public PlayerLogicStateAliveAirborneTest(Node testScene) : @@ -13,8 +12,7 @@ public PlayerLogicStateAliveAirborneTest(Node testScene) : [Setup] public void Setup() { - _context = PlayerLogic.CreateFakeContext(); - _state = new(_context); + _state = new(); } [Test] diff --git a/test/src/player/state/states/PlayerLogic.State.Alive.Grounded.IdleTest.cs b/test/src/player/state/states/PlayerLogic.State.Alive.Grounded.IdleTest.cs index 01a2d5c..7d6c5d0 100644 --- a/test/src/player/state/states/PlayerLogic.State.Alive.Grounded.IdleTest.cs +++ b/test/src/player/state/states/PlayerLogic.State.Alive.Grounded.IdleTest.cs @@ -1,12 +1,12 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; -using Moq; using Shouldly; public class PlayerLogicStateAliveGroundedIdleTest : TestClass { - private PlayerLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private PlayerLogic.State.Idle _state = default!; public PlayerLogicStateAliveGroundedIdleTest(Node testScene) : @@ -14,14 +14,14 @@ public PlayerLogicStateAliveGroundedIdleTest(Node testScene) : [Setup] public void Setup() { - _context = PlayerLogic.CreateFakeContext(); - _state = new(_context); + _state = new(); + _context = _state.CreateFakeContext(); } [Test] public void Enters() { var parent = - new PlayerLogic.State.Grounded(new Mock().Object); + new PlayerLogic.State.Grounded(); _state.Enter(parent); _context.Outputs.ShouldBe(new object[] { diff --git a/test/src/player/state/states/PlayerLogic.State.Alive.Grounded.MovingTest.cs b/test/src/player/state/states/PlayerLogic.State.Alive.Grounded.MovingTest.cs index f2eb2d3..e36fc74 100644 --- a/test/src/player/state/states/PlayerLogic.State.Alive.Grounded.MovingTest.cs +++ b/test/src/player/state/states/PlayerLogic.State.Alive.Grounded.MovingTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class PlayerLogicStateAliveGroundedMovingTest : TestClass { - private PlayerLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private PlayerLogic.State.Moving _state = default!; @@ -15,17 +16,16 @@ public PlayerLogicStateAliveGroundedMovingTest(Node testScene) : [Setup] public void Setup() { - _context = PlayerLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] public void Enters() { - var parent = - new PlayerLogic.State.Grounded(new Mock().Object); + var parent = new PlayerLogic.State.Grounded(); _state.Enter(parent); _context.Outputs.ShouldBe(new object[] { diff --git a/test/src/player/state/states/PlayerLogic.State.Alive.GroundedTest.cs b/test/src/player/state/states/PlayerLogic.State.Alive.GroundedTest.cs index 5e5105f..bd27b4b 100644 --- a/test/src/player/state/states/PlayerLogic.State.Alive.GroundedTest.cs +++ b/test/src/player/state/states/PlayerLogic.State.Alive.GroundedTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class PlayerLogicStateAliveGroundedTest : TestClass { - private PlayerLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _player = default!; private Mock _appRepo = default!; private PlayerLogic.Settings _settings = default!; @@ -17,17 +18,16 @@ public PlayerLogicStateAliveGroundedTest(Node testScene) : [Setup] public void Setup() { - _context = PlayerLogic.CreateFakeContext(); - _player = new Mock(); _appRepo = new Mock(); _settings = new PlayerLogic.Settings(1, 1, 1, 1, 1, 1, 1); + _state = new(); + _context = _state.CreateFakeContext(); + _context.Set(_player.Object); _context.Set(_appRepo.Object); _context.Set(_settings); - - _state = new(_context); } [Test] @@ -38,7 +38,7 @@ public void JumpGoesToJumping() { next.ShouldBeAssignableTo(); - _context.Outputs.ShouldBeOfTypes(new System.Type[] { + _context.Outputs.ShouldBeOfTypes(new[] { typeof(PlayerLogic.Output.VelocityChanged) }); } diff --git a/test/src/player/state/states/PlayerLogic.State.AliveTest.cs b/test/src/player/state/states/PlayerLogic.State.AliveTest.cs index 51fe7f1..2fd3df5 100644 --- a/test/src/player/state/states/PlayerLogic.State.AliveTest.cs +++ b/test/src/player/state/states/PlayerLogic.State.AliveTest.cs @@ -2,12 +2,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotCollections; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class PlayerLogicStateAliveTest : TestClass { - private PlayerLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private PlayerLogic.Data _data = default!; private Mock _player = default!; private PlayerLogic.Settings _settings = default!; @@ -20,21 +21,20 @@ public PlayerLogicStateAliveTest(Node testScene) : [Setup] public void Setup() { - _context = PlayerLogic.CreateFakeContext(); - _data = new(); _player = new Mock(); _settings = new PlayerLogic.Settings(1, 1, 1, 1, 1, 1, 1); _gameRepo = new Mock(); _appRepo = new Mock(); + _state = new(); + _context = _state.CreateFakeContext(); + _context.Set(_data); _context.Set(_player.Object); _context.Set(_settings); _context.Set(_gameRepo.Object); _context.Set(_appRepo.Object); - - _state = new(_context); } [Test] diff --git a/test/src/player/state/states/PlayerLogic.State.DeadTest.cs b/test/src/player/state/states/PlayerLogic.State.DeadTest.cs index 01d49fa..f6315e5 100644 --- a/test/src/player/state/states/PlayerLogic.State.DeadTest.cs +++ b/test/src/player/state/states/PlayerLogic.State.DeadTest.cs @@ -9,8 +9,7 @@ public PlayerLogicStateDeadTest(Node testScene) : base(testScene) { } [Test] public void Initializes() { - var context = PlayerLogic.CreateFakeContext(); - var state = new PlayerLogic.State.Dead(context); + var state = new PlayerLogic.State.Dead(); state.ShouldNotBeNull(); } diff --git a/test/src/player/state/states/PlayerLogic.State.DisabledTest.cs b/test/src/player/state/states/PlayerLogic.State.DisabledTest.cs index 03b7f26..6ff7549 100644 --- a/test/src/player/state/states/PlayerLogic.State.DisabledTest.cs +++ b/test/src/player/state/states/PlayerLogic.State.DisabledTest.cs @@ -1,12 +1,13 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class PlayerLogicStateDisabledTest : TestClass { - private PlayerLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private Mock _appRepo = default!; private PlayerLogic.State.Disabled _state = default!; @@ -14,27 +15,30 @@ public PlayerLogicStateDisabledTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { - _context = PlayerLogic.CreateFakeContext(); _appRepo = new(); + _state = new(); + _context = _state.CreateFakeContext(); _context.Set(_appRepo.Object); - _state = new(_context); } [Test] public void EntersAndExits() { _state.Enter(); - _appRepo.VerifyAdd( - (repo) => repo.GameStarting += _state.OnGameAboutToStart - ); - _context.Outputs.ShouldBe(new object[] { new PlayerLogic.Output.Animations.Idle() }); + } - _state.Exit(); + [Test] + public void Subscribes() { + _state.Attach(_context); + _appRepo.VerifyAdd( + (repo) => repo.GameStarting += _state.OnGameAboutToStart + ); + _state.Detach(); _appRepo.VerifyRemove( (repo) => repo.GameStarting -= _state.OnGameAboutToStart ); diff --git a/test/src/player_camera/state/PlayerCameraLogic.State.InputDisabledTest.cs b/test/src/player_camera/state/PlayerCameraLogic.State.InputDisabledTest.cs index 98dd2c3..dbcd72e 100644 --- a/test/src/player_camera/state/PlayerCameraLogic.State.InputDisabledTest.cs +++ b/test/src/player_camera/state/PlayerCameraLogic.State.InputDisabledTest.cs @@ -11,13 +11,13 @@ public PlayerCameraLogicStateInputDisabledTest(Node testScene) : [Test] public void GoesToInputEnabled() { - var context = PlayerCameraLogic.CreateFakeContext(); + var state = new PlayerCameraLogic.State.InputDisabled(); + var context = state.CreateFakeContext(); var gameRepo = new Mock(); var appRepo = new Mock(); context.Set(gameRepo.Object); context.Set(appRepo.Object); - var state = new PlayerCameraLogic.State.InputDisabled(context); var nextState = state.On(new PlayerCameraLogic.Input.EnableInput()); nextState.ShouldBeOfType(); diff --git a/test/src/player_camera/state/PlayerCameraLogic.State.InputEnabledTest.cs b/test/src/player_camera/state/PlayerCameraLogic.State.InputEnabledTest.cs index 88fee58..fb1809d 100644 --- a/test/src/player_camera/state/PlayerCameraLogic.State.InputEnabledTest.cs +++ b/test/src/player_camera/state/PlayerCameraLogic.State.InputEnabledTest.cs @@ -1,25 +1,28 @@ namespace GameDemo.Tests; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; public class PlayerCameraLogicStateInputEnabledTest : TestClass { - private PlayerCameraLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; private PlayerCameraSettings _settings = default!; private PlayerCameraLogic.Data _data = default!; private Mock _appRepo = default!; private Mock _gameRepo = default!; + private PlayerCameraLogic.State.InputEnabled _state = default!; public PlayerCameraLogicStateInputEnabledTest(Node testScene) : base(testScene) { } [Setup] public void Setup() { + _state = new(); + _context = _state.CreateFakeContext(); _settings = new(); _data = new(); - _context = PlayerCameraLogic.CreateFakeContext(); _appRepo = new(); _gameRepo = new(); @@ -37,16 +40,13 @@ public void Setup() { [Test] public void GoesToInputDisabled() { - var state = new PlayerCameraLogic.State.InputEnabled(_context); - var nextState = state.On(new PlayerCameraLogic.Input.DisableInput()); + var nextState = _state.On(new PlayerCameraLogic.Input.DisableInput()); nextState.ShouldBeOfType(); } [Test] public void UpdatesTargetAnglesWhenMouseInputOccurs() { - var state = new PlayerCameraLogic.State.InputEnabled(_context); - var targetAngleHorizontal = _data.TargetAngleHorizontal; var targetAngleVertical = _data.TargetAngleVertical; @@ -54,11 +54,11 @@ public void UpdatesTargetAnglesWhenMouseInputOccurs() { Relative = Vector2.One }; - var nextState = state.On( + var nextState = _state.On( new PlayerCameraLogic.Input.MouseInputOccurred(motion) ); - state.ShouldBeSameAs(nextState); + _state.ShouldBeSameAs(nextState); _data.TargetAngleHorizontal.ShouldNotBe(targetAngleHorizontal); _data.TargetAngleVertical.ShouldNotBe(targetAngleVertical); diff --git a/test/src/player_camera/state/PlayerCameraLogic.StateTest.cs b/test/src/player_camera/state/PlayerCameraLogic.StateTest.cs index 4c14e1a..b69515b 100644 --- a/test/src/player_camera/state/PlayerCameraLogic.StateTest.cs +++ b/test/src/player_camera/state/PlayerCameraLogic.StateTest.cs @@ -1,8 +1,8 @@ namespace GameDemo.Tests; -using System; using Chickensoft.GoDotCollections; using Chickensoft.GoDotTest; +using Chickensoft.LogicBlocks; using Godot; using Moq; using Shouldly; @@ -13,7 +13,8 @@ public class PlayerCameraLogicStateTest : TestClass { private Mock _appRepo = default!; private Mock _gameRepo = default!; private PlayerCameraLogic.Data _data = default!; - private PlayerCameraLogic.IFakeContext _context = default!; + private IFakeContext _context = default!; + private PlayerCameraLogic.State _state = default!; public PlayerCameraLogicStateTest(Node testScene) : base(testScene) { } @@ -24,7 +25,8 @@ public void Setup() { _appRepo = new(); _gameRepo = new(); _data = new(); - _context = PlayerCameraLogic.CreateFakeContext(); + _state = new(); + _context = _state.CreateFakeContext(); // Automatically mock the logic block context to provide mock versions // of everything the state needs. @@ -45,33 +47,29 @@ public void ListensToMouseAndPlayerPosition() { _gameRepo.Setup(repo => repo.PlayerGlobalPosition) .Returns(playerGlobalPosition.Object); - var state = new PlayerCameraLogic.State(_context); - - state.Enter(); + _state.Attach(_context); _appRepo - .VerifyAdd(repo => repo.IsMouseCaptured.Sync += state.OnMouseCaptured); + .VerifyAdd(repo => repo.IsMouseCaptured.Sync += _state.OnMouseCaptured); _gameRepo .VerifyAdd(repo => - repo.PlayerGlobalPosition.Sync += state.OnPlayerGlobalPositionChanged + repo.PlayerGlobalPosition.Sync += _state.OnPlayerGlobalPositionChanged ); - state.Exit(); + _state.Detach(); _appRepo - .VerifyRemove(repo => repo.IsMouseCaptured.Sync -= state.OnMouseCaptured); + .VerifyRemove(repo => repo.IsMouseCaptured.Sync -= _state.OnMouseCaptured); _gameRepo .VerifyRemove(repo => - repo.PlayerGlobalPosition.Sync -= state.OnPlayerGlobalPositionChanged + repo.PlayerGlobalPosition.Sync -= _state.OnPlayerGlobalPositionChanged ); } [Test] public void OnMouseCaptured() { - var state = new PlayerCameraLogic.State(_context); - // Make sure it enables input when mouse is captured. - state.OnMouseCaptured(true); + _state.OnMouseCaptured(true); _context.Inputs.ShouldBe(new object[] { new PlayerCameraLogic.Input.EnableInput() @@ -80,7 +78,7 @@ public void OnMouseCaptured() { _context.Reset(); // Make sure it disables input when mouse is not captured. - state.OnMouseCaptured(false); + _state.OnMouseCaptured(false); _context.Inputs.ShouldBe(new object[] { new PlayerCameraLogic.Input.DisableInput() @@ -89,10 +87,8 @@ public void OnMouseCaptured() { [Test] public void OnPlayerGlobalPositionChanged() { - var state = new PlayerCameraLogic.State(_context); - // Make sure it updates the camera position when the player moves. - state.OnPlayerGlobalPositionChanged(Vector3.Zero); + _state.OnPlayerGlobalPositionChanged(Vector3.Zero); _context.Inputs.ShouldBe(new object[] { new PlayerCameraLogic.Input.TargetPositionChanged(Vector3.Zero) @@ -101,10 +97,8 @@ public void OnPlayerGlobalPositionChanged() { [Test] public void OnCameraTargetOffsetChanged() { - var state = new PlayerCameraLogic.State(_context); - // Make sure it updates the camera offset when the player moves. - state.OnCameraTargetOffsetChanged(Vector3.Zero); + _state.OnCameraTargetOffsetChanged(Vector3.Zero); _context.Inputs.ShouldBe(new object[] { new PlayerCameraLogic.Input.TargetOffsetChanged(Vector3.Zero) @@ -136,13 +130,11 @@ public void OnPhysicsTicked() { _gameRepo.Setup(repo => repo.SetCameraBasis(It.IsAny())); - var state = new PlayerCameraLogic.State(_context); + var nextState = _state.On(new PlayerCameraLogic.Input.PhysicsTicked(1d)); - var nextState = state.On(new PlayerCameraLogic.Input.PhysicsTicked(1d)); + _state.ShouldBeSameAs(nextState); - state.ShouldBeSameAs(nextState); - - _context.Outputs.ShouldBeOfTypes(new Type[] { + _context.Outputs.ShouldBeOfTypes(new[] { typeof(PlayerCameraLogic.Output.GimbalRotationChanged), typeof(PlayerCameraLogic.Output.GlobalTransformChanged), typeof(PlayerCameraLogic.Output.CameraLocalPositionChanged), @@ -157,9 +149,7 @@ public void OnTargetPositionChanged() { var originalTargetPosition = _data.TargetPosition; var newTargetPosition = Vector3.Up; - var state = new PlayerCameraLogic.State(_context); - - state.On(new PlayerCameraLogic.Input.TargetPositionChanged( + _state.On(new PlayerCameraLogic.Input.TargetPositionChanged( newTargetPosition )); @@ -171,9 +161,7 @@ public void TargetOffsetChanged() { var originalTargetOffset = _data.TargetOffset; var newTargetOffset = Vector3.Up; - var state = new PlayerCameraLogic.State(_context); - - state.On(new PlayerCameraLogic.Input.TargetOffsetChanged( + _state.On(new PlayerCameraLogic.Input.TargetOffsetChanged( newTargetOffset )); diff --git a/test/src/player_camera/state/PlayerCameraLogicTest.cs b/test/src/player_camera/state/PlayerCameraLogicTest.cs index 6d45edb..149c318 100644 --- a/test/src/player_camera/state/PlayerCameraLogicTest.cs +++ b/test/src/player_camera/state/PlayerCameraLogicTest.cs @@ -39,11 +39,8 @@ public void Initializes() { _logic.Get().ShouldBe(_gameRepo.Object); _logic.Get().ShouldNotBeNull(); - var context = PlayerCameraLogic.CreateFakeContext(); - context.Set(_appRepo.Object); - context.Set(_gameRepo.Object); _logic - .GetInitialState(context) + .GetInitialState() .ShouldBeOfType(); // Test outputs