game registry internal refactor

This commit is contained in:
Rendo 2025-07-25 18:02:47 +05:00
commit d5573db251
11 changed files with 68 additions and 188 deletions

View file

@ -7,8 +7,7 @@ public partial class GameRegistry : Node
private const string PLANT_RESOURCE_PATH = "res://assets/plants/";
private const string ZOMBIE_RESOURCE_PATH = "res://assets/zombies/";
public static GameRegistry Instance { get; private set; }
public static readonly Dictionary<string, PlantResource> PlantDictionary = [];
public static readonly Dictionary<string, ZombieResource> ZombieDictionary = [];
public static readonly Dictionary<string, DisplayResource> EntityDictionary = [];
public override void _EnterTree()
{
@ -21,10 +20,9 @@ public partial class GameRegistry : Node
{
var plant = ResourceLoader.Load<PlantResource>(PLANT_RESOURCE_PATH + file);
plant.internal_id = file.ToLower().Split('.')[0];
PlantDictionary.Add(file.ToLower().Split('.')[0], plant);
EntityDictionary.Add(file.ToLower().Split('.')[0], plant);
}
}
//Zombie init
string[] zombieFiles = ResourceLoader.ListDirectory(ZOMBIE_RESOURCE_PATH);
@ -34,66 +32,67 @@ public partial class GameRegistry : Node
{
var zombie = ResourceLoader.Load<ZombieResource>(ZOMBIE_RESOURCE_PATH + file);
zombie.internal_id = file.ToLower().Split('.')[0];
ZombieDictionary.Add(file.ToLower().Split('.')[0], zombie);
EntityDictionary.Add(file.ToLower().Split('.')[0], zombie);
}
}
}
public static PlantResource GetPlantByName(string name)
public static DisplayResource GetEntityByName(string name)
{
if (PlantDictionary.ContainsKey(name) == false) return null;
return PlantDictionary[name];
if (EntityDictionary.ContainsKey(name) == false) return null;
return EntityDictionary[name];
}
public static List<string> GetPlantNames()
public static List<string> GetEntityNames()
{
List<string> result = [];
foreach (var key in PlantDictionary.Keys)
foreach (var key in EntityDictionary.Keys)
{
result.Add(key);
}
return result;
}
public static List<DisplayResource> GetEntities()
{
List<DisplayResource> result = [];
foreach (var value in EntityDictionary.Values)
{
result.Add(value);
}
return result;
}
public static List<PlantResource> GetPlants()
{
List<PlantResource> result = [];
foreach (var value in PlantDictionary.Values)
{
result.Add(value);
}
return result;
}
public static int GetPlantCount()
{
return PlantDictionary.Count;
}
var entities = GetEntities();
List<PlantResource> plants = [];
public static ZombieResource GetZombieByName(string name)
{
if (ZombieDictionary.ContainsKey(name) == false) return null;
return ZombieDictionary[name];
}
public static List<string> GetZombieNames()
{
List<string> result = [];
foreach (var key in ZombieDictionary.Keys)
foreach (var entity in entities)
{
result.Add(key);
if (entity is PlantResource plant)
{
plants.Add(plant);
}
}
return result;
return plants;
}
public static List<ZombieResource> GetZombies()
{
List<ZombieResource> result = [];
foreach (var value in ZombieDictionary.Values)
{
result.Add(value);
}
return result;
}
var entities = GetEntities();
List<ZombieResource> zombies = [];
public static int GetZombieCount()
foreach (var entity in entities)
{
if (entity is ZombieResource zombie)
{
zombies.Add(zombie);
}
}
return zombies;
}
public static int GetEntityCount()
{
return ZombieDictionary.Count;
return EntityDictionary.Count;
}
}