From 3a5154f051226ef8d02e48dc3f580833c0d3b834 Mon Sep 17 00:00:00 2001 From: Rendo Date: Thu, 17 Jul 2025 11:19:09 +0500 Subject: [PATCH] Simplified level load and Utitility.Seedpackets --- scenes/entities/Zombies/zombie.tscn | 2 -- scenes/templates/standard_players_house.tscn | 4 +--- scripts/LevelController.cs | 11 ++++------- scripts/Utility.cs | 12 +----------- scripts/gui/ZombieLevelPreviewer.cs | 2 +- scripts/gui/seedpackets/ChoosableHandler.cs | 2 +- scripts/level/RuntimeLevelData.cs | 13 +++++++------ 7 files changed, 15 insertions(+), 31 deletions(-) diff --git a/scenes/entities/Zombies/zombie.tscn b/scenes/entities/Zombies/zombie.tscn index 1b74327..8306aea 100644 --- a/scenes/entities/Zombies/zombie.tscn +++ b/scenes/entities/Zombies/zombie.tscn @@ -995,7 +995,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) @@ -1003,7 +1002,6 @@ 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) diff --git a/scenes/templates/standard_players_house.tscn b/scenes/templates/standard_players_house.tscn index af63f87..1c015cc 100644 --- a/scenes/templates/standard_players_house.tscn +++ b/scenes/templates/standard_players_house.tscn @@ -1,7 +1,6 @@ -[gd_scene load_steps=16 format=3 uid="uid://bu0dh5ct387xu"] +[gd_scene load_steps=15 format=3 uid="uid://bu0dh5ct387xu"] [ext_resource type="PackedScene" uid="uid://dd3yegl1xo44m" path="res://scenes/templates/level_template.tscn" id="1_vdv3d"] -[ext_resource type="Resource" uid="uid://br3364jty1j0i" path="res://resources/levels/test_level_for_execution.tres" id="2_bpfdr"] [ext_resource type="Texture2D" uid="uid://b0tb2hjum40aw" path="res://assets/sprites/background_summer.png" id="3_lsqv3"] [ext_resource type="Script" uid="uid://84gvlkflxdhk" path="res://scripts/level/zombe_spawners/RowSpawner.cs" id="4_kn7hc"] [ext_resource type="Script" uid="uid://puqxp2xeg1r2" path="res://scripts/level/LevelRunner.cs" id="5_vbgdr"] @@ -270,7 +269,6 @@ libraries = { } [node name="Data" parent="." index="1" node_paths=PackedStringArray("levelRunner", "player")] -levelResource = ExtResource("2_bpfdr") levelRunner = NodePath("../LevelRunner") player = NodePath("../MainAnimationPlayer") diff --git a/scripts/LevelController.cs b/scripts/LevelController.cs index bca7ebe..8330947 100644 --- a/scripts/LevelController.cs +++ b/scripts/LevelController.cs @@ -31,12 +31,8 @@ public partial class LevelController : Node { if (_isLevelRunning) return; - - GetTree().CreateTimer(0.001).Timeout += ()=> - { - RuntimeLevelData.Instance.levelResource = levelResource; - RuntimeLevelData.Instance.StartLevel(); - }; + + RuntimeLevelData.LevelResource = levelResource; GetTree().ChangeSceneToPacked(levelTileset); @@ -48,7 +44,8 @@ public partial class LevelController : Node { if (_isLevelRunning == false) return; - + RuntimeLevelData.LevelResource = null; + _isLevelRunning = false; } } diff --git a/scripts/Utility.cs b/scripts/Utility.cs index 50a4eab..5095e05 100644 --- a/scripts/Utility.cs +++ b/scripts/Utility.cs @@ -9,16 +9,6 @@ namespace Newlon; public class Utility { - // - // Code-accessed enumenators - // - #region Enums - - public enum EffectSlots { FREEZE, STUN, POISON, GARLIC }; - - public enum DamageTypes { PHYSICAL, ICE }; - - #endregion public const int EffectSlotCount = 4; public const int LineCount = 5; @@ -32,6 +22,6 @@ public class Utility public static double SFX = 1.0f; public static double Music = 1.0f; public static bool Splash = false; - + public static int MaxSeedpackets = 9; } diff --git a/scripts/gui/ZombieLevelPreviewer.cs b/scripts/gui/ZombieLevelPreviewer.cs index 30ccc08..e999f9d 100644 --- a/scripts/gui/ZombieLevelPreviewer.cs +++ b/scripts/gui/ZombieLevelPreviewer.cs @@ -39,7 +39,7 @@ public partial class ZombieLevelPreviewer : Node2D { List zombies = new(); - foreach (var wave in RuntimeLevelData.Instance.levelResource.waves) + foreach (var wave in RuntimeLevelData.LevelResource.waves) { foreach (var spawn in wave.zombiesOrdered) { diff --git a/scripts/gui/seedpackets/ChoosableHandler.cs b/scripts/gui/seedpackets/ChoosableHandler.cs index 306309a..d766856 100644 --- a/scripts/gui/seedpackets/ChoosableHandler.cs +++ b/scripts/gui/seedpackets/ChoosableHandler.cs @@ -8,7 +8,7 @@ public class ChoosableHandler : SeedpacketHandler, ISeedpacketPress public void Pressed() { - if (LevelGUIElements.Instance.SeedpacketsHotbar.GetChildCount() > 9) return; + if (LevelGUIElements.Instance.SeedpacketsHotbar.GetChildCount() >= Utility.MaxSeedpackets) return; _owner.disablePacket = true; var hotbarSeedpacket = Seedpacket.Prefab.Instantiate(); diff --git a/scripts/level/RuntimeLevelData.cs b/scripts/level/RuntimeLevelData.cs index eed08f8..b6a023c 100644 --- a/scripts/level/RuntimeLevelData.cs +++ b/scripts/level/RuntimeLevelData.cs @@ -17,8 +17,6 @@ public partial class RuntimeLevelData : Node [Export] public float SunCount { get; private set; } = 0; [Export] - public AdventureLevelResource levelResource; - [Export] private LevelRunner levelRunner; [Export] private AnimationPlayer player; @@ -26,6 +24,7 @@ public partial class RuntimeLevelData : Node public delegate void OnLevelStateChangedEventHandler(LevelStates state); public static RuntimeLevelData Instance { get; private set; } + public static AdventureLevelResource LevelResource { get; set; } private LevelStates _currentState = LevelStates.ChooseYourSeeds; @@ -36,9 +35,6 @@ public partial class RuntimeLevelData : Node Instance = this; GetTree().Paused = true; Engine.TimeScale = 1.0; - } - public void StartLevel() - { SetLevelState(LevelStates.ChooseYourSeeds); } #region Sun @@ -76,7 +72,7 @@ public partial class RuntimeLevelData : Node break; case LevelStates.Game: GetTree().Paused = false; - levelRunner.SetLevelResource(levelResource); + levelRunner.SetLevelResource(LevelResource); break; case LevelStates.Win: break; @@ -88,6 +84,11 @@ public partial class RuntimeLevelData : Node { return _currentState; } + public override void _ExitTree() + { + LevelController.Instance.EndLevel(); + } + //private Array _selectedPlants; //private bool _selected;