Move App logic to other projects

This commit is contained in:
2025-03-07 01:08:35 -08:00
parent 3b5ee84ce2
commit 1cb79f5b30
49 changed files with 185 additions and 205 deletions

View File

@@ -0,0 +1,9 @@
namespace Zennysoft.Game.Ma.Implementation;
public partial class AppLogic
{
public record Data
{
public bool ShouldLoadExistingGame { get; set; }
}
}

View 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;
}
}

View File

@@ -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;
}
}

View 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>;
}

View 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>();
}

View File

@@ -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());
}
}
}

View File

@@ -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>();
}
}
}

View File

@@ -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>();
}
}
}

View File

@@ -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();
}
}
}
}

View File

@@ -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());
}
}
}