91 lines
2.2 KiB
C#
91 lines
2.2 KiB
C#
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; }
|
|
private Dictionary<string, PlantResource> PlantDictionary = [];
|
|
private Dictionary<string, ZombieResource> ZombieDictionary = [];
|
|
|
|
public override void _Ready()
|
|
{
|
|
Instance = this;
|
|
|
|
//Plant init
|
|
string[] plantFiles = DirAccess.GetFilesAt(PLANT_RESOURCE_PATH);
|
|
|
|
foreach (var file in plantFiles)
|
|
{
|
|
if (ResourceLoader.Exists(PLANT_RESOURCE_PATH + file))
|
|
{
|
|
var plant = ResourceLoader.Load<PlantResource>(PLANT_RESOURCE_PATH + file);
|
|
PlantDictionary.Add(file.ToLower().Split('.')[0], plant);
|
|
}
|
|
}
|
|
|
|
//Zombie init
|
|
string[] zombieFiles = DirAccess.GetFilesAt(ZOMBIE_RESOURCE_PATH);
|
|
|
|
foreach (var file in zombieFiles)
|
|
{
|
|
if (ResourceLoader.Exists(ZOMBIE_RESOURCE_PATH + file))
|
|
{
|
|
var zombie = ResourceLoader.Load<ZombieResource>(ZOMBIE_RESOURCE_PATH + file);
|
|
ZombieDictionary.Add(file.ToLower().Split('.')[0], zombie);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static PlantResource GetPlantByName(string name)
|
|
{
|
|
if (Instance.PlantDictionary.ContainsKey(name) == false) return null;
|
|
return Instance.PlantDictionary[name];
|
|
}
|
|
public static List<string> GetPlantNames()
|
|
{
|
|
List<string> result = [];
|
|
foreach (var key in Instance.PlantDictionary.Keys)
|
|
{
|
|
result.Add(key);
|
|
}
|
|
return result;
|
|
}
|
|
public static List<PlantResource> GetPlants()
|
|
{
|
|
List<PlantResource> result = [];
|
|
foreach (var value in Instance.PlantDictionary.Values)
|
|
{
|
|
result.Add(value);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
public static ZombieResource GetZombieByName(string name)
|
|
{
|
|
if (Instance.ZombieDictionary.ContainsKey(name) == false) return null;
|
|
return Instance.ZombieDictionary[name];
|
|
}
|
|
public static List<string> GetZombieNames()
|
|
{
|
|
List<string> result = [];
|
|
foreach (var key in Instance.ZombieDictionary.Keys)
|
|
{
|
|
result.Add(key);
|
|
}
|
|
return result;
|
|
}
|
|
public static List<ZombieResource> GetZombies()
|
|
{
|
|
List<ZombieResource> result = [];
|
|
foreach (var value in Instance.ZombieDictionary.Values)
|
|
{
|
|
result.Add(value);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|