Major Player refactor
This commit is contained in:
125
src/app/App.cs
125
src/app/App.cs
@@ -3,78 +3,77 @@ using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
|
||||
namespace GameJamDungeon
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public interface IApp : ICanvasLayer, IProvide<IAppRepo>;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class App : CanvasLayer, IApp
|
||||
{
|
||||
public interface IApp : ICanvasLayer, IProvide<IAppRepo>;
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class App : CanvasLayer, IApp
|
||||
public const string GAME_SCENE_PATH = "res://src/game/Game.tscn";
|
||||
|
||||
public IGame Game { get; set; } = default!;
|
||||
|
||||
public IInstantiator Instantiator { get; set; } = default!;
|
||||
|
||||
IAppRepo IProvide<IAppRepo>.Value() => AppRepo;
|
||||
|
||||
public IAppRepo AppRepo { get; set; } = default!;
|
||||
public IAppLogic AppLogic { get; set; } = default!;
|
||||
public AppLogic.IBinding AppBinding { get; set; } = default!;
|
||||
|
||||
[Node] public IMenu Menu { get; set; } = default!;
|
||||
|
||||
[Node] public ISubViewport GameWindow { get; set; } = default!;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
Instantiator = new Instantiator(GetTree());
|
||||
AppRepo = new AppRepo();
|
||||
AppLogic = new AppLogic();
|
||||
AppLogic.Set(AppRepo);
|
||||
Menu.NewGame += OnNewGame;
|
||||
Menu.Quit += OnQuit;
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
this.Provide();
|
||||
}
|
||||
|
||||
public const string GAME_SCENE_PATH = "res://src/game/Game.tscn";
|
||||
public void OnReady()
|
||||
{
|
||||
AppBinding = AppLogic.Bind();
|
||||
|
||||
public IGame Game { get; set; } = default!;
|
||||
|
||||
public IInstantiator Instantiator { get; set; } = default!;
|
||||
|
||||
IAppRepo IProvide<IAppRepo>.Value() => AppRepo;
|
||||
|
||||
public IAppRepo AppRepo { get; set; } = default!;
|
||||
public IAppLogic AppLogic { get; set; } = default!;
|
||||
public AppLogic.IBinding AppBinding { get; set; } = default!;
|
||||
|
||||
[Node] public IMenu Menu { get; set; } = default!;
|
||||
|
||||
[Node] public ISubViewport GameWindow { get; set; } = default!;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
Instantiator = new Instantiator(GetTree());
|
||||
AppRepo = new AppRepo();
|
||||
AppLogic = new AppLogic();
|
||||
AppLogic.Set(AppRepo);
|
||||
Menu.NewGame += OnNewGame;
|
||||
Menu.Quit += OnQuit;
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
this.Provide();
|
||||
}
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
AppBinding = AppLogic.Bind();
|
||||
|
||||
AppBinding
|
||||
.Handle((in AppLogic.Output.ShowLoadingScreen _) =>
|
||||
{
|
||||
Menu.Hide();
|
||||
})
|
||||
.Handle((in AppLogic.Output.SetupGameScene _) =>
|
||||
{
|
||||
Menu.Hide();
|
||||
Instantiator.SceneTree.Paused = true;
|
||||
Game = Instantiator.LoadAndInstantiate<Game>(GAME_SCENE_PATH);
|
||||
GameWindow.AddChildEx(Game);
|
||||
})
|
||||
.Handle((in AppLogic.Output.ShowGame _) =>
|
||||
{
|
||||
Instantiator.SceneTree.Paused = false;
|
||||
Game.Show();
|
||||
});
|
||||
AppBinding
|
||||
.Handle((in AppLogic.Output.ShowLoadingScreen _) =>
|
||||
{
|
||||
Menu.Hide();
|
||||
})
|
||||
.Handle((in AppLogic.Output.SetupGameScene _) =>
|
||||
{
|
||||
Menu.Hide();
|
||||
Instantiator.SceneTree.Paused = true;
|
||||
Game = Instantiator.LoadAndInstantiate<Game>(GAME_SCENE_PATH);
|
||||
GameWindow.AddChildEx(Game);
|
||||
})
|
||||
.Handle((in AppLogic.Output.ShowGame _) =>
|
||||
{
|
||||
Instantiator.SceneTree.Paused = false;
|
||||
Game.Show();
|
||||
});
|
||||
|
||||
|
||||
AppLogic.Start();
|
||||
}
|
||||
AppLogic.Start();
|
||||
}
|
||||
|
||||
public void OnNewGame() => AppLogic.Input(new AppLogic.Input.NewGame());
|
||||
public void OnNewGame() => AppLogic.Input(new AppLogic.Input.NewGame());
|
||||
|
||||
public void OnQuit() => AppLogic.Input(new AppLogic.Input.QuitGame());
|
||||
public void OnQuit() => AppLogic.Input(new AppLogic.Input.QuitGame());
|
||||
|
||||
public void OnExitTree()
|
||||
{
|
||||
AppLogic.Stop();
|
||||
AppBinding.Dispose();
|
||||
AppRepo.Dispose();
|
||||
}
|
||||
public void OnExitTree()
|
||||
{
|
||||
AppLogic.Stop();
|
||||
AppBinding.Dispose();
|
||||
AppRepo.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,77 +1,76 @@
|
||||
using System;
|
||||
|
||||
namespace GameJamDungeon
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public interface IAppRepo : IDisposable
|
||||
{
|
||||
public interface IAppRepo : IDisposable
|
||||
event Action? GameEntered;
|
||||
|
||||
event Action? GameExited;
|
||||
|
||||
event Action? SplashScreenSkipped;
|
||||
|
||||
event Action? MainMenuEntered;
|
||||
|
||||
event Action? ShowLoadingScreen;
|
||||
|
||||
void SkipSplashScreen();
|
||||
|
||||
void OnMainMenuEntered();
|
||||
|
||||
void OnEnterGame();
|
||||
|
||||
void OnExitGame();
|
||||
|
||||
void OnGameOver();
|
||||
|
||||
void OnShowLoadingScreen();
|
||||
|
||||
}
|
||||
|
||||
public class AppRepo : IAppRepo
|
||||
{
|
||||
public event Action? SplashScreenSkipped;
|
||||
public event Action? MainMenuEntered;
|
||||
public event Action? GameEntered;
|
||||
public event Action? GameExited;
|
||||
public event Action? ShowLoadingScreen;
|
||||
|
||||
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();
|
||||
|
||||
public void OnShowLoadingScreen() => ShowLoadingScreen?.Invoke();
|
||||
|
||||
protected void Dispose(bool disposing)
|
||||
{
|
||||
event Action? GameEntered;
|
||||
|
||||
event Action? GameExited;
|
||||
|
||||
event Action? SplashScreenSkipped;
|
||||
|
||||
event Action? MainMenuEntered;
|
||||
|
||||
event Action? ShowLoadingScreen;
|
||||
|
||||
void SkipSplashScreen();
|
||||
|
||||
void OnMainMenuEntered();
|
||||
|
||||
void OnEnterGame();
|
||||
|
||||
void OnExitGame();
|
||||
|
||||
void OnGameOver();
|
||||
|
||||
void OnShowLoadingScreen();
|
||||
if (!_disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed objects.
|
||||
SplashScreenSkipped = null;
|
||||
MainMenuEntered = null;
|
||||
GameEntered = null;
|
||||
GameExited = null;
|
||||
ShowLoadingScreen = null;
|
||||
}
|
||||
|
||||
_disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public class AppRepo : IAppRepo
|
||||
public void Dispose()
|
||||
{
|
||||
public event Action? SplashScreenSkipped;
|
||||
public event Action? MainMenuEntered;
|
||||
public event Action? GameEntered;
|
||||
public event Action? GameExited;
|
||||
public event Action? ShowLoadingScreen;
|
||||
|
||||
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();
|
||||
|
||||
public void OnShowLoadingScreen() => ShowLoadingScreen?.Invoke();
|
||||
|
||||
protected void Dispose(bool disposing)
|
||||
{
|
||||
if (!_disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// Dispose managed objects.
|
||||
SplashScreenSkipped = null;
|
||||
MainMenuEntered = null;
|
||||
GameEntered = null;
|
||||
GameExited = null;
|
||||
ShowLoadingScreen = null;
|
||||
}
|
||||
|
||||
_disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
namespace GameJamDungeon
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
public partial class AppLogic
|
||||
public static class Input
|
||||
{
|
||||
public static class Input
|
||||
{
|
||||
public readonly record struct NewGame;
|
||||
public readonly record struct NewGame;
|
||||
|
||||
public readonly record struct LoadGameFinished;
|
||||
public readonly record struct LoadGameFinished;
|
||||
|
||||
public readonly record struct FadeOutFinished;
|
||||
public readonly record struct FadeOutFinished;
|
||||
|
||||
public readonly record struct QuitGame;
|
||||
public readonly record struct QuitGame;
|
||||
|
||||
public readonly record struct GameOver;
|
||||
public readonly record struct GameOver;
|
||||
|
||||
public readonly record struct ShowLoadingScreen;
|
||||
}
|
||||
public readonly record struct ShowLoadingScreen;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,31 @@
|
||||
namespace GameJamDungeon
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
public partial class AppLogic
|
||||
public static class Output
|
||||
{
|
||||
public static class Output
|
||||
{
|
||||
public readonly record struct FadeToBlack;
|
||||
public readonly record struct FadeToBlack;
|
||||
|
||||
public readonly record struct ShowSplashScreen;
|
||||
public readonly record struct ShowSplashScreen;
|
||||
|
||||
public readonly record struct HideSplashScreen;
|
||||
public readonly record struct HideSplashScreen;
|
||||
|
||||
public readonly record struct RemoveExistingGame;
|
||||
public readonly record struct RemoveExistingGame;
|
||||
|
||||
public readonly record struct PlayGame;
|
||||
public readonly record struct PlayGame;
|
||||
|
||||
public readonly record struct ShowGame;
|
||||
public readonly record struct ShowGame;
|
||||
|
||||
public readonly record struct HideGame;
|
||||
public readonly record struct HideGame;
|
||||
|
||||
public readonly record struct SetupGameScene;
|
||||
public readonly record struct SetupGameScene;
|
||||
|
||||
public readonly record struct ShowLoadingScreen;
|
||||
public readonly record struct ShowLoadingScreen;
|
||||
|
||||
public readonly record struct ShowMainMenu;
|
||||
public readonly record struct ShowMainMenu;
|
||||
|
||||
public readonly record struct ExitGame;
|
||||
public readonly record struct ExitGame;
|
||||
|
||||
public readonly record struct GameOver;
|
||||
}
|
||||
public readonly record struct GameOver;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace GameJamDungeon
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
public partial class AppLogic
|
||||
{
|
||||
[Meta]
|
||||
public abstract partial record State : StateLogic<State>;
|
||||
}
|
||||
[Meta]
|
||||
public abstract partial record State : StateLogic<State>;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace GameJamDungeon
|
||||
{
|
||||
public interface IAppLogic : ILogicBlock<AppLogic.State>;
|
||||
namespace GameJamDungeon;
|
||||
|
||||
[Meta]
|
||||
[LogicBlock(typeof(State), Diagram = true)]
|
||||
public partial class AppLogic : LogicBlock<AppLogic.State>, IAppLogic
|
||||
{
|
||||
public override Transition GetInitialState() => To<State.SetupGameScene>();
|
||||
}
|
||||
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.SetupGameScene>();
|
||||
}
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace GameJamDungeon
|
||||
{
|
||||
public partial class AppLogic
|
||||
{
|
||||
public partial record State
|
||||
{
|
||||
[Meta]
|
||||
public partial record SetupGameScene : State, IGet<Input.LoadGameFinished>
|
||||
{
|
||||
public SetupGameScene()
|
||||
{
|
||||
this.OnEnter(() =>
|
||||
{
|
||||
Output(new Output.SetupGameScene());
|
||||
Output(new Output.ShowGame());
|
||||
Input(new Input.LoadGameFinished());
|
||||
});
|
||||
}
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public Transition On(in Input.LoadGameFinished input)
|
||||
public partial class AppLogic
|
||||
{
|
||||
public partial record State
|
||||
{
|
||||
[Meta]
|
||||
public partial record SetupGameScene : State, IGet<Input.LoadGameFinished>
|
||||
{
|
||||
public SetupGameScene()
|
||||
{
|
||||
this.OnEnter(() =>
|
||||
{
|
||||
return To<InGame>();
|
||||
}
|
||||
Output(new Output.SetupGameScene());
|
||||
Output(new Output.ShowGame());
|
||||
Input(new Input.LoadGameFinished());
|
||||
});
|
||||
}
|
||||
|
||||
public Transition On(in Input.LoadGameFinished input)
|
||||
{
|
||||
return To<InGame>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,36 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace GameJamDungeon
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public partial class AppLogic
|
||||
{
|
||||
public partial class AppLogic
|
||||
public partial record State
|
||||
{
|
||||
public partial record State
|
||||
[Meta]
|
||||
public partial record InGame : State, IGet<Input.GameOver>
|
||||
{
|
||||
[Meta]
|
||||
public partial record InGame : State, IGet<Input.GameOver>
|
||||
public InGame()
|
||||
{
|
||||
public InGame()
|
||||
|
||||
this.OnEnter(() =>
|
||||
{
|
||||
Get<IAppRepo>().OnEnterGame();
|
||||
Output(new Output.ShowGame());
|
||||
});
|
||||
this.OnExit(() => Output(new Output.HideGame()));
|
||||
|
||||
this.OnEnter(() =>
|
||||
{
|
||||
Get<IAppRepo>().OnEnterGame();
|
||||
Output(new Output.ShowGame());
|
||||
});
|
||||
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.GameOver());
|
||||
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.GameOver());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,33 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace GameJamDungeon
|
||||
{
|
||||
public partial class AppLogic
|
||||
{
|
||||
public partial record State
|
||||
{
|
||||
[Meta]
|
||||
public partial record MainMenu : State, IGet<Input.NewGame>, IGet<Input.QuitGame>
|
||||
{
|
||||
public MainMenu()
|
||||
{
|
||||
this.OnEnter(() =>
|
||||
{
|
||||
Get<IAppRepo>().OnMainMenuEntered();
|
||||
Output(new Output.ShowMainMenu());
|
||||
});
|
||||
}
|
||||
public Transition On(in Input.NewGame input)
|
||||
{
|
||||
Output(new Output.SetupGameScene());
|
||||
return To<LoadingScreen>();
|
||||
}
|
||||
namespace GameJamDungeon;
|
||||
|
||||
public Transition On(in Input.QuitGame input)
|
||||
public partial class AppLogic
|
||||
{
|
||||
public partial record State
|
||||
{
|
||||
[Meta]
|
||||
public partial record MainMenu : State, IGet<Input.NewGame>, IGet<Input.QuitGame>
|
||||
{
|
||||
public MainMenu()
|
||||
{
|
||||
this.OnEnter(() =>
|
||||
{
|
||||
Output(new Output.ExitGame());
|
||||
return ToSelf();
|
||||
}
|
||||
Get<IAppRepo>().OnMainMenuEntered();
|
||||
Output(new Output.ShowMainMenu());
|
||||
});
|
||||
}
|
||||
public Transition On(in Input.NewGame input)
|
||||
{
|
||||
Output(new Output.SetupGameScene());
|
||||
return To<LoadingScreen>();
|
||||
}
|
||||
|
||||
public Transition On(in Input.QuitGame input)
|
||||
{
|
||||
Output(new Output.ExitGame());
|
||||
return ToSelf();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user