2023-08-05 23:50:08 -07:00
|
|
|
using Godot;
|
|
|
|
using SupaLidlGame.Extensions;
|
|
|
|
|
|
|
|
namespace SupaLidlGame.Entities;
|
|
|
|
|
|
|
|
public partial class DynamicDoor : StaticBody2D
|
|
|
|
{
|
|
|
|
[Export]
|
|
|
|
public string MapStateKey { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
2023-08-07 02:38:51 -07:00
|
|
|
public Godot.Collections.Array<NodePath> VisibleOnToggle { get; set; } = new();
|
2023-08-05 23:50:08 -07:00
|
|
|
|
|
|
|
[Export]
|
|
|
|
public bool DefaultState { get; set; }
|
|
|
|
|
|
|
|
private AnimationPlayer _animPlayer;
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
_animPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
|
|
|
|
|
|
|
|
var globalState = this.GetGlobalState();
|
|
|
|
globalState.MapState.MapStateBoolChanged += OnMapStateChanged;
|
2023-08-07 02:38:51 -07:00
|
|
|
SetAnimations(false);
|
2023-08-05 23:50:08 -07:00
|
|
|
RefreshMapState((bool)globalState.MapState[MapStateKey]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void OnMapStateChanged(string key, bool value)
|
|
|
|
{
|
|
|
|
GD.Print("Map state changed");
|
|
|
|
if (key == MapStateKey)
|
|
|
|
{
|
2023-08-07 02:38:51 -07:00
|
|
|
SetAnimations(true);
|
2023-08-05 23:50:08 -07:00
|
|
|
RefreshMapState(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RefreshMapState(bool value)
|
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
{
|
|
|
|
Open();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void Open()
|
|
|
|
{
|
|
|
|
_animPlayer?.TryPlay("open");
|
2023-08-07 02:38:51 -07:00
|
|
|
//this.GetWorld().CurrentPlayer.Camera.Shake(1, 0.5f);
|
2023-08-05 23:50:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void Close()
|
|
|
|
{
|
2023-08-07 02:38:51 -07:00
|
|
|
_animPlayer?.TryPlay("close");
|
|
|
|
//this.GetWorld().CurrentPlayer.Camera.Shake(2, 0.25f);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetAnimations(bool isEnabled)
|
|
|
|
{
|
|
|
|
foreach (var animKey in _animPlayer.GetAnimationList())
|
|
|
|
{
|
|
|
|
var anim = _animPlayer.GetAnimation(animKey);
|
|
|
|
for (int i = 0; i < anim.GetTrackCount(); i++)
|
|
|
|
{
|
|
|
|
foreach (var nodePath in VisibleOnToggle)
|
|
|
|
{
|
|
|
|
if (anim.TrackGetPath(i) == nodePath)
|
|
|
|
{
|
|
|
|
GD.Print($"Disabled anim for {nodePath}");
|
|
|
|
anim.TrackSetEnabled(i, isEnabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-05 23:50:08 -07:00
|
|
|
}
|
|
|
|
}
|