Overhaul game state logic to support gameplay loop
This commit is contained in:
@@ -28,21 +28,14 @@ public partial class App : CanvasLayer, IApp
|
||||
public IAppLogic AppLogic { get; set; } = default!;
|
||||
public AppLogic.IBinding AppBinding { get; set; } = default!;
|
||||
|
||||
[Node] public Menu Menu { get; set; } = default!;
|
||||
|
||||
[Node] public ISubViewport GameWindow { get; set; } = default!;
|
||||
|
||||
[Node] public ISplash Splash { get; set; } = default!;
|
||||
[Node] public IColorRect BlankScreen { get; set; } = default!;
|
||||
[Node] public IAnimationPlayer AnimationPlayer { get; set; } = default!;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
var container = new SimpleInjector.Container();
|
||||
container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
|
||||
container.RegisterSingleton<IAppRepo, AppRepo>();
|
||||
container.RegisterSingleton<IAppLogic, AppLogic>();
|
||||
//container.Verify();
|
||||
|
||||
Instantiator = new Instantiator(GetTree());
|
||||
|
||||
@@ -52,12 +45,6 @@ public partial class App : CanvasLayer, IApp
|
||||
AppLogic.Set(AppRepo);
|
||||
AppLogic.Set(new AppLogic.Data());
|
||||
|
||||
Menu.NewGame += OnNewGame;
|
||||
Menu.LoadGame += OnLoadGame;
|
||||
Menu.Quit += OnQuit;
|
||||
|
||||
AnimationPlayer.AnimationFinished += OnAnimationFinished;
|
||||
|
||||
Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
this.Provide();
|
||||
}
|
||||
@@ -69,14 +56,9 @@ public partial class App : CanvasLayer, IApp
|
||||
AppBinding
|
||||
.Handle((in AppLogic.Output.ShowSplashScreen _) =>
|
||||
{
|
||||
HideMenus();
|
||||
BlankScreen.Hide();
|
||||
Splash.Show();
|
||||
})
|
||||
.Handle((in AppLogic.Output.HideSplashScreen _) =>
|
||||
{
|
||||
BlankScreen.Show();
|
||||
FadeToBlack();
|
||||
})
|
||||
.Handle((in AppLogic.Output.SetupGameScene _) =>
|
||||
{
|
||||
@@ -86,19 +68,9 @@ public partial class App : CanvasLayer, IApp
|
||||
})
|
||||
.Handle((in AppLogic.Output.ShowMainMenu _) =>
|
||||
{
|
||||
// Load everything while we're showing a black screen, then fade in.
|
||||
HideMenus();
|
||||
Menu.Show();
|
||||
|
||||
FadeInFromBlack();
|
||||
Menu.NewGameButton.GrabFocus();
|
||||
})
|
||||
.Handle((in AppLogic.Output.FadeToBlack _) => FadeToBlack())
|
||||
.Handle((in AppLogic.Output.HideGame _) => FadeToBlack())
|
||||
.Handle((in AppLogic.Output.ShowGame _) =>
|
||||
{
|
||||
HideMenus();
|
||||
FadeInFromBlack();
|
||||
})
|
||||
.Handle((in AppLogic.Output.StartLoadingSaveFile _) =>
|
||||
{
|
||||
@@ -126,36 +98,6 @@ public partial class App : CanvasLayer, IApp
|
||||
AppLogic.Input(new AppLogic.Input.SaveFileLoaded());
|
||||
}
|
||||
|
||||
public void FadeInFromBlack()
|
||||
{
|
||||
BlankScreen.Show();
|
||||
AnimationPlayer.Play("fade_in");
|
||||
}
|
||||
|
||||
public void FadeToBlack()
|
||||
{
|
||||
BlankScreen.Show();
|
||||
AnimationPlayer.Play("fade_out");
|
||||
}
|
||||
|
||||
public void HideMenus()
|
||||
{
|
||||
Splash.Hide();
|
||||
Menu.Hide();
|
||||
}
|
||||
|
||||
public void OnAnimationFinished(StringName animation)
|
||||
{
|
||||
if (animation == "fade_in")
|
||||
{
|
||||
AppLogic.Input(new AppLogic.Input.FadeInFinished());
|
||||
BlankScreen.Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
AppLogic.Input(new AppLogic.Input.FadeOutFinished());
|
||||
}
|
||||
|
||||
public void OnExitTree()
|
||||
{
|
||||
AppLogic.Stop();
|
||||
|
||||
Reference in New Issue
Block a user