mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-05 11:35:55 +00:00
Boxswitch with state
This commit is contained in:
parent
036a36a80f
commit
87645f2617
14 changed files with 278 additions and 37 deletions
46
Scripts/Interactables/Modules/SwitchSpriteChanger.cs
Normal file
46
Scripts/Interactables/Modules/SwitchSpriteChanger.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using Cirno.Scripts.Enums;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Interactables.Modules;
|
||||
|
||||
public partial class SwitchSpriteChanger : AnimatedSprite2D
|
||||
{
|
||||
[Export]
|
||||
public StateSwitch Switch { get; private set; }
|
||||
|
||||
[Export] public StringName OnAnimationName { get; private set; } = "On";
|
||||
[Export] public StringName OffAnimationName { get; private set; } = "Off";
|
||||
[Export] public StringName DestroyedAnimationName { get; private set; } = "Destroyed";
|
||||
[Export] public StringName DisabledAnimationName { get; private set; } = "Disabled";
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Switch.OnActivated += SwitchOnActivated;
|
||||
UpdateSprite();
|
||||
}
|
||||
|
||||
private void SwitchOnActivated(ActivationType activationType)
|
||||
{
|
||||
UpdateSprite();
|
||||
}
|
||||
|
||||
private void UpdateSprite()
|
||||
{
|
||||
switch (Switch.CurrentState)
|
||||
{
|
||||
case SwitchState.On:
|
||||
this.Play(OnAnimationName);
|
||||
break;
|
||||
case SwitchState.Off:
|
||||
this.Play(OffAnimationName);
|
||||
break;
|
||||
case SwitchState.Destroyed:
|
||||
this.Play(DestroyedAnimationName);
|
||||
break;
|
||||
case SwitchState.Disabled:
|
||||
this.Play(DisabledAnimationName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Scripts/Interactables/Modules/SwitchSpriteChanger.cs.uid
Normal file
1
Scripts/Interactables/Modules/SwitchSpriteChanger.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b5sanpv5j7wyd
|
||||
Loading…
Add table
Add a link
Reference in a new issue