SupaLidlGame/State/Global/MapState.cs

58 lines
1.3 KiB
C#
Raw Normal View History

2023-08-05 23:50:08 -07:00
using Godot;
using Godot.Collections;
2023-08-12 15:01:22 -07:00
namespace SupaLidlGame.State.Global;
2023-12-13 18:25:32 -08:00
[GlobalClass]
2023-08-05 23:50:08 -07:00
public partial class MapState : Resource
{
[Export]
2023-12-13 18:25:32 -08:00
private Dictionary<string, Variant> _state;
2023-08-05 23:50:08 -07:00
[Signal]
public delegate void MapStateChangedEventHandler(string key, Variant value);
[Signal]
public delegate void MapStateBoolChangedEventHandler(string key, bool value);
public Variant this[string key]
{
get
{
if (_state.ContainsKey(key))
{
return _state[key];
}
return default;
}
set
{
if (_state.ContainsKey(key))
{
_state[key] = value;
}
else
{
_state.Add(key, value);
}
EmitSignal(SignalName.MapStateChanged, key, value);
switch (value.VariantType)
{
case Variant.Type.Bool:
EmitSignal(SignalName.MapStateBoolChanged, key, (bool)value);
break;
}
}
}
2024-05-30 22:07:37 -07:00
public bool? GetBoolean(string key)
{
if (_state[key].VariantType == Variant.Type.Bool)
{
return (bool)_state[key];
}
return null;
}
2023-08-05 23:50:08 -07:00
}