Big refactor in place: Organize nodes in line with dependency injection expectations, use state machine flow more
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
namespace GameJamDungeon;
|
||||
|
||||
using Chickensoft.AutoInject;
|
||||
@@ -5,6 +6,7 @@ using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using DialogueManagerRuntime;
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -32,25 +34,17 @@ public partial class Game : Node3D, IGame
|
||||
|
||||
[Dependency] public IAppRepo AppRepo => this.DependOn<IAppRepo>();
|
||||
|
||||
[Node] public IInventoryMenu InventoryMenu { get; set; } = default!;
|
||||
|
||||
[Node] public Control MiniMap { get; set; } = default!;
|
||||
|
||||
[Node] public Area3D Teleport { get; set; } = default!;
|
||||
|
||||
[Node] public IDungeonFloor Overworld { get; set; } = default!;
|
||||
|
||||
[Node] public IDungeonFloor Floor1 { get; set; } = default!;
|
||||
|
||||
[Node] public IDungeonFloor Floor2 { get; set; } = default!;
|
||||
|
||||
[Node] public IDungeonFloor Floor3 { get; set; } = default!;
|
||||
|
||||
[Node] public AnimationPlayer AnimationPlayer { get; set; } = default!;
|
||||
[Node] public IMap Map { get; set; } = default!;
|
||||
|
||||
[Node] public DialogueController DialogueController { get; set; } = default!;
|
||||
|
||||
private List<IDungeonFloor> Floors;
|
||||
[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()
|
||||
{
|
||||
@@ -59,17 +53,13 @@ public partial class Game : Node3D, IGame
|
||||
GameLogic.Set(GameRepo);
|
||||
GameLogic.Set(AppRepo);
|
||||
Instantiator = new Instantiator(GetTree());
|
||||
Floors = new List<IDungeonFloor> { Overworld, Floor1, Floor2, Floor3 };
|
||||
Teleport.BodyEntered += OnTeleportEntered;
|
||||
|
||||
FloorClearMenu.TransitionCompleted += OnFloorClearTransitionCompleted;
|
||||
}
|
||||
|
||||
private void OnTeleportEntered(Node3D body)
|
||||
private void OnFloorClearTransitionCompleted()
|
||||
{
|
||||
GameRepo.Pause();
|
||||
DialogueManager.GetCurrentScene = (() => this);
|
||||
var dialogueResource = GD.Load<Resource>("res://src/ui/dialogue/FloorExit.dialogue");
|
||||
DialogueController.ShowDialogue(dialogueResource, "floor_exit");
|
||||
DialogueManager.DialogueEnded += (Resource resource) => { GameRepo.Resume(); };
|
||||
GameLogic.Input(new GameLogic.Input.FloorClearTransitioned());
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
@@ -84,36 +74,27 @@ public partial class Game : Node3D, IGame
|
||||
GameBinding
|
||||
.Handle((in GameLogic.Output.StartGame _) =>
|
||||
{
|
||||
InGameUI.Show();
|
||||
GameRepo.SetPlayerGlobalPosition(Map.GetPlayerSpawnPoint());
|
||||
})
|
||||
.Handle((in GameLogic.Output.LoadNextFloor _) =>
|
||||
.Handle((in GameLogic.Output.SetPauseMode output) => CallDeferred(nameof(SetPauseMode), output.IsPaused))
|
||||
.Handle((in GameLogic.Output.ShowPauseMenu _) =>
|
||||
{
|
||||
AnimationPlayer.Play("wait_and_load");
|
||||
var currentFloor = Floors.ElementAt(GameRepo.CurrentFloor);
|
||||
currentFloor.CallDeferred(MethodName.QueueFree, []);
|
||||
|
||||
if (GameRepo.EquippedWeapon.Value.WeaponInfo != null && GameRepo.EquippedWeapon.Value.WeaponInfo.WeaponTags.Contains(WeaponTag.BreaksOnChange))
|
||||
{
|
||||
GameRepo.InventoryItems.Value.Remove(GameRepo.EquippedWeapon.Value);
|
||||
GameRepo.OnWeaponEquipped(new Weapon());
|
||||
}
|
||||
|
||||
PauseMenu.Show();
|
||||
PauseMenu.FadeIn();
|
||||
})
|
||||
.Handle((in GameLogic.Output.SetPauseMode output) =>
|
||||
{
|
||||
CallDeferred(nameof(SetPauseMode), output.IsPaused);
|
||||
})
|
||||
.Handle((in GameLogic.Output.SetInventoryMode _) => { InventoryMenu.RedrawInventory(); InventoryMenu.Show(); })
|
||||
.Handle((in GameLogic.Output.HideInventory _) => { InventoryMenu.Hide(); })
|
||||
.Handle((in GameLogic.Output.ShowMiniMap _) => { MiniMap.Show(); })
|
||||
.Handle((in GameLogic.Output.HideMiniMap _) => { MiniMap.Hide(); })
|
||||
.Handle((in GameLogic.Output.GameOver _) => { AppRepo.OnGameOver(); });
|
||||
.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());
|
||||
AnimationPlayer.AnimationStarted += AnimationPlayer_AnimationStarted;
|
||||
AnimationPlayer.AnimationFinished += AnimationPlayer_AnimationFinished;
|
||||
|
||||
AnimationPlayer.Play("wait_and_load");
|
||||
|
||||
this.Provide();
|
||||
}
|
||||
@@ -123,20 +104,6 @@ public partial class Game : Node3D, IGame
|
||||
GameLogic.Input(new GameLogic.Input.InventoryMenuToggle());
|
||||
}
|
||||
|
||||
private void AnimationPlayer_AnimationStarted(StringName animName)
|
||||
{
|
||||
var newFloor = Floors.ElementAt(GameRepo.CurrentFloor + 1);
|
||||
newFloor.CallDeferred(nameof(newFloor.InitializeDungeon), []);
|
||||
newFloor.Show();
|
||||
}
|
||||
|
||||
private void AnimationPlayer_AnimationFinished(StringName animName)
|
||||
{
|
||||
var spawnPoints = GetTree().GetNodesInGroup("Exit").OfType<Marker3D>();
|
||||
Teleport.GlobalPosition = spawnPoints.Last().GlobalPosition;
|
||||
GameRepo.CurrentFloor++;
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed(GameInputs.Inventory))
|
||||
|
||||
Reference in New Issue
Block a user