136 lines
4.0 KiB
C#
136 lines
4.0 KiB
C#
|
|
namespace GameJamDungeon;
|
|
|
|
using Chickensoft.AutoInject;
|
|
using Chickensoft.GodotNodeInterfaces;
|
|
using Chickensoft.Introspection;
|
|
using DialogueManagerRuntime;
|
|
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public interface IGame : IProvide<IGameRepo>, IProvide<IGame>, INode3D
|
|
{
|
|
public void ToggleInventory();
|
|
}
|
|
|
|
[Meta(typeof(IAutoNode))]
|
|
public partial class Game : Node3D, IGame
|
|
{
|
|
public override void _Notification(int what) => this.Notify(what);
|
|
|
|
IGameRepo IProvide<IGameRepo>.Value() => GameRepo;
|
|
|
|
IGame IProvide<IGame>.Value() => this;
|
|
|
|
public IInstantiator Instantiator { get; set; } = default!;
|
|
|
|
public IGameLogic GameLogic { get; set; } = default!;
|
|
|
|
public IGameRepo GameRepo { get; set; } = default!;
|
|
|
|
public GameLogic.IBinding GameBinding { get; set; } = default!;
|
|
|
|
[Dependency] public IAppRepo AppRepo => this.DependOn<IAppRepo>();
|
|
|
|
[Node] public IMap Map { get; set; } = default!;
|
|
|
|
[Node] public DialogueController DialogueController { get; set; } = default!;
|
|
|
|
[Node] public IPauseMenu PauseMenu { get; set; } = default!;
|
|
|
|
[Node] public FloorClearMenu FloorClearMenu { get; set; } = default!;
|
|
|
|
[Node] public DeathMenu DeathMenu { get; set; } = default!;
|
|
|
|
[Node] public InGameUI InGameUI { get; set; } = default!;
|
|
|
|
public void Setup()
|
|
{
|
|
GameRepo = new GameRepo();
|
|
GameLogic = new GameLogic();
|
|
GameLogic.Set(GameRepo);
|
|
GameLogic.Set(AppRepo);
|
|
Instantiator = new Instantiator(GetTree());
|
|
|
|
FloorClearMenu.TransitionCompleted += OnFloorClearTransitionCompleted;
|
|
}
|
|
|
|
private void OnFloorClearTransitionCompleted()
|
|
{
|
|
GameLogic.Input(new GameLogic.Input.FloorClearTransitioned());
|
|
}
|
|
|
|
public void Exit()
|
|
{
|
|
GameLogic.Input(new GameLogic.Input.LoadNextFloor());
|
|
GameRepo.Resume();
|
|
}
|
|
|
|
public void OnResolved()
|
|
{
|
|
GameBinding = GameLogic.Bind();
|
|
GameBinding
|
|
.Handle((in GameLogic.Output.StartGame _) =>
|
|
{
|
|
InGameUI.Show();
|
|
GameRepo.SetPlayerGlobalPosition(Map.GetPlayerSpawnPoint());
|
|
})
|
|
.Handle((in GameLogic.Output.SetPauseMode output) => CallDeferred(nameof(SetPauseMode), output.IsPaused))
|
|
.Handle((in GameLogic.Output.ShowPauseMenu _) =>
|
|
{
|
|
PauseMenu.Show();
|
|
PauseMenu.FadeIn();
|
|
})
|
|
.Handle((in GameLogic.Output.HidePauseMenu _) => { PauseMenu.Hide(); })
|
|
.Handle((in GameLogic.Output.ExitPauseMenu _) => { PauseMenu.FadeOut(); })
|
|
.Handle((in GameLogic.Output.ShowFloorClearMenu _) => { FloorClearMenu.Show(); FloorClearMenu.FadeIn(); })
|
|
.Handle((in GameLogic.Output.SetInventoryMode _) => { InGameUI.ShowInventoryScreen(); })
|
|
.Handle((in GameLogic.Output.HideInventory _) => { InGameUI.HideInventoryScreen(); })
|
|
.Handle((in GameLogic.Output.ShowMiniMap _) => { InGameUI.ShowMiniMap(); })
|
|
.Handle((in GameLogic.Output.HideMiniMap _) => { InGameUI.HideMiniMap(); })
|
|
.Handle((in GameLogic.Output.ShowLostScreen _) => { DeathMenu.Show(); DeathMenu.FadeIn(); })
|
|
.Handle((in GameLogic.Output.ExitLostScreen _) => { DeathMenu.FadeOut(); });
|
|
GameLogic.Start();
|
|
|
|
GameLogic.Input(new GameLogic.Input.Initialize());
|
|
|
|
this.Provide();
|
|
}
|
|
|
|
public void ToggleInventory()
|
|
{
|
|
GameLogic.Input(new GameLogic.Input.InventoryMenuToggle());
|
|
}
|
|
|
|
public override void _UnhandledInput(InputEvent @event)
|
|
{
|
|
if (@event.IsActionPressed(GameInputs.Inventory))
|
|
{
|
|
GD.Print("Inventory button pressed");
|
|
GameLogic.Input(new GameLogic.Input.InventoryMenuToggle());
|
|
}
|
|
|
|
if (@event.IsActionPressed(GameInputs.MiniMap))
|
|
{
|
|
GD.Print("MiniMap button pressed");
|
|
GameLogic.Input(new GameLogic.Input.MiniMapButtonPressed());
|
|
}
|
|
|
|
if (@event.IsActionReleased(GameInputs.MiniMap))
|
|
{
|
|
GD.Print("MiniMap button released");
|
|
GameLogic.Input(new GameLogic.Input.MiniMapButtonReleased());
|
|
}
|
|
}
|
|
|
|
private void SetPauseMode(bool isPaused)
|
|
{
|
|
if (GetTree() != null)
|
|
GetTree().Paused = isPaused;
|
|
}
|
|
|
|
public void OnStart() => GameLogic.Input(new GameLogic.Input.Start());
|
|
}
|