98 lines
2.2 KiB
C#
98 lines
2.2 KiB
C#
using Godot;
|
|
using Newlon.Resources;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Newlon;
|
|
|
|
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, EntityResource> EntityDictionary = [];
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
//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<PlantResource>(PLANT_RESOURCE_PATH + file);
|
|
EntityDictionary.Add(plant.GetInternalID(), 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<ZombieResource>(ZOMBIE_RESOURCE_PATH + file);
|
|
EntityDictionary.Add(zombie.GetInternalID(), zombie);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static EntityResource GetEntityByName(string name)
|
|
{
|
|
if (EntityDictionary.ContainsKey(name) == false) return null;
|
|
return EntityDictionary[name];
|
|
}
|
|
public static List<string> GetEntityNames()
|
|
{
|
|
List<string> result = [];
|
|
foreach (var key in EntityDictionary.Keys)
|
|
{
|
|
result.Add(key);
|
|
}
|
|
return result;
|
|
}
|
|
public static List<EntityResource> GetEntities()
|
|
{
|
|
List<EntityResource> result = [];
|
|
foreach (var value in EntityDictionary.Values)
|
|
{
|
|
result.Add(value);
|
|
}
|
|
return result;
|
|
}
|
|
public static List<PlantResource> GetPlants()
|
|
{
|
|
var entities = GetEntities();
|
|
List<PlantResource> plants = [];
|
|
|
|
foreach (var entity in entities)
|
|
{
|
|
if (entity is PlantResource plant)
|
|
{
|
|
plants.Add(plant);
|
|
}
|
|
}
|
|
|
|
return plants;
|
|
}
|
|
public static List<ZombieResource> GetZombies()
|
|
{
|
|
var entities = GetEntities();
|
|
List<ZombieResource> zombies = [];
|
|
|
|
foreach (var entity in entities)
|
|
{
|
|
if (entity is ZombieResource zombie)
|
|
{
|
|
zombies.Add(zombie);
|
|
}
|
|
}
|
|
|
|
return zombies;
|
|
}
|
|
public static int GetEntityCount()
|
|
{
|
|
return EntityDictionary.Count;
|
|
}
|
|
|
|
}
|