From 6b3f6b5bfb1a465dda245fbd50bd85deba65434a Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 3 Jun 2025 11:32:26 +0200 Subject: [PATCH] Autospawner trigger --- Scripts/Actors/RogueliteEnemySpawner.cs | 52 +++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/Scripts/Actors/RogueliteEnemySpawner.cs b/Scripts/Actors/RogueliteEnemySpawner.cs index 8cd94ef3..74e6b905 100644 --- a/Scripts/Actors/RogueliteEnemySpawner.cs +++ b/Scripts/Actors/RogueliteEnemySpawner.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using Cirno.Scripts.Components.FSM.Enemy; using Cirno.Scripts.Resources; using Cirno.Scripts.Resources.Loot; @@ -8,7 +9,7 @@ using Godot; namespace Cirno.Scripts.Actors; [Tool] -public partial class RogueliteEnemySpawner : Marker2D +public partial class RogueliteEnemySpawner : Marker2D, IActivable { private EnemyResource _enemy; @@ -26,7 +27,21 @@ public partial class RogueliteEnemySpawner : Marker2D } } - [Export] public bool AutoSpawn { get; set; } = false; + private bool _autoSpawn = false; + + [Export] + public bool AutoSpawn + { + get => _autoSpawn; + set + { + _autoSpawn = value; + if (Engine.IsEditorHint()) + { + QueueRedraw(); + } + } + } [Export] public int Wave { get; private set; } = 0; @@ -41,8 +56,11 @@ public partial class RogueliteEnemySpawner : Marker2D if (!Engine.IsEditorHint()) return; if (Enemy is null) return; if (Enemy.IconSprite is null) return; + + var modulate = AutoSpawn ? new Color(1.0f, 1.0f, 1.0f, 1.0f) : new Color(1.0f, 1.0f, 1.0f, 0.5f); + + DrawTexture(Enemy.IconSprite, - new Vector2(_enemy.IconSprite.GetWidth() / 2f, _enemy.IconSprite.GetHeight() / 2f), modulate); - DrawTexture(Enemy.IconSprite, - new Vector2(_enemy.IconSprite.GetWidth() / 2f, _enemy.IconSprite.GetHeight() / 2f)); } private void Redraw() @@ -103,4 +121,30 @@ public partial class RogueliteEnemySpawner : Marker2D _spawnedEnemy = null; Spawned = false; } + + public bool Activate(ActivationType activationType = ActivationType.Toggle) + { + switch (activationType) + { + case ActivationType.Toggle: + Spawn(); + break; + case ActivationType.Enable: + break; + case ActivationType.Disable: + break; + case ActivationType.Use: + break; + case ActivationType.Destroy: + break; + case ActivationType.Open: + break; + case ActivationType.Close: + break; + default: + throw new ArgumentOutOfRangeException(nameof(activationType), activationType, null); + } + + return true; + } } \ No newline at end of file