Files
GameJamDungeon/src/map/Map.cs
2024-09-11 15:55:47 -07:00

49 lines
1.2 KiB
C#

using Chickensoft.AutoInject;
using Chickensoft.GodotNodeInterfaces;
using Chickensoft.Introspection;
using DialogueManagerRuntime;
using Godot;
using System.Collections.Generic;
using System.Linq;
namespace GameJamDungeon;
public interface IMap : INode3D
{
public List<IDungeonFloor> Floors { get; }
public Vector3 GetPlayerSpawnPoint();
}
[Meta(typeof(IAutoNode))]
public partial class Map : Node3D, IMap
{
public override void _Notification(int what) => this.Notify(what);
[Node] public Area3D Teleport { get; set; } = default!;
public List<IDungeonFloor> Floors { get; set; } = default!;
private IDungeonFloor _currentFloor;
public void Setup()
{
Floors = GetChildren().OfType<IDungeonFloor>().ToList();
_currentFloor = Floors.ElementAt(0);
Teleport.BodyEntered += OnTeleportEntered;
}
public Vector3 GetPlayerSpawnPoint()
{
return _currentFloor.GetPlayerSpawnPoint();
}
private void OnTeleportEntered(Node3D body)
{
DialogueManager.GetCurrentScene = (() => this);
var dialogueResource = GD.Load<Resource>("res://src/ui/dialogue/FloorExit.dialogue");
DialogueController.ShowDialogue(dialogueResource, "floor_exit");
}
}