Files
GameJamDungeon/src/map/Map.cs
Zenny b26654346b Put minimap back in place
Note: issue still exists where the last spot the player existed before the level finished loading is marked visibile on the minimap
2025-03-03 02:45:45 -08:00

66 lines
1.6 KiB
C#

using Chickensoft.AutoInject;
using Chickensoft.GodotNodeInterfaces;
using Chickensoft.Introspection;
using Godot;
using System.Linq;
namespace GameJamDungeon;
public interface IMap : INode3D
{
public Godot.Collections.Array<PackedScene> Floors { get; }
public IDungeonFloor CurrentFloor { get; }
public void SpawnNextFloor();
public Transform3D GetPlayerSpawnPosition();
}
[Meta(typeof(IAutoNode))]
public partial class Map : Node3D, IMap
{
public override void _Notification(int what) => this.Notify(what);
[Dependency]
public IGame Game => this.DependOn<IGame>();
[Dependency]
public IPlayer Player => this.DependOn<IPlayer>();
[Export]
public Godot.Collections.Array<PackedScene> Floors { get; set; } = default!;
public IDungeonFloor CurrentFloor { get; private set; }
public void Setup()
{
LoadFloor();
}
public void SpawnNextFloor()
{
var oldFloor = CurrentFloor;
oldFloor.CallDeferred(MethodName.QueueFree, []);
LoadFloor();
CurrentFloor.InitializeDungeon();
var transform = GetPlayerSpawnPosition();
Player.TeleportPlayer(new Vector3(transform.Origin.X, -1.75f, transform.Origin.Z));
CurrentFloor.FloorIsLoaded = true;
Game.NextFloorLoaded();
}
public Transform3D GetPlayerSpawnPosition() => CurrentFloor.GetPlayerSpawnPoint();
private void LoadFloor()
{
var currentFloorScene = Floors.First();
var instantiator = new Instantiator(GetTree());
var loadedScene = instantiator.LoadAndInstantiate<Node3D>(currentFloorScene.ResourcePath);
AddChild(loadedScene);
CurrentFloor = (IDungeonFloor)loadedScene;
Floors.Remove(currentFloorScene);
}
}