Move files and folders to new repo format to enable multi-project format
This commit is contained in:
154
Zennysoft.Game.Ma/src/app/App.cs
Normal file
154
Zennysoft.Game.Ma/src/app/App.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using static Zennysoft.Game.Ma.AppLogic.Input;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public interface IApp : ICanvasLayer, IProvide<IAppRepo>;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class App : CanvasLayer, IApp
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
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 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()
|
||||
{
|
||||
Instantiator = new Instantiator(GetTree());
|
||||
AppRepo = new AppRepo();
|
||||
AppLogic = new AppLogic();
|
||||
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();
|
||||
}
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
AppBinding = AppLogic.Bind();
|
||||
|
||||
AppBinding
|
||||
.Handle((in AppLogic.Output.ShowSplashScreen _) =>
|
||||
{
|
||||
HideMenus();
|
||||
BlankScreen.Hide();
|
||||
Splash.Show();
|
||||
})
|
||||
.Handle((in AppLogic.Output.HideSplashScreen _) =>
|
||||
{
|
||||
BlankScreen.Show();
|
||||
FadeToBlack();
|
||||
})
|
||||
.Handle((in AppLogic.Output.SetupGameScene _) =>
|
||||
{
|
||||
Game = Instantiator.LoadAndInstantiate<Game>(GAME_SCENE_PATH);
|
||||
GameWindow.AddChildEx(Game);
|
||||
Instantiator.SceneTree.Paused = false;
|
||||
})
|
||||
.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 _) =>
|
||||
{
|
||||
Game.SaveFileLoaded += OnSaveFileLoaded;
|
||||
Game.LoadExistingGame();
|
||||
})
|
||||
.Handle((in AppLogic.Output.ExitGame _) =>
|
||||
{
|
||||
GetTree().Quit();
|
||||
});
|
||||
|
||||
|
||||
AppLogic.Start();
|
||||
}
|
||||
|
||||
public void OnNewGame() => AppLogic.Input(new NewGame());
|
||||
|
||||
private void OnLoadGame() => AppLogic.Input(new LoadGame());
|
||||
|
||||
public void OnQuit() => AppLogic.Input(new QuitGame());
|
||||
|
||||
public void OnSaveFileLoaded()
|
||||
{
|
||||
Game.SaveFileLoaded -= OnSaveFileLoaded;
|
||||
AppLogic.Input(new 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 FadeInFinished());
|
||||
BlankScreen.Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
AppLogic.Input(new FadeOutFinished());
|
||||
}
|
||||
|
||||
public void OnExitTree()
|
||||
{
|
||||
AppLogic.Stop();
|
||||
AppBinding.Dispose();
|
||||
AppRepo.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user