Teleport works, item pickup is broken
This commit is contained in:
@@ -4,6 +4,8 @@ using Chickensoft.AutoInject;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public interface IGame : IProvide<IGameRepo>, INode3D;
|
||||
|
||||
@@ -14,6 +16,8 @@ public partial class Game : Node3D, IGame
|
||||
|
||||
IGameRepo IProvide<IGameRepo>.Value() => GameRepo;
|
||||
|
||||
public IInstantiator Instantiator { get; set; } = default!;
|
||||
|
||||
public IGameLogic GameLogic { get; set; } = default!;
|
||||
|
||||
public IGameRepo GameRepo { get; set; } = default!;
|
||||
@@ -28,21 +32,57 @@ public partial class Game : Node3D, IGame
|
||||
|
||||
[Node] public NavigationRegion3D NavigationRegion { 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!;
|
||||
|
||||
private List<IDungeonFloor> Floors;
|
||||
|
||||
private int _currentFloor = -1;
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
GameRepo = new GameRepo();
|
||||
GameLogic = new GameLogic();
|
||||
GameLogic.Set(GameRepo);
|
||||
GameLogic.Set(AppRepo);
|
||||
Instantiator = new Instantiator(GetTree());
|
||||
Floors = new List<IDungeonFloor> { Overworld, Floor1, Floor2, Floor3 };
|
||||
Teleport.BodyEntered += OnTeleportEntered;
|
||||
}
|
||||
|
||||
private void OnTeleportEntered(Node3D body)
|
||||
{
|
||||
GameLogic.Input(new GameLogic.Input.LoadNextFloor());
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
GameBinding = GameLogic.Bind();
|
||||
GameBinding
|
||||
.Handle((in GameLogic.Output.StartGame _) => { })
|
||||
.Handle((in GameLogic.Output.SetPauseMode output) => { CallDeferred(nameof(SetPauseMode), output.IsPaused); })
|
||||
.Handle((in GameLogic.Output.StartGame _) =>
|
||||
{
|
||||
})
|
||||
.Handle((in GameLogic.Output.LoadNextFloor _) =>
|
||||
{
|
||||
SetPauseMode(true);
|
||||
AnimationPlayer.Play("wait_and_load");
|
||||
var currentFloor = Floors.ElementAt(_currentFloor);
|
||||
currentFloor.CallDeferred(MethodName.QueueFree, []);
|
||||
|
||||
})
|
||||
.Handle((in GameLogic.Output.SetPauseMode output) =>
|
||||
{
|
||||
CallDeferred(nameof(SetPauseMode), output.IsPaused);
|
||||
})
|
||||
.Handle((in GameLogic.Output.SetInventoryMode _) => { InventoryMenu.PopulateItems(_.Inventory); InventoryMenu.Show(); })
|
||||
.Handle((in GameLogic.Output.HideInventory _) => { InventoryMenu.Hide(); InventoryMenu.ClearItems(); })
|
||||
.Handle((in GameLogic.Output.ShowMiniMap _) => { MiniMap.Show(); })
|
||||
@@ -51,10 +91,31 @@ public partial class Game : Node3D, IGame
|
||||
GameLogic.Start();
|
||||
|
||||
GameLogic.Input(new GameLogic.Input.Initialize());
|
||||
AnimationPlayer.AnimationStarted += AnimationPlayer_AnimationStarted;
|
||||
AnimationPlayer.AnimationFinished += AnimationPlayer_AnimationFinished;
|
||||
|
||||
AnimationPlayer.Play("wait_and_load");
|
||||
|
||||
this.Provide();
|
||||
}
|
||||
|
||||
private void AnimationPlayer_AnimationStarted(StringName animName)
|
||||
{
|
||||
SetPauseMode(true);
|
||||
|
||||
var newFloor = Floors.ElementAt(_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;
|
||||
_currentFloor++;
|
||||
SetPauseMode(false);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed(GameInputs.Inventory))
|
||||
|
||||
Reference in New Issue
Block a user