69 lines
1.6 KiB
C#
69 lines
1.6 KiB
C#
using Godot;
|
|
using Godot.Collections;
|
|
using System.Linq;
|
|
using Zennysoft.Game.Ma;
|
|
|
|
[Tool]
|
|
public partial class DungeonFloorLayout : LayoutType
|
|
{
|
|
[Export]
|
|
public DungeonFloorSetType SetType
|
|
{
|
|
get => _setType;
|
|
set
|
|
{
|
|
_setType = value;
|
|
LayoutWithSpawnRate = [];
|
|
NotifyPropertyListChanged();
|
|
}
|
|
}
|
|
|
|
[ExportToolButton("Populate Map Data")]
|
|
public Callable PopulateMapList => Callable.From(() => PopulateDictionary(SetType));
|
|
|
|
[Export]
|
|
public Dictionary<string, float> LayoutWithSpawnRate;
|
|
|
|
[Export]
|
|
public Dictionary<EnemyType, float> EnemySpawnRates;
|
|
|
|
private string _floorPath = "res://src/map/dungeon/floors/";
|
|
private DungeonFloorSetType _setType;
|
|
|
|
private void PopulateDictionary(DungeonFloorSetType setType)
|
|
{
|
|
var floorPath = _floorPath;
|
|
var floorType = string.Empty;
|
|
if (setType == DungeonFloorSetType.SetA)
|
|
floorType = "SetAFloors";
|
|
else if (setType == DungeonFloorSetType.SetB)
|
|
floorType = "SetBFloors";
|
|
|
|
var pathToScenes = $"{floorPath}/{floorType}";
|
|
|
|
var files = DirAccess.GetFilesAt(pathToScenes).Where(x => x.EndsWith(".tscn"));
|
|
|
|
var newMaps = new Dictionary<string, float>();
|
|
foreach (var file in files)
|
|
{
|
|
if (LayoutWithSpawnRate.ContainsKey($"{floorType}/{file}"))
|
|
{
|
|
var spawnRate = LayoutWithSpawnRate.TryGetValue($"{floorType}/{file}", out var currentSpawnRate);
|
|
newMaps.Add($"{floorType}/{file}", currentSpawnRate);
|
|
}
|
|
else
|
|
newMaps.Add($"{floorType}/{file}", 1.0f);
|
|
}
|
|
|
|
LayoutWithSpawnRate = newMaps;
|
|
|
|
NotifyPropertyListChanged();
|
|
}
|
|
|
|
public enum DungeonFloorSetType
|
|
{
|
|
SetA,
|
|
SetB
|
|
}
|
|
}
|