Improvements to Chinthe animation logic Fix broken Godot Tool system and just use a more manual approach to setting map nodes Remove ItemDatabase from individual room scenes
56 lines
2.0 KiB
C#
56 lines
2.0 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace Zennysoft.Game.Ma;
|
|
|
|
public static class LayoutToScenePathConverter
|
|
{
|
|
private static readonly string _folderPath = "res://src/map/dungeon/floors";
|
|
|
|
public static string Convert(FloorNode floorNode)
|
|
{
|
|
if (floorNode is DungeonFloorNode dungeonFloorNode)
|
|
return RandomDungeonFloor(dungeonFloorNode);
|
|
else if (floorNode is SpecialFloorNode specialFloorNode)
|
|
return SpawnSpecialFloor(specialFloorNode.FloorName);
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
private static string SpawnSpecialFloor(SpecialFloorType floorType)
|
|
{
|
|
var path = $"{_folderPath}/Special Floors/";
|
|
var files = DirAccess.GetFilesAt(path);
|
|
switch (floorType)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
|
|
private static string RandomDungeonFloor(DungeonFloorNode floorNode)
|
|
{
|
|
var folderName = _folderPath + "/" + floorNode.FolderName;
|
|
var floorList = DirAccess.GetFilesAt(folderName).Where(x => x.EndsWith(".tscn"));
|
|
var rng = new RandomNumberGenerator();
|
|
rng.Randomize();
|
|
var index = (int)rng.RandWeighted([.. floorNode.FloorOdds]);
|
|
var result = floorList.ElementAt(index);
|
|
return folderName + "/" + result;
|
|
}
|
|
}
|