Files
GameJamDungeon/src/app/App.cs

80 lines
2.0 KiB
C#

using Chickensoft.AutoInject;
using Chickensoft.GodotNodeInterfaces;
using Chickensoft.Introspection;
using Godot;
namespace GameJamDungeon
{
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 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;
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();
});
AppLogic.Start();
}
public void OnNewGame() => AppLogic.Input(new AppLogic.Input.NewGame());
public void OnQuit() => AppLogic.Input(new AppLogic.Input.QuitGame());
public void OnExitTree()
{
AppLogic.Stop();
AppBinding.Dispose();
AppRepo.Dispose();
}
}
}