Re-introduce prototype code
This commit is contained in:
61
src/app/App.cs
Normal file
61
src/app/App.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
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 ISubViewport GameWindow { get; set; } = default!;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
Instantiator = new Instantiator(GetTree());
|
||||
AppRepo = new AppRepo();
|
||||
AppLogic = new AppLogic();
|
||||
AppLogic.Set(AppRepo);
|
||||
|
||||
this.Provide();
|
||||
}
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
Game = Instantiator.LoadAndInstantiate<Game>(GAME_SCENE_PATH);
|
||||
GameWindow.AddChildEx(Game);
|
||||
AppBinding = AppLogic.Bind();
|
||||
AppLogic.Start();
|
||||
|
||||
Instantiator.SceneTree.Paused = false;
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user