Add map loading logic and spawn rate control
This commit is contained in:
49
Zennysoft.Game.Ma/src/map/LayoutToScenePathConverter.cs
Normal file
49
Zennysoft.Game.Ma/src/map/LayoutToScenePathConverter.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user