using Godot; using Newlon; using System.Collections.Generic; public partial class GameRegistry : Node { private const string PLANT_RESOURCE_PATH = "res://resources/plants/"; private const string ZOMBIE_RESOURCE_PATH = "res://resources/zombies/"; public static GameRegistry Instance { get; private set; } public static readonly Dictionary PlantDictionary = []; public static readonly Dictionary ZombieDictionary = []; public override void _Ready() { //Plant init string[] plantFiles = ResourceLoader.ListDirectory(PLANT_RESOURCE_PATH); foreach (var file in plantFiles) { if (ResourceLoader.Exists(PLANT_RESOURCE_PATH + file)) { var plant = ResourceLoader.Load(PLANT_RESOURCE_PATH + file); plant.internal_id = file.ToLower().Split('.')[0]; PlantDictionary.Add(file.ToLower().Split('.')[0], plant); } } //Zombie init string[] zombieFiles = ResourceLoader.ListDirectory(ZOMBIE_RESOURCE_PATH); foreach (var file in zombieFiles) { if (ResourceLoader.Exists(ZOMBIE_RESOURCE_PATH + file)) { var zombie = ResourceLoader.Load(ZOMBIE_RESOURCE_PATH + file); zombie.internal_id = file.ToLower().Split('.')[0]; ZombieDictionary.Add(file.ToLower().Split('.')[0], zombie); } } } public static PlantResource GetPlantByName(string name) { if (PlantDictionary.ContainsKey(name) == false) return null; return PlantDictionary[name]; } public static List GetPlantNames() { List result = []; foreach (var key in PlantDictionary.Keys) { result.Add(key); } return result; } public static List GetPlants() { List result = []; foreach (var value in PlantDictionary.Values) { result.Add(value); } return result; } public static int GetPlantCount() { return PlantDictionary.Count; } public static ZombieResource GetZombieByName(string name) { if (ZombieDictionary.ContainsKey(name) == false) return null; return ZombieDictionary[name]; } public static List GetZombieNames() { List result = []; foreach (var key in ZombieDictionary.Keys) { result.Add(key); } return result; } public static List GetZombies() { List result = []; foreach (var value in ZombieDictionary.Values) { result.Add(value); } return result; } public static int GetZombieCount() { return ZombieDictionary.Count; } }