mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Modularized doors and lightbridges
This commit is contained in:
parent
1a24711984
commit
1a5bd1b6d8
27 changed files with 513 additions and 346 deletions
57
Scripts/Components/Actors/LightBridgeSpriteComponent.cs
Normal file
57
Scripts/Components/Actors/LightBridgeSpriteComponent.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
using System.Threading.Tasks;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Components.Actors;
|
||||
|
||||
public partial class LightBridgeSpriteComponent : Sprite2D
|
||||
{
|
||||
[Export]
|
||||
public Material TurnOffMaterial { get; private set; }
|
||||
|
||||
[Export]
|
||||
public Material ActiveMaterial { get; private set; }
|
||||
|
||||
protected Door _door;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
_door = GetParent<Door>();
|
||||
|
||||
_door.DoorOpened += DoorOpened;
|
||||
_door.DoorClosed += DoorClosed;
|
||||
}
|
||||
|
||||
protected virtual void DoorOpened()
|
||||
{
|
||||
if (TurnOffMaterial is null) return;
|
||||
|
||||
this.Material = TurnOffMaterial;
|
||||
_ = AnimateShutdownAsync();
|
||||
}
|
||||
|
||||
protected virtual void DoorClosed()
|
||||
{
|
||||
if (ActiveMaterial is null) return;
|
||||
this.Material = ActiveMaterial;
|
||||
}
|
||||
|
||||
protected async Task AnimateShutdownAsync()
|
||||
{
|
||||
Tween tween = GetTree().CreateTween();
|
||||
tween.TweenMethod(Callable.From((float value) => SetShaderScanlineDensity(value)), 0f, 50f, 0.5);
|
||||
tween.Parallel().TweenMethod(Callable.From((float value) => SetShaderTeleportProgress(value)), 0f, 1f, 0.5);
|
||||
|
||||
await ToSignal(tween, "finished");
|
||||
}
|
||||
|
||||
private void SetShaderTeleportProgress(float value)
|
||||
{
|
||||
((ShaderMaterial)this.Material).SetShaderParameter("teleport_progress", value);
|
||||
}
|
||||
|
||||
private void SetShaderScanlineDensity(float value)
|
||||
{
|
||||
((ShaderMaterial)this.Material).SetShaderParameter("scanline_density", value);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue