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 LayoutWithSpawnRate; [Export] public Dictionary 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(); 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 } }