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

@ -1,41 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://cubfkr2mkgxjc"]
[ext_resource type="Script" uid="uid://dac0bvlhho7u4" path="res://scripts/DebugZombieSpawner.cs" id="1_m367a"]
[node name="DebugZombieSpawner" type="PopupPanel" node_paths=PackedStringArray("label", "line", "spin")]
initial_position = 1
size = Vector2i(200, 100)
visible = true
script = ExtResource("1_m367a")
label = NodePath("Vbox/Similars")
line = NodePath("Vbox/Line/LineEdit")
spin = NodePath("Vbox/Line/SpinBox")
[node name="Vbox" type="VBoxContainer" parent="."]
offset_left = 4.0
offset_top = 4.0
offset_right = 196.0
offset_bottom = 96.0
[node name="Line" type="HBoxContainer" parent="Vbox"]
layout_mode = 2
[node name="LineEdit" type="LineEdit" parent="Vbox/Line"]
layout_mode = 2
size_flags_horizontal = 3
focus_next = NodePath("../SpinBox")
max_length = 16
[node name="SpinBox" type="SpinBox" parent="Vbox/Line"]
layout_mode = 2
min_value = 1.0
max_value = 50.0
value = 1.0
[node name="Similars" type="Label" parent="Vbox"]
layout_mode = 2
size_flags_vertical = 3
[connection signal="popup_hide" from="." to="." method="OnPopupHide"]
[connection signal="text_changed" from="Vbox/Line/LineEdit" to="." method="OnTextChanged"]
[connection signal="text_submitted" from="Vbox/Line/LineEdit" to="." method="OnTextSubmitted"]

View file

@ -814,7 +814,7 @@ metadata/_edit_lock_ = true
[node name="RightUpperLeg" type="Bone2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt"]
use_parent_material = true
position = Vector2(-6, 3)
scale = Vector2(0.999836, 0.999836)
scale = Vector2(0.999837, 0.999837)
rest = Transform2D(1, 0, 0, 1, -6, 3)
editor_settings/show_bone_gizmo = false
@ -826,13 +826,13 @@ metadata/_edit_lock_ = true
[node name="RightLowerLeg" type="Bone2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/RightUpperLeg"]
position = Vector2(-2, 12)
scale = Vector2(0.999837, 0.999837)
scale = Vector2(0.99983, 0.99983)
rest = Transform2D(1, 0, 0, 1, -2, 12)
editor_settings/show_bone_gizmo = false
[node name="RightFoot" type="Bone2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/RightUpperLeg/RightLowerLeg"]
position = Vector2(-2, 14)
scale = Vector2(0.999832, 0.999832)
scale = Vector2(0.999834, 0.999834)
rest = Transform2D(1, 0, 0, 1, -2, 14)
auto_calculate_length_and_angle = false
length = 12.0
@ -855,7 +855,7 @@ metadata/_edit_lock_ = true
[node name="LeftUpperLeg" type="Bone2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt"]
use_parent_material = true
position = Vector2(6, 4)
scale = Vector2(0.99983, 0.99983)
scale = Vector2(0.999834, 0.999834)
rest = Transform2D(1, 0, 0, 1, 6, 4)
editor_settings/show_bone_gizmo = false
@ -867,7 +867,7 @@ metadata/_edit_lock_ = true
[node name="LeftLowerLeg" type="Bone2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/LeftUpperLeg"]
position = Vector2(-1, 13)
scale = Vector2(0.999835, 0.999835)
scale = Vector2(0.99983, 0.99983)
rest = Transform2D(1, 0, 0, 1, -1, 13)
editor_settings/show_bone_gizmo = false
@ -879,7 +879,7 @@ metadata/_edit_lock_ = true
[node name="LeftFoot" type="Bone2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/LeftUpperLeg/LeftLowerLeg"]
position = Vector2(6, 10)
scale = Vector2(0.999833, 0.999833)
scale = Vector2(0.999824, 0.999824)
rest = Transform2D(1, 0, 0, 1, 6, 10)
auto_calculate_length_and_angle = false
length = 12.0
@ -903,7 +903,7 @@ editor_settings/show_bone_gizmo = false
z_index = -1
use_parent_material = true
position = Vector2(-14, -23)
scale = Vector2(0.999827, 0.999827)
scale = Vector2(0.999829, 0.999829)
rest = Transform2D(1, 0, 0, 1, -14, -23)
editor_settings/show_bone_gizmo = false
@ -915,13 +915,13 @@ metadata/_edit_lock_ = true
[node name="RightLowerArm" type="Bone2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/Body/RightUpperArm"]
position = Vector2(-2, 15)
scale = Vector2(0.999826, 0.999826)
scale = Vector2(0.999829, 0.999829)
rest = Transform2D(1, 0, 0, 1, -2, 15)
editor_settings/show_bone_gizmo = false
[node name="RightHand" type="Bone2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/Body/RightUpperArm/RightLowerArm"]
position = Vector2(-1, 13)
scale = Vector2(0.999829, 0.999829)
scale = Vector2(0.999824, 0.999824)
rest = Transform2D(1, 0, 0, 1, -1, 13)
auto_calculate_length_and_angle = false
length = 8.0
@ -949,8 +949,8 @@ metadata/_edit_lock_ = true
[node name="Tie" type="Bone2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/Body"]
position = Vector2(-9, -21)
rotation = 0.0566317
skew = -0.0004673
rotation = 0.12179
skew = -0.000472784
rest = Transform2D(1, 0, 0, 1, -9, -21)
auto_calculate_length_and_angle = false
length = 24.0
@ -965,7 +965,7 @@ metadata/_edit_lock_ = true
[node name="Head" type="Bone2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/Body"]
position = Vector2(-10, -25)
scale = Vector2(0.999832, 0.999832)
scale = Vector2(0.999829, 0.999829)
rest = Transform2D(1, 0, 0, 1, -10, -25)
editor_settings/show_bone_gizmo = false
@ -988,7 +988,6 @@ metadata/_edit_lock_ = true
[node name="Right_Eye" type="Sprite2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/Body/Head/HeadParticle/Head"]
position = Vector2(-16, -8)
scale = Vector2(1, 1)
texture = SubResource("AtlasTexture_vcc72")
centered = false
offset = Vector2(-2, -2)
@ -996,15 +995,14 @@ metadata/_edit_lock_ = true
[node name="Left_Eye" type="Sprite2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/Body/Head/HeadParticle/Head"]
position = Vector2(-4, -9)
scale = Vector2(1, 1)
texture = SubResource("AtlasTexture_kto0i")
centered = false
offset = Vector2(-2, -2)
metadata/_edit_lock_ = true
[node name="Jaw" type="Sprite2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/Body/Head/HeadParticle/Head"]
position = Vector2(-3.0007, 2.99882)
rotation = 0.00549593
position = Vector2(-3.00149, 2.99746)
rotation = 0.0118193
scale = Vector2(0.999828, 0.999828)
texture = SubResource("AtlasTexture_x5uj2")
centered = false
@ -1056,7 +1054,7 @@ remote_path = NodePath("../../HeadParticle/Head/Left_Eye")
[node name="LeftUpperArm" type="Bone2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/Body"]
position = Vector2(-1, -20)
scale = Vector2(0.999826, 0.999826)
scale = Vector2(0.999835, 0.999835)
rest = Transform2D(1, 0, 0, 1, -1, -20)
editor_settings/show_bone_gizmo = false
@ -1078,8 +1076,8 @@ minTorque = -45.0
maxTorque = 45.0
[node name="Left_Lower_Arm" type="Sprite2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/Body/LeftUpperArm/HandProjectile"]
rotation = 0.0532462
scale = Vector2(0.999998, 0.999998)
rotation = 0.114509
scale = Vector2(1, 1)
texture = SubResource("AtlasTexture_auqeq")
centered = false
offset = Vector2(-5, 0)
@ -1088,7 +1086,7 @@ metadata/_edit_lock_ = true
[node name="Left_Hand" type="Sprite2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/Body/LeftUpperArm/HandProjectile/Left_Lower_Arm"]
show_behind_parent = true
position = Vector2(-0.99983, 12.9978)
rotation = -0.0234996
rotation = -0.0505374
scale = Vector2(0.99966, 0.99966)
texture = SubResource("AtlasTexture_vlvtp")
centered = false
@ -1105,13 +1103,13 @@ _observedEntity = NodePath("../../../../../../../..")
[node name="LeftLowerArm" type="Bone2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/Body/LeftUpperArm"]
position = Vector2(-2, 14)
scale = Vector2(0.999828, 0.999828)
scale = Vector2(0.99983, 0.99983)
rest = Transform2D(1, 0, 0, 1, -2, 14)
editor_settings/show_bone_gizmo = false
[node name="LeftHand" type="Bone2D" parent="CanvasGroup/basic_zombie_walk/Zombie/Butt/Body/LeftUpperArm/LeftLowerArm"]
position = Vector2(-1, 13)
scale = Vector2(0.99983, 0.99983)
scale = Vector2(0.999829, 0.999829)
rest = Transform2D(1, 0, 0, 1, -1, 13)
auto_calculate_length_and_angle = false
length = 6.0
@ -1161,6 +1159,7 @@ entity = NodePath("..")
[node name="Mover" type="Node" parent="."]
script = ExtResource("4_u5syx")
_speed = SubResource("Resource_ckb7n")
_speedControlMult = 0.740519
[node name="HitPlayer" type="Node" parent="."]
script = ExtResource("12_he8da")

View file

@ -1,69 +0,0 @@
using Godot;
using System.Linq;
using System.Collections.Generic;
public partial class DebugZombieSpawner : PopupPanel
{
private List<string> variants;
[Export] private Label label;
[Export] private LineEdit line;
[Export] private SpinBox spin;
public void OnTextChanged(string text)
{
variants = GameRegistry.GetZombieNames();
variants.Sort(Comparer);
if (variants.Count > 3)
{
label.Text = $"{variants[0]}\n{variants[1]}\n{variants[2]}";
}
else
{
label.Text = "";
for (int i = 0; i < variants.Count; i++)
{
label.Text += variants[i] + "\n";
}
}
}
public void OnTextSubmitted(string text)
{
spin.GrabFocus();
}
public void OnPopupHide()
{
if (variants == null || variants.Count == 0)
{
return;
}
ZombieSequencer.Instance.DebugClearQueue();
for(int i = 0; i < spin.Value; i++)
{
ZombieSequencer.Instance.Add(variants[0]);
}
QueueFree();
}
private int Comparer(string x, string y)
{
return LevensteinDistance(x,line.Text) - LevensteinDistance(y,line.Text);
}
private static int LevensteinDistance(string a, string b)
{
if (b.Length == 0)
{
return a.Length;
}
else if (a.Length == 0)
{
return b.Length;
}
else if (a[0] == b[0])
{
return LevensteinDistance(a[1..], b[1..]);
}
List<int> x = [LevensteinDistance(a[1..], b[1..]), LevensteinDistance(a[1..], b), LevensteinDistance(a, b[1..])];
return 1 + x.Min();
}
}

View file

@ -1 +0,0 @@
uid://dac0bvlhho7u4

View file

@ -72,7 +72,7 @@ public partial class SaveSerializer : Node
foreach (var plantId in parsed.PlayerPlants)
{
playerProgress.PlayerPlants.Add(GameRegistry.GetPlantByName(plantId));
playerProgress.PlayerPlants.Add((PlantResource)GameRegistry.GetEntityByName(plantId));
}
@ -80,7 +80,7 @@ public partial class SaveSerializer : Node
}
private static void InitiateCleanSave()
{
PlayerProgress.Instance.PlayerPlants = new List<PlantResource>([GameRegistry.GetPlantByName("peashooter")]);
PlayerProgress.Instance.PlayerPlants = new List<PlantResource>([(PlantResource)GameRegistry.GetEntityByName("peashooter")]);
PlayerProgress.Instance.Money = 0;
SaveGame();

View file

@ -12,12 +12,6 @@ public partial class Cheats : Node
{
RuntimeLevelData.Instance.AddSun(50);
}
if (@event.IsActionPressed("cheat_zombie_spawn"))
{
var spawner = GD.Load<PackedScene>("res://scenes/debug_zombie_spawner.tscn").Instantiate<DebugZombieSpawner>();
GetTree().CurrentScene.AddChild(spawner);
}
if (@event.IsActionPressed("cheat_unlock_all"))
{
PlayerProgress.Instance.PlayerPlants = GameRegistry.GetPlants();

View file

@ -3,13 +3,11 @@ using Newlon.Components.GUI.Seedpackets;
public partial class AlmanachGrid : GridContainer
{
private PackedScene _plantCard;
private PackedScene _plantCard = ResourceLoader.Load<PackedScene>("res://scenes/gui/seedpacket.tscn");
[Export]
private bool _zombies;
public override void _Ready()
{
_plantCard = ResourceLoader.Load<PackedScene>("res://scenes/gui/seedpacket.tscn");
if (_zombies)
{
var list = GameRegistry.GetZombies();

View file

@ -1,4 +1,5 @@
using Godot;
using Newlon;
using Newlon.Components;
using Newlon.Components.Level;
using Newlon.Components.Plants;
@ -37,7 +38,7 @@ public partial class InitialPackedSceneSpawner : Node
{
PoolContainer.Instance.Plants.AddChild(plant);
node.GlobalPosition = position;
plant.Resource = GameRegistry.GetPlantByName(plant.internal_id);
plant.Resource = GameRegistry.GetEntityByName(plant.internal_id) as PlantResource;
PoolContainer.Instance.EntityField[plant.Resource.Layer].Add(plant.GlobalPosition, plant);
}
else

View file

@ -163,7 +163,7 @@ public partial class SurvivalZombieSpawner : Node
List<ZombieResource> list = [];
foreach (var res in pool)
{
list.Add(GameRegistry.GetZombieByName(res));
list.Add(GameRegistry.GetEntityByName(res) as ZombieResource);
}
return list;
}

View file

@ -58,7 +58,7 @@ public partial class ZombieSequencer : Node2D
private void Spawn(string id, int lane)
{
RuntimeZombieData zombie = GameRegistry.GetZombieByName(id).Scene.Instantiate<RuntimeZombieData>();
RuntimeZombieData zombie = GameRegistry.GetEntityByName(id).Scene.Instantiate<RuntimeZombieData>();
PoolContainer.Instance.Zombies.AddChild(zombie);
zombie.GlobalPosition = new Vector2(GlobalPosition.X, FieldParams.RightFieldBoundary.Y - (lane - 1) * FieldParams.TileHeight);

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)
var entities = GetEntities();
List<PlantResource> plants = [];
foreach (var entity in entities)
{
result.Add(value);
}
return result;
}
public static int GetPlantCount()
if (entity is PlantResource plant)
{
return PlantDictionary.Count;
plants.Add(plant);
}
}
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)
{
result.Add(key);
}
return result;
return plants;
}
public static List<ZombieResource> GetZombies()
{
List<ZombieResource> result = [];
foreach (var value in ZombieDictionary.Values)
var entities = GetEntities();
List<ZombieResource> zombies = [];
foreach (var entity in entities)
{
result.Add(value);
if (entity is ZombieResource zombie)
{
zombies.Add(zombie);
}
return result;
}
public static int GetZombieCount()
return zombies;
}
public static int GetEntityCount()
{
return ZombieDictionary.Count;
return EntityDictionary.Count;
}
}