Survival mode ready

This commit is contained in:
Rendo 2025-06-26 20:18:19 +05:00
commit 7614b12076
50 changed files with 586 additions and 81 deletions

View file

@ -7,13 +7,11 @@ 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 static readonly Dictionary<string, PlantResource> PlantDictionary = [];
public static readonly Dictionary<string, ZombieResource> ZombieDictionary = [];
public override void _Ready()
public override void _Ready()
{
Instance = this;
//Plant init
string[] plantFiles = DirAccess.GetFilesAt(PLANT_RESOURCE_PATH);
@ -22,6 +20,7 @@ public partial class GameRegistry : Node
if (ResourceLoader.Exists(PLANT_RESOURCE_PATH + file))
{
var plant = ResourceLoader.Load<PlantResource>(PLANT_RESOURCE_PATH + file);
plant.internal_id = file.ToLower().Split('.')[0];
PlantDictionary.Add(file.ToLower().Split('.')[0], plant);
}
}
@ -34,6 +33,7 @@ public partial class GameRegistry : Node
if (ResourceLoader.Exists(ZOMBIE_RESOURCE_PATH + file))
{
var zombie = ResourceLoader.Load<ZombieResource>(ZOMBIE_RESOURCE_PATH + file);
zombie.internal_id = file.ToLower().Split('.')[0];
ZombieDictionary.Add(file.ToLower().Split('.')[0], zombie);
}
}
@ -41,13 +41,13 @@ public partial class GameRegistry : Node
public static PlantResource GetPlantByName(string name)
{
if (Instance.PlantDictionary.ContainsKey(name) == false) return null;
return Instance.PlantDictionary[name];
if (PlantDictionary.ContainsKey(name) == false) return null;
return PlantDictionary[name];
}
public static List<string> GetPlantNames()
{
List<string> result = [];
foreach (var key in Instance.PlantDictionary.Keys)
foreach (var key in PlantDictionary.Keys)
{
result.Add(key);
}
@ -56,23 +56,26 @@ public partial class GameRegistry : Node
public static List<PlantResource> GetPlants()
{
List<PlantResource> result = [];
foreach (var value in Instance.PlantDictionary.Values)
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 (Instance.ZombieDictionary.ContainsKey(name) == false) return null;
return Instance.ZombieDictionary[name];
if (ZombieDictionary.ContainsKey(name) == false) return null;
return ZombieDictionary[name];
}
public static List<string> GetZombieNames()
{
List<string> result = [];
foreach (var key in Instance.ZombieDictionary.Keys)
foreach (var key in ZombieDictionary.Keys)
{
result.Add(key);
}
@ -81,11 +84,16 @@ public partial class GameRegistry : Node
public static List<ZombieResource> GetZombies()
{
List<ZombieResource> result = [];
foreach (var value in Instance.ZombieDictionary.Values)
foreach (var value in ZombieDictionary.Values)
{
result.Add(value);
}
return result;
}
public static int GetZombieCount()
{
return ZombieDictionary.Count;
}
}