Teleporter visualizer

This commit is contained in:
Marco 2025-03-31 11:59:45 +02:00
commit 1a8e88f719
6 changed files with 78 additions and 17 deletions

View file

@ -8,6 +8,7 @@ using GTweensGodot.Extensions;
namespace Cirno.Scripts.Activables;
[Tool]
public partial class Teleporter : Activable
{
[Export]
@ -41,30 +42,25 @@ public partial class Teleporter : Activable
public override void _Ready()
{
_particles = GetNode<GpuParticles2D>("./Particles");
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
_animatedSprite.Play(IsEnabled ? "Active" : "Default");
if (Engine.IsEditorHint()) return;
_particles = GetNode<GpuParticles2D>("./Particles");
IsPrimed = true;
_particles.Emitting = false;
_particleTimer = 0;
this.Visible = !Invisible;
if (IsEnabled)
{
_animatedSprite.Play("Active");
}
else
{
_animatedSprite.Play("Default");
}
_teleportStartSound = GetNodeOrNull<AudioStreamPlayer2D>("TeleportStart");
_teleportEndSound = GetNodeOrNull<AudioStreamPlayer2D>("TeleportEnd");
}
public override void _Process(double delta)
{
if (Engine.IsEditorHint()) return;
if (!_particles.Emitting) return;
_particleTimer += delta;

View file

@ -0,0 +1,41 @@
using Cirno.Scripts.Activables;
using Godot;
namespace Cirno.Scripts.Utils;
[Tool]
public partial class TeleporterLinker : Node2D
{
private Teleporter _teleporter;
[Export] public Color Color { get; set; } = Colors.Blue;
public override void _Ready()
{
_teleporter = GetParentOrNull<Teleporter>();
}
public override void _Draw()
{
if (!Engine.IsEditorHint())
return;
if (_teleporter is null) return;
if (!_teleporter.IsEnabled) return;
if (_teleporter.Target is null) return;
Vector2 start = _teleporter.GlobalPosition;
Vector2 end = _teleporter.Target.GlobalPosition;
DrawLine(ToLocal(start), ToLocal(end), Color, 2.0f);
}
public override void _Process(double delta)
{
if (Engine.IsEditorHint())
{
QueueRedraw();
}
}
}

View file

@ -0,0 +1 @@
uid://3jcfdfymcvxu