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

@@ -1,51 +1,51 @@
<Project Sdk="Godot.NET.Sdk/4.4.0">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<!-- Use NativeAOT. -->
<PublishAot>true</PublishAot>
</PropertyGroup>
<ItemGroup>
<Compile Remove="src\items\weapons\models\**" />
<EmbeddedResource Remove="src\items\weapons\models\**" />
</ItemGroup>
<ItemGroup>
<!-- Root the assemblies to avoid trimming. -->
<TrimmerRootAssembly Include="GodotSharp" />
<TrimmerRootAssembly Include="$(TargetName)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Chickensoft.AutoInject" Version="2.5.0" />
<PackageReference Include="Chickensoft.GodotNodeInterfaces" Version="2.4.0" />
<PackageReference Include="Chickensoft.Introspection" Version="2.2.0" />
<PackageReference Include="Chickensoft.Introspection.Generator" Version="2.2.0" />
<PackageReference Include="Chickensoft.LogicBlocks" Version="5.15.0" />
<PackageReference Include="Chickensoft.LogicBlocks.DiagramGenerator" Version="5.15.0" />
<PackageReference Include="Chickensoft.SaveFileBuilder" Version="1.1.0" />
<PackageReference Include="Chickensoft.Serialization.Godot" Version="0.7.6" />
<PackageReference Include="GodotSharp.SourceGenerators" Version="2.5.0" />
<PackageReference Include="SimpleInjector" Version="5.5.0" />
<PackageReference Include="SSH.NET" Version="2024.2.0" />
<PackageReference Include="System.IO.Abstractions" Version="21.2.1" />
<PackageReference Include="Zeroconf" Version="3.7.16" />
</ItemGroup>
<ItemGroup>
<Folder Include="src\ui\dialogue\" />
</ItemGroup>
<ItemGroup>
<None Include=".editorconfig" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Zennysoft.Game.Abstractions\Zennysoft.Game.Abstractions.csproj" />
<ProjectReference Include="..\Zennysoft.Game.Ma.Implementation\Zennysoft.Game.Ma.Implementation.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Godot.SourceGenerators" Version="4.4.0-dev.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="GodotSharp" Version="4.4.0-dev.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="GodotSharpEditor" Version="4.4.0-dev.2" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<!-- Use NativeAOT. -->
<PublishAot>true</PublishAot>
</PropertyGroup>
<ItemGroup>
<Compile Remove="src\items\weapons\models\**" />
<EmbeddedResource Remove="src\items\weapons\models\**" />
</ItemGroup>
<ItemGroup>
<!-- Root the assemblies to avoid trimming. -->
<TrimmerRootAssembly Include="GodotSharp" />
<TrimmerRootAssembly Include="$(TargetName)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Chickensoft.AutoInject" Version="2.5.0" />
<PackageReference Include="Chickensoft.GodotNodeInterfaces" Version="2.4.0" />
<PackageReference Include="Chickensoft.Introspection" Version="2.2.0" />
<PackageReference Include="Chickensoft.Introspection.Generator" Version="2.2.0" />
<PackageReference Include="Chickensoft.LogicBlocks" Version="5.16.0" />
<PackageReference Include="Chickensoft.LogicBlocks.DiagramGenerator" Version="5.16.0" />
<PackageReference Include="Chickensoft.SaveFileBuilder" Version="1.1.0" />
<PackageReference Include="Chickensoft.Serialization.Godot" Version="0.7.6" />
<PackageReference Include="GodotSharp.SourceGenerators" Version="2.6.0-250131-2115.Release" />
<PackageReference Include="SimpleInjector" Version="5.5.0" />
<PackageReference Include="SSH.NET" Version="2024.2.0" />
<PackageReference Include="System.IO.Abstractions" Version="22.0.11" />
<PackageReference Include="Zeroconf" Version="3.7.16" />
</ItemGroup>
<ItemGroup>
<Folder Include="src\ui\dialogue\" />
</ItemGroup>
<ItemGroup>
<None Include=".editorconfig" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Zennysoft.Game.Abstractions\Zennysoft.Game.Abstractions.csproj" />
<ProjectReference Include="..\Zennysoft.Game.Ma.Implementation\Zennysoft.Game.Ma.Implementation.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Godot.SourceGenerators" Version="4.4.0-dev.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="GodotSharp" Version="4.4.0-dev.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="GodotSharpEditor" Version="4.4.0-dev.2" />
</ItemGroup>
</Project>

View File

@@ -2,7 +2,11 @@
using Chickensoft.GodotNodeInterfaces;
using Chickensoft.Introspection;
using Godot;
using static Zennysoft.Game.Ma.AppLogic.Input;
using SimpleInjector;
using SimpleInjector.Lifestyles;
using Zennysoft.Game.Abstractions;
using Zennysoft.Game.Ma.Implementation;
using static Zennysoft.Game.Ma.Implementation.AppLogic.Input;
namespace Zennysoft.Game.Ma;
@@ -35,9 +39,17 @@ public partial class App : CanvasLayer, IApp
public void Initialize()
{
var container = new SimpleInjector.Container();
container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
container.Register<IAppRepo, AppRepo>(Lifestyle.Singleton);
container.Register<IAppLogic, AppLogic>(Lifestyle.Singleton);
container.Verify();
Instantiator = new Instantiator(GetTree());
AppRepo = new AppRepo();
AppLogic = new AppLogic();
AppRepo = container.GetInstance<IAppRepo>();
AppLogic = container.GetInstance<IAppLogic>();
AppLogic.Set(AppRepo);
AppLogic.Set(new AppLogic.Data());

View File

@@ -1,67 +0,0 @@
using System;
namespace Zennysoft.Game.Ma;
public interface IAppRepo : IDisposable
{
event Action? GameEntered;
event Action? GameExited;
event Action? SplashScreenSkipped;
event Action? MainMenuEntered;
void SkipSplashScreen();
void OnMainMenuEntered();
void OnEnterGame();
void OnExitGame();
void OnGameOver();
}
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);
}
}

View File

@@ -1 +0,0 @@
uid://dyd1r1pl5beku

View File

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

View File

@@ -1 +0,0 @@
uid://cbqvl36d7foae

View File

@@ -1,24 +0,0 @@
namespace Zennysoft.Game.Ma;
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

@@ -1 +0,0 @@
uid://b2hwfi78870pf

View File

@@ -1,33 +0,0 @@
namespace Zennysoft.Game.Ma;
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

@@ -1 +0,0 @@
uid://dfygx4qdyomdw

View File

@@ -1,10 +0,0 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace Zennysoft.Game.Ma;
public partial class AppLogic
{
[Meta]
public abstract partial record State : StateLogic<State>;
}

View File

@@ -1 +0,0 @@
uid://dqc8wddrx0txd

View File

@@ -1,13 +0,0 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace Zennysoft.Game.Ma;
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

@@ -1 +0,0 @@
uid://e51dlkiwpksy

View File

@@ -1,30 +0,0 @@
@startuml AppLogic
state "AppLogic State" as Zennysoft_Game_Ma_AppLogic_State {
state "InGame" as Zennysoft_Game_Ma_AppLogic_State_InGame
state "LeavingMenu" as Zennysoft_Game_Ma_AppLogic_State_LeavingMenu
state "LoadingSaveFile" as Zennysoft_Game_Ma_AppLogic_State_LoadingSaveFile
state "MainMenu" as Zennysoft_Game_Ma_AppLogic_State_MainMenu
state "SplashScreen" as Zennysoft_Game_Ma_AppLogic_State_SplashScreen
}
Zennysoft_Game_Ma_AppLogic_State_InGame --> Zennysoft_Game_Ma_AppLogic_State_MainMenu : GameOver
Zennysoft_Game_Ma_AppLogic_State_LeavingMenu --> Zennysoft_Game_Ma_AppLogic_State_InGame : FadeOutFinished
Zennysoft_Game_Ma_AppLogic_State_LeavingMenu --> Zennysoft_Game_Ma_AppLogic_State_LoadingSaveFile : FadeOutFinished
Zennysoft_Game_Ma_AppLogic_State_LoadingSaveFile --> Zennysoft_Game_Ma_AppLogic_State_InGame : SaveFileLoaded
Zennysoft_Game_Ma_AppLogic_State_MainMenu --> Zennysoft_Game_Ma_AppLogic_State_LeavingMenu : LoadGame
Zennysoft_Game_Ma_AppLogic_State_MainMenu --> Zennysoft_Game_Ma_AppLogic_State_LeavingMenu : NewGame
Zennysoft_Game_Ma_AppLogic_State_MainMenu --> Zennysoft_Game_Ma_AppLogic_State_MainMenu : QuitGame
Zennysoft_Game_Ma_AppLogic_State_SplashScreen --> Zennysoft_Game_Ma_AppLogic_State_MainMenu : FadeOutFinished
Zennysoft_Game_Ma_AppLogic_State_InGame : OnEnter → ShowGame
Zennysoft_Game_Ma_AppLogic_State_InGame : OnExit → HideGame
Zennysoft_Game_Ma_AppLogic_State_InGame : OnGameOver → RemoveExistingGame
Zennysoft_Game_Ma_AppLogic_State_LeavingMenu : OnEnter → FadeToBlack
Zennysoft_Game_Ma_AppLogic_State_LoadingSaveFile : OnEnter → StartLoadingSaveFile
Zennysoft_Game_Ma_AppLogic_State_MainMenu : OnEnter → SetupGameScene, ShowMainMenu
Zennysoft_Game_Ma_AppLogic_State_MainMenu : OnQuitGame → ExitGame
Zennysoft_Game_Ma_AppLogic_State_SplashScreen : OnEnter → ShowSplashScreen
Zennysoft_Game_Ma_AppLogic_State_SplashScreen : OnSplashScreenSkipped() → HideSplashScreen
[*] --> Zennysoft_Game_Ma_AppLogic_State_SplashScreen
@enduml

View File

@@ -1,36 +0,0 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace Zennysoft.Game.Ma;
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

@@ -1 +0,0 @@
uid://ckb88dvtckagu

View File

@@ -1,24 +0,0 @@
namespace Zennysoft.Game.Ma;
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

@@ -1 +0,0 @@
uid://du7y6o0h004sm

View File

@@ -1,21 +0,0 @@
namespace Zennysoft.Game.Ma;
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

@@ -1,42 +0,0 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace Zennysoft.Game.Ma;
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

@@ -1 +0,0 @@
uid://b5ehfb8l8u2fy

View File

@@ -1,32 +0,0 @@
namespace Zennysoft.Game.Ma;
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
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());
}
}
}

View File

@@ -1 +0,0 @@
uid://dxbrwt7jduxu8

View File

@@ -1 +0,0 @@
uid://xix7akau8f8g

View File

@@ -1 +0,0 @@
uid://cm2spwox38qgx

View File

@@ -1 +0,0 @@
uid://bjhw05eivyte3

View File

@@ -2,6 +2,7 @@ using Chickensoft.AutoInject;
using Chickensoft.GodotNodeInterfaces;
using Chickensoft.Introspection;
using Godot;
using Zennysoft.Game.Abstractions;
namespace Zennysoft.Game.Ma;

View File

@@ -1,6 +0,0 @@
namespace Zennysoft.Game.Ma.src.enemy;
public interface ICanPatrol
{
public void Patrol();
}

View File

@@ -1,9 +1,9 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Zennysoft.Game.Ma.src.enemy;
using Godot;
using System;
using System.Threading.Tasks;
using Zennysoft.Game.Abstractions;
namespace Zennysoft.Game.Ma;

View File

@@ -1,7 +1,7 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Zennysoft.Game.Ma.src.enemy;
using Godot;
using Zennysoft.Game.Abstractions;
using Zennysoft.Game.Ma.Implementation;
namespace Zennysoft.Game.Ma;

View File

@@ -1,7 +1,7 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Zennysoft.Game.Ma.src.enemy;
using Godot;
using Zennysoft.Game.Abstractions;
using Zennysoft.Game.Ma.Implementation;
namespace Zennysoft.Game.Ma;

View File

@@ -1,7 +1,7 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Zennysoft.Game.Ma.src.enemy;
using Godot;
using Zennysoft.Game.Abstractions;
using Zennysoft.Game.Ma.Implementation;
namespace Zennysoft.Game.Ma;

View File

@@ -1,6 +1,7 @@
namespace Zennysoft.Game.Ma;
using Chickensoft.Introspection;
using Zennysoft.Game.Abstractions;
public partial class GameLogic
{

View File

@@ -2,6 +2,7 @@
using Chickensoft.GodotNodeInterfaces;
using Chickensoft.Introspection;
using Godot;
using Zennysoft.Game.Abstractions;
namespace Zennysoft.Game.Ma;

View File

@@ -1,4 +1,5 @@
using Chickensoft.Introspection;
using Zennysoft.Game.Abstractions;
namespace Zennysoft.Game.Ma;