Speeeeeed up
This commit is contained in:
@@ -4,6 +4,8 @@ using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.SaveFileBuilder;
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -13,7 +15,7 @@ public interface IMap : INode3D, IProvide<ISaveChunk<MapData>>
|
||||
|
||||
void LoadFloor();
|
||||
|
||||
List<string> FloorScenes { get; }
|
||||
ImmutableDictionary<Floor, string> FloorScenes { get; }
|
||||
|
||||
IDungeonFloor CurrentFloor { get; }
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,7 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://by67pn7fdsg1m"]
|
||||
[gd_scene load_steps=2 format=3 uid="uid://by67pn7fdsg1m"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://14e8mu48ed4" path="res://src/map/Map.cs" id="1_bw70o"]
|
||||
[ext_resource type="PackedScene" uid="uid://dl6h1djc27ddl" path="res://src/map/dungeon/floors/Floor00.tscn" id="2_ne2vg"]
|
||||
[ext_resource type="PackedScene" uid="uid://jha0mhct0e7i" path="res://src/map/dungeon/rooms/Set B/40. Goddess of Guidance's Room - True Form.tscn" id="3_ne2vg"]
|
||||
[ext_resource type="PackedScene" uid="uid://5ja3qxn8h7iw" path="res://src/map/dungeon/rooms/Set A/15. Boss Floor A.tscn" id="6_abpbr"]
|
||||
[ext_resource type="PackedScene" uid="uid://dvnc26rebk6o0" path="res://src/map/overworld/Overworld.tscn" id="6_ne2vg"]
|
||||
[ext_resource type="PackedScene" uid="uid://ceo7ph483io44" path="res://src/map/dungeon/rooms/Set B/34. Boss Floor B.tscn" id="7_caf7v"]
|
||||
[ext_resource type="PackedScene" uid="uid://bo20ffw2ygbks" path="res://src/map/dungeon/rooms/Set B/35. Goddess of Guidance's Room.tscn" id="8_y74f3"]
|
||||
[ext_resource type="PackedScene" uid="uid://dttk7gis5ibge" path="res://src/map/dungeon/rooms/Set B/30. Void Room.tscn" id="9_dbqu2"]
|
||||
[ext_resource type="PackedScene" uid="uid://cyrrhoarhxlhg" path="res://src/map/dungeon/rooms/Set B/36. Final Floor.tscn" id="10_xcm54"]
|
||||
|
||||
[node name="Map" type="Node3D"]
|
||||
script = ExtResource("1_bw70o")
|
||||
_floors = Array[PackedScene]([ExtResource("7_caf7v"), ExtResource("6_abpbr"), ExtResource("6_ne2vg"), ExtResource("8_y74f3"), ExtResource("2_ne2vg"), ExtResource("9_dbqu2"), ExtResource("3_ne2vg"), ExtResource("10_xcm54")])
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
Floors = Array[int]([3, 2, 0, 4, 1, 5, 6])
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
[ext_resource type="Texture2D" uid="uid://dd1jvmfs1cbbg" path="res://src/map/dungeon/models/Set B/35. Goddess of Guidance's Floor/GoG Room mirrored_floral_single_tile.jpg" id="13_aytwf"]
|
||||
[ext_resource type="Texture2D" uid="uid://nvg6i8gbgqjv" path="res://src/map/dungeon/models/Set B/35. Goddess of Guidance's Floor/GoG Room mirrored_angkor_mural.jpg" id="14_tf4w3"]
|
||||
[ext_resource type="Texture2D" uid="uid://3w1ac5fvks5v" path="res://src/map/dungeon/models/Set B/35. Goddess of Guidance's Floor/GoG Room mirrored_area_2_big_tile.png" id="15_nduur"]
|
||||
[ext_resource type="Shader" path="res://src/map/map shaders/GOGROOM Water.gdshader" id="16_q4do2"]
|
||||
[ext_resource type="Shader" uid="uid://beg8sp6kw66w8" path="res://src/map/map shaders/GOGROOM Water.gdshader" id="16_q4do2"]
|
||||
[ext_resource type="PackedScene" uid="uid://dbvr8ewajja6a" path="res://src/enemy/EnemyDatabase.tscn" id="17_j4ho3"]
|
||||
[ext_resource type="PackedScene" uid="uid://bs56ccgosmu47" path="res://src/enemy/enemy_types/01. sproingy/Sproingy.tscn" id="18_qt11j"]
|
||||
[ext_resource type="PackedScene" uid="uid://b0gwivt7cw7nd" path="res://src/enemy/enemy_types/02. michael/Michael.tscn" id="19_tkf4r"]
|
||||
|
||||
Reference in New Issue
Block a user