✨ Building task queue and remove duplicated construction complete sound
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using AceFieldNewHorizon.Scripts.System;
|
||||
using Godot;
|
||||
@@ -12,7 +13,7 @@ public partial class BaseTile : Node2D
|
||||
private CollisionShape2D _collisionShape;
|
||||
private Sprite2D _sprite;
|
||||
private ColorRect _progressOverlay;
|
||||
private AudioStreamPlayer _completionSound;
|
||||
private Action _onConstructionComplete;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -21,15 +22,6 @@ public partial class BaseTile : Node2D
|
||||
_progressOverlay = GetNodeOrNull<ColorRect>("ProgressOverlay");
|
||||
if (_progressOverlay != null)
|
||||
_progressOverlay.Visible = false;
|
||||
|
||||
// Setup audio player
|
||||
_completionSound = new AudioStreamPlayer();
|
||||
AddChild(_completionSound);
|
||||
var sound = GD.Load<AudioStream>("res://Sounds/Events/ConstructionComplete.wav");
|
||||
if (sound != null)
|
||||
{
|
||||
_completionSound.Stream = sound;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetGhostMode(bool canPlace)
|
||||
@@ -52,10 +44,15 @@ public partial class BaseTile : Node2D
|
||||
}
|
||||
|
||||
// Building progress visualization
|
||||
public void StartConstruction(float buildTime)
|
||||
public void StartConstruction(float buildTime, Action onComplete = null)
|
||||
{
|
||||
if (_progressOverlay == null || _sprite?.Texture == null) return;
|
||||
if (_progressOverlay == null || _sprite?.Texture == null)
|
||||
{
|
||||
onComplete?.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
_onConstructionComplete = onComplete;
|
||||
var texSize = new Vector2(GridUtils.TileSize, GridUtils.TileSize);
|
||||
|
||||
_progressOverlay.Visible = true;
|
||||
@@ -80,8 +77,11 @@ public partial class BaseTile : Node2D
|
||||
);
|
||||
}
|
||||
|
||||
// Fade out the overlay instead of making it instantly disappear
|
||||
// Fade out the overlay
|
||||
await FadeOutOverlay(0.5f);
|
||||
|
||||
// Notify completion
|
||||
_onConstructionComplete?.Invoke();
|
||||
}
|
||||
|
||||
RunProgress();
|
||||
@@ -92,12 +92,6 @@ public partial class BaseTile : Node2D
|
||||
var elapsed = 0f;
|
||||
var startAlpha = _progressOverlay.Modulate.A;
|
||||
|
||||
// Play completion sound
|
||||
if (_completionSound?.Stream != null)
|
||||
{
|
||||
_completionSound.Play();
|
||||
}
|
||||
|
||||
while (elapsed < duration)
|
||||
{
|
||||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||||
|
Reference in New Issue
Block a user