From d5573db251995915408de46f4964aad5f3ffea4e Mon Sep 17 00:00:00 2001 From: Rendo Date: Fri, 25 Jul 2025 18:02:47 +0500 Subject: [PATCH] game registry internal refactor --- scenes/debug_zombie_spawner.tscn | 41 ---------- scenes/entities/Zombies/zombie.tscn | 43 +++++----- scripts/DebugZombieSpawner.cs | 69 ---------------- scripts/DebugZombieSpawner.cs.uid | 1 - scripts/SaveSerializer.cs | 4 +- scripts/debug/Cheats.cs | 6 -- scripts/gui/almanach/AlmanachGrid.cs | 4 +- scripts/level/InitialPackedSceneSpawner.cs | 3 +- .../zombe_spawners/SurvivalZombieSpawner.cs | 2 +- .../level/zombe_spawners/ZombieSequencer.cs | 2 +- scripts/systems/GameRegistry.cs | 81 +++++++++---------- 11 files changed, 68 insertions(+), 188 deletions(-) delete mode 100644 scenes/debug_zombie_spawner.tscn delete mode 100644 scripts/DebugZombieSpawner.cs delete mode 100644 scripts/DebugZombieSpawner.cs.uid diff --git a/scenes/debug_zombie_spawner.tscn b/scenes/debug_zombie_spawner.tscn deleted file mode 100644 index 5026776..0000000 --- a/scenes/debug_zombie_spawner.tscn +++ /dev/null @@ -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"] diff --git a/scenes/entities/Zombies/zombie.tscn b/scenes/entities/Zombies/zombie.tscn index fe89651..3956a16 100644 --- a/scenes/entities/Zombies/zombie.tscn +++ b/scenes/entities/Zombies/zombie.tscn @@ -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") diff --git a/scripts/DebugZombieSpawner.cs b/scripts/DebugZombieSpawner.cs deleted file mode 100644 index 0ee0f30..0000000 --- a/scripts/DebugZombieSpawner.cs +++ /dev/null @@ -1,69 +0,0 @@ -using Godot; -using System.Linq; -using System.Collections.Generic; - -public partial class DebugZombieSpawner : PopupPanel -{ - private List 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 x = [LevensteinDistance(a[1..], b[1..]), LevensteinDistance(a[1..], b), LevensteinDistance(a, b[1..])]; - return 1 + x.Min(); - } -} diff --git a/scripts/DebugZombieSpawner.cs.uid b/scripts/DebugZombieSpawner.cs.uid deleted file mode 100644 index 3f2c794..0000000 --- a/scripts/DebugZombieSpawner.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://dac0bvlhho7u4 diff --git a/scripts/SaveSerializer.cs b/scripts/SaveSerializer.cs index e097058..584b3bd 100644 --- a/scripts/SaveSerializer.cs +++ b/scripts/SaveSerializer.cs @@ -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([GameRegistry.GetPlantByName("peashooter")]); + PlayerProgress.Instance.PlayerPlants = new List([(PlantResource)GameRegistry.GetEntityByName("peashooter")]); PlayerProgress.Instance.Money = 0; SaveGame(); diff --git a/scripts/debug/Cheats.cs b/scripts/debug/Cheats.cs index e9fa2dd..46c9654 100644 --- a/scripts/debug/Cheats.cs +++ b/scripts/debug/Cheats.cs @@ -12,12 +12,6 @@ public partial class Cheats : Node { RuntimeLevelData.Instance.AddSun(50); } - if (@event.IsActionPressed("cheat_zombie_spawn")) - { - var spawner = GD.Load("res://scenes/debug_zombie_spawner.tscn").Instantiate(); - - GetTree().CurrentScene.AddChild(spawner); - } if (@event.IsActionPressed("cheat_unlock_all")) { PlayerProgress.Instance.PlayerPlants = GameRegistry.GetPlants(); diff --git a/scripts/gui/almanach/AlmanachGrid.cs b/scripts/gui/almanach/AlmanachGrid.cs index ff1a23c..4173054 100644 --- a/scripts/gui/almanach/AlmanachGrid.cs +++ b/scripts/gui/almanach/AlmanachGrid.cs @@ -3,13 +3,11 @@ using Newlon.Components.GUI.Seedpackets; public partial class AlmanachGrid : GridContainer { - private PackedScene _plantCard; + private PackedScene _plantCard = ResourceLoader.Load("res://scenes/gui/seedpacket.tscn"); [Export] private bool _zombies; public override void _Ready() { - _plantCard = ResourceLoader.Load("res://scenes/gui/seedpacket.tscn"); - if (_zombies) { var list = GameRegistry.GetZombies(); diff --git a/scripts/level/InitialPackedSceneSpawner.cs b/scripts/level/InitialPackedSceneSpawner.cs index e1cf30f..85480ac 100644 --- a/scripts/level/InitialPackedSceneSpawner.cs +++ b/scripts/level/InitialPackedSceneSpawner.cs @@ -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 diff --git a/scripts/level/zombe_spawners/SurvivalZombieSpawner.cs b/scripts/level/zombe_spawners/SurvivalZombieSpawner.cs index 1927cbe..f87cf55 100644 --- a/scripts/level/zombe_spawners/SurvivalZombieSpawner.cs +++ b/scripts/level/zombe_spawners/SurvivalZombieSpawner.cs @@ -163,7 +163,7 @@ public partial class SurvivalZombieSpawner : Node List list = []; foreach (var res in pool) { - list.Add(GameRegistry.GetZombieByName(res)); + list.Add(GameRegistry.GetEntityByName(res) as ZombieResource); } return list; } diff --git a/scripts/level/zombe_spawners/ZombieSequencer.cs b/scripts/level/zombe_spawners/ZombieSequencer.cs index e9fe451..fedb093 100644 --- a/scripts/level/zombe_spawners/ZombieSequencer.cs +++ b/scripts/level/zombe_spawners/ZombieSequencer.cs @@ -58,7 +58,7 @@ public partial class ZombieSequencer : Node2D private void Spawn(string id, int lane) { - RuntimeZombieData zombie = GameRegistry.GetZombieByName(id).Scene.Instantiate(); + RuntimeZombieData zombie = GameRegistry.GetEntityByName(id).Scene.Instantiate(); PoolContainer.Instance.Zombies.AddChild(zombie); zombie.GlobalPosition = new Vector2(GlobalPosition.X, FieldParams.RightFieldBoundary.Y - (lane - 1) * FieldParams.TileHeight); diff --git a/scripts/systems/GameRegistry.cs b/scripts/systems/GameRegistry.cs index dae99e2..d7b46fb 100644 --- a/scripts/systems/GameRegistry.cs +++ b/scripts/systems/GameRegistry.cs @@ -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 PlantDictionary = []; - public static readonly Dictionary ZombieDictionary = []; + public static readonly Dictionary EntityDictionary = []; public override void _EnterTree() { @@ -21,10 +20,9 @@ public partial class GameRegistry : Node { var plant = ResourceLoader.Load(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(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 GetPlantNames() + public static List GetEntityNames() { List result = []; - foreach (var key in PlantDictionary.Keys) + foreach (var key in EntityDictionary.Keys) { result.Add(key); } return result; } + public static List GetEntities() + { + List result = []; + foreach (var value in EntityDictionary.Values) + { + result.Add(value); + } + return result; + } public static List GetPlants() { - List result = []; - foreach (var value in PlantDictionary.Values) - { - result.Add(value); - } - return result; - } - public static int GetPlantCount() - { - return PlantDictionary.Count; - } + var entities = GetEntities(); + List plants = []; - public static ZombieResource GetZombieByName(string name) - { - if (ZombieDictionary.ContainsKey(name) == false) return null; - return ZombieDictionary[name]; - } - public static List GetZombieNames() - { - List 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 GetZombies() { - List result = []; - foreach (var value in ZombieDictionary.Values) - { - result.Add(value); - } - return result; - } + var entities = GetEntities(); + List 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; } }