Add map loading logic and spawn rate control

This commit is contained in:
2025-09-30 02:32:03 -07:00
parent 70d1871985
commit 6f582fcca1
43 changed files with 470 additions and 118 deletions

View File

@@ -0,0 +1,49 @@
using Godot;
using System;
using System.Linq;
using static SpecialFloorLayout;
namespace Zennysoft.Game.Ma;
public static class LayoutToScenePathConverter
{
private static readonly string _folderPath = "res://src/map/dungeon/floors";
public static string Convert(LayoutType layoutType)
{
if (layoutType is SpecialFloorLayout specialFloor)
{
var path = $"{_folderPath}/Special Floors/";
var files = DirAccess.GetFilesAt(path);
switch (specialFloor.FloorName)
{
case SpecialFloorType.Overworld:
return path + files.Single(x => x.Contains("Overworld.tscn"));
case SpecialFloorType.Altar:
return path + files.Single(x => x.Contains("Altar.tscn"));
case SpecialFloorType.BossFloorA:
return path + files.Single(x => x.Contains("Boss Floor A.tscn"));
case SpecialFloorType.BossFloorB:
return path + files.Single(x => x.Contains("Boss Floor B.tscn"));
case SpecialFloorType.GoddessOfGuidanceFloor:
return path + files.Single(x => x.Contains("Goddess of Guidance's Room.tscn"));
case SpecialFloorType.TrueGoddessOfGuidanceFloor:
return path + files.Single(x => x.Contains("Goddess of Guidance's Room - True Form.tscn"));
case SpecialFloorType.FinalFloor:
return path + files.Single(x => x.Contains("Final Floor.tscn"));
default:
throw new NotImplementedException();
}
}
else if (layoutType is DungeonFloorLayout dungeonFloor)
{
var rng = new RandomNumberGenerator();
rng.Randomize();
var index = (int)rng.RandWeighted([.. dungeonFloor.LayoutWithSpawnRate.Values]);
var result = dungeonFloor.LayoutWithSpawnRate.ElementAt(index);
return _folderPath + "/" + result.Key;
}
throw new NotImplementedException();
}
}