Move App logic to other projects
This commit is contained in:
46
Zennysoft.Game.Ma.Implementation/App/AppRepo.cs
Normal file
46
Zennysoft.Game.Ma.Implementation/App/AppRepo.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
public class AppRepo : IAppRepo
|
||||
{
|
||||
public event Action? SplashScreenSkipped;
|
||||
public event Action? MainMenuEntered;
|
||||
public event Action? GameEntered;
|
||||
public event Action? GameExited;
|
||||
|
||||
private bool _disposedValue;
|
||||
|
||||
public void SkipSplashScreen() => SplashScreenSkipped?.Invoke();
|
||||
|
||||
public void OnMainMenuEntered() => MainMenuEntered?.Invoke();
|
||||
|
||||
public void OnEnterGame() => GameEntered?.Invoke();
|
||||
|
||||
public void OnExitGame() => GameExited?.Invoke();
|
||||
|
||||
public void OnGameOver() => GameExited?.Invoke();
|
||||
|
||||
protected void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed objects.
|
||||
SplashScreenSkipped = null;
|
||||
MainMenuEntered = null;
|
||||
GameEntered = null;
|
||||
GameExited = null;
|
||||
}
|
||||
|
||||
_disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
public record Data
|
||||
{
|
||||
public bool ShouldLoadExistingGame { get; set; }
|
||||
}
|
||||
}
|
||||
24
Zennysoft.Game.Ma.Implementation/App/State/AppLogic.Input.cs
Normal file
24
Zennysoft.Game.Ma.Implementation/App/State/AppLogic.Input.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
public static class Input
|
||||
{
|
||||
public readonly record struct NewGame;
|
||||
|
||||
public readonly record struct LoadGame;
|
||||
|
||||
public readonly record struct LoadGameFinished;
|
||||
|
||||
public readonly record struct FadeInFinished;
|
||||
public readonly record struct FadeOutFinished;
|
||||
|
||||
public readonly record struct QuitGame;
|
||||
|
||||
public readonly record struct GameOver;
|
||||
|
||||
public readonly record struct ShowLoadingScreen;
|
||||
|
||||
public readonly record struct SaveFileLoaded;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
public static class Output
|
||||
{
|
||||
public readonly record struct FadeToBlack;
|
||||
|
||||
public readonly record struct ShowSplashScreen;
|
||||
|
||||
public readonly record struct HideSplashScreen;
|
||||
|
||||
public readonly record struct RemoveExistingGame;
|
||||
|
||||
public readonly record struct PlayGame;
|
||||
|
||||
public readonly record struct ShowGame;
|
||||
|
||||
public readonly record struct HideGame;
|
||||
|
||||
public readonly record struct SetupGameScene;
|
||||
|
||||
public readonly record struct ShowLoadingScreen;
|
||||
|
||||
public readonly record struct ShowMainMenu;
|
||||
|
||||
public readonly record struct ExitGame;
|
||||
|
||||
public readonly record struct GameOver;
|
||||
|
||||
public readonly record struct StartLoadingSaveFile;
|
||||
}
|
||||
}
|
||||
10
Zennysoft.Game.Ma.Implementation/App/State/AppLogic.State.cs
Normal file
10
Zennysoft.Game.Ma.Implementation/App/State/AppLogic.State.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
[Meta]
|
||||
public abstract partial record State : StateLogic<State>;
|
||||
}
|
||||
13
Zennysoft.Game.Ma.Implementation/App/State/AppLogic.cs
Normal file
13
Zennysoft.Game.Ma.Implementation/App/State/AppLogic.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
public interface IAppLogic : ILogicBlock<AppLogic.State>;
|
||||
|
||||
[Meta]
|
||||
[LogicBlock(typeof(State), Diagram = true)]
|
||||
public partial class AppLogic : LogicBlock<AppLogic.State>, IAppLogic
|
||||
{
|
||||
public override Transition GetInitialState() => To<State.SplashScreen>();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
public partial record State
|
||||
{
|
||||
[Meta]
|
||||
public partial record InGame : State, IGet<Input.GameOver>
|
||||
{
|
||||
public InGame()
|
||||
{
|
||||
|
||||
this.OnEnter(() =>
|
||||
{
|
||||
Output(new Output.ShowGame());
|
||||
Get<IAppRepo>().OnEnterGame();
|
||||
});
|
||||
this.OnExit(() => Output(new Output.HideGame()));
|
||||
|
||||
OnAttach(() => Get<IAppRepo>().GameExited += OnGameExited);
|
||||
OnDetach(() => Get<IAppRepo>().GameExited -= OnGameExited);
|
||||
}
|
||||
|
||||
public Transition On(in Input.GameOver input)
|
||||
{
|
||||
Output(new Output.RemoveExistingGame());
|
||||
return To<MainMenu>();
|
||||
}
|
||||
|
||||
public void OnGameExited() => Input(new Input.QuitGame());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
public partial record State
|
||||
{
|
||||
[Meta]
|
||||
public partial record LeavingMenu : State, IGet<Input.FadeOutFinished>
|
||||
{
|
||||
public LeavingMenu()
|
||||
{
|
||||
this.OnEnter(() => Output(new Output.FadeToBlack()));
|
||||
}
|
||||
|
||||
public Transition On(in Input.FadeOutFinished input) =>
|
||||
Get<Data>().ShouldLoadExistingGame
|
||||
? To<LoadingSaveFile>()
|
||||
: To<InGame>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
public partial record State
|
||||
{
|
||||
[Meta]
|
||||
public partial record LoadingSaveFile : State, IGet<Input.SaveFileLoaded>
|
||||
{
|
||||
public LoadingSaveFile()
|
||||
{
|
||||
this.OnEnter(() => Output(new Output.StartLoadingSaveFile()));
|
||||
}
|
||||
|
||||
public Transition On(in Input.SaveFileLoaded input) => To<InGame>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
public partial record State
|
||||
{
|
||||
[Meta]
|
||||
public partial record MainMenu : State, IGet<Input.NewGame>, IGet<Input.LoadGame>, IGet<Input.QuitGame>
|
||||
{
|
||||
public MainMenu()
|
||||
{
|
||||
this.OnEnter(() =>
|
||||
{
|
||||
Get<Data>().ShouldLoadExistingGame = false;
|
||||
Output(new Output.SetupGameScene());
|
||||
Get<IAppRepo>().OnMainMenuEntered();
|
||||
Output(new Output.ShowMainMenu());
|
||||
});
|
||||
}
|
||||
|
||||
public Transition On(in Input.NewGame input)
|
||||
{
|
||||
return To<LeavingMenu>();
|
||||
}
|
||||
|
||||
public Transition On(in Input.LoadGame input)
|
||||
{
|
||||
Get<Data>().ShouldLoadExistingGame = true;
|
||||
return To<LeavingMenu>();
|
||||
}
|
||||
|
||||
public Transition On(in Input.QuitGame input)
|
||||
{
|
||||
Output(new Output.ExitGame());
|
||||
return ToSelf();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
namespace Zennysoft.Game.Ma.Implementation;
|
||||
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
public partial record State
|
||||
{
|
||||
[Meta]
|
||||
public partial record SplashScreen : State, IGet<Input.FadeOutFinished>
|
||||
{
|
||||
public SplashScreen()
|
||||
{
|
||||
this.OnEnter(() => Output(new Output.ShowSplashScreen()));
|
||||
|
||||
OnAttach(
|
||||
() => Get<IAppRepo>().SplashScreenSkipped += OnSplashScreenSkipped
|
||||
);
|
||||
|
||||
OnDetach(
|
||||
() => Get<IAppRepo>().SplashScreenSkipped -= OnSplashScreenSkipped
|
||||
);
|
||||
}
|
||||
|
||||
public Transition On(in Input.FadeOutFinished input) => To<MainMenu>();
|
||||
|
||||
public void OnSplashScreenSkipped() =>
|
||||
Output(new Output.HideSplashScreen());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user