Speeeeeed up
This commit is contained in:
@@ -5,6 +5,7 @@ using Chickensoft.LogicBlocks;
|
||||
using Chickensoft.SaveFileBuilder;
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
@@ -31,9 +32,9 @@ public partial class Map : Node3D, IMap
|
||||
#endregion
|
||||
|
||||
[Export]
|
||||
private Godot.Collections.Array<PackedScene> _floors { get; set; } = default!;
|
||||
private Godot.Collections.Array<Floor> Floors { get; set; } = default!;
|
||||
|
||||
public List<string> FloorScenes { get; private set; } = [];
|
||||
public ImmutableDictionary<Floor, string> FloorScenes { get; private set; }
|
||||
|
||||
public IDungeonFloor CurrentFloor { get; private set; }
|
||||
|
||||
@@ -41,77 +42,76 @@ public partial class Map : Node3D, IMap
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
MapChunk = new SaveChunk<MapData>(
|
||||
onSave: (chunk) => new MapData()
|
||||
{
|
||||
FloorScenes = FloorScenes,
|
||||
},
|
||||
onLoad: (chunk, data) =>
|
||||
{
|
||||
FloorScenes = data.FloorScenes;
|
||||
}
|
||||
);
|
||||
GameChunk.AddChunk(MapChunk);
|
||||
|
||||
GameChunk.AddChunk(MapChunk);
|
||||
this.Provide();
|
||||
|
||||
this.Provide();
|
||||
|
||||
InitializeMapData();
|
||||
InitializeMapData();
|
||||
}
|
||||
|
||||
public void InitializeMapData()
|
||||
{
|
||||
ClearMap();
|
||||
FloorScenes = [];
|
||||
foreach (var floor in _floors)
|
||||
FloorScenes.Add(floor.ResourcePath);
|
||||
CurrentFloorNumber.OnNext(0);
|
||||
ClearMap();
|
||||
FloorScenes = ImmutableDictionary<Floor, string>.Empty
|
||||
.Add(Floor.Overworld, $"res://src/map/overworld/Overworld.tscn")
|
||||
.Add(Floor.Altar, $"res://src/map/dungeon/floors/Floor00.tscn")
|
||||
.Add(Floor.BossFloorA, $"res://src/map/dungeon/rooms/Set A/15. Boss Floor A.tscn")
|
||||
.Add(Floor.BossFloorB, $"res://src/map/dungeon/rooms/Set B/34. Boss Floor B.tscn")
|
||||
.Add(Floor.GoddessOfGuidanceFloor, $"res://src/map/dungeon/rooms/Set B/35. Goddess of Guidance's Room.tscn")
|
||||
.Add(Floor.VoidRoom, $"res://src/map/dungeon/rooms/Set B/30. Void Room.tscn")
|
||||
.Add(Floor.FinalFloor, $"res://src/map/dungeon/rooms/Set B/36. Final Floor.tscn")
|
||||
.Add(Floor.Floor01, $"res://src/map/dungeon/floors/Floor01.tscn")
|
||||
.Add(Floor.Floor02, $"res://src/map/dungeon/floors/Floor02.tscn")
|
||||
.Add(Floor.Floor03, $"res://src/map/dungeon/floors/Floor03.tscn")
|
||||
.Add(Floor.Floor04, $"res://src/map/dungeon/floors/Floor04.tscn")
|
||||
.Add(Floor.Floor05, $"res://src/map/dungeon/floors/Floor05.tscn");
|
||||
CurrentFloorNumber.OnNext(0);
|
||||
}
|
||||
|
||||
public void LoadMap()
|
||||
{
|
||||
LoadFloor();
|
||||
CurrentFloor.InitializeDungeon();
|
||||
var transform = GetPlayerSpawnPosition();
|
||||
Player.TeleportPlayer(transform);
|
||||
CurrentFloor.FloorIsLoaded = true;
|
||||
LoadFloor();
|
||||
CurrentFloor.InitializeDungeon();
|
||||
var transform = GetPlayerSpawnPosition();
|
||||
Player.TeleportPlayer(transform);
|
||||
CurrentFloor.FloorIsLoaded = true;
|
||||
}
|
||||
|
||||
private void ClearMap()
|
||||
{
|
||||
CurrentFloor?.CallDeferred(MethodName.QueueFree, []);
|
||||
CurrentFloor?.CallDeferred(MethodName.QueueFree, []);
|
||||
}
|
||||
|
||||
public void SpawnNextFloor()
|
||||
{
|
||||
ClearMap();
|
||||
LoadFloor();
|
||||
CurrentFloor.InitializeDungeon();
|
||||
var transform = GetPlayerSpawnPosition();
|
||||
Player.TeleportPlayer(transform);
|
||||
CurrentFloor.FloorIsLoaded = true;
|
||||
CurrentFloorNumber.OnNext(CurrentFloorNumber.Value + 1);
|
||||
ClearMap();
|
||||
LoadFloor();
|
||||
CurrentFloor.InitializeDungeon();
|
||||
var transform = GetPlayerSpawnPosition();
|
||||
Player.TeleportPlayer(transform);
|
||||
CurrentFloor.FloorIsLoaded = true;
|
||||
CurrentFloorNumber.OnNext(CurrentFloorNumber.Value + 1);
|
||||
}
|
||||
|
||||
public IDungeonRoom GetPlayersCurrentRoom()
|
||||
{
|
||||
var rooms = CurrentFloor.Rooms;
|
||||
var playersRoom = rooms.SingleOrDefault(x => x.IsPlayerInRoom);
|
||||
return playersRoom;
|
||||
var rooms = CurrentFloor.Rooms;
|
||||
var playersRoom = rooms.SingleOrDefault(x => x.IsPlayerInRoom);
|
||||
return playersRoom;
|
||||
}
|
||||
|
||||
public Transform3D GetPlayerSpawnPosition() => CurrentFloor.GetPlayerSpawnPoint();
|
||||
|
||||
public void LoadFloor()
|
||||
{
|
||||
ClearMap();
|
||||
var currentFloorScene = FloorScenes.First();
|
||||
var instantiator = new Instantiator(GetTree());
|
||||
var loadedScene = instantiator.LoadAndInstantiate<Node3D>(currentFloorScene);
|
||||
AddChild(loadedScene);
|
||||
CurrentFloor = (IDungeonFloor)loadedScene;
|
||||
FloorScenes.Remove(currentFloorScene);
|
||||
var transform = GetPlayerSpawnPosition();
|
||||
Player.TeleportPlayer(transform);
|
||||
ClearMap();
|
||||
FloorScenes.TryGetValue(Floors.First(), out var currentFloorScene);
|
||||
var instantiator = new Instantiator(GetTree());
|
||||
var loadedScene = instantiator.LoadAndInstantiate<Node3D>(currentFloorScene);
|
||||
AddChild(loadedScene);
|
||||
CurrentFloor = (IDungeonFloor)loadedScene;
|
||||
Floors.Remove(Floors.First());
|
||||
var transform = GetPlayerSpawnPosition();
|
||||
Player.TeleportPlayer(transform);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user