66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
using System;
|
|
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
|
using NaughtyAttributes;
|
|
|
|
namespace Escape_Room_Engine.Engine.Scripts.Modules
|
|
{
|
|
public enum DoorEventType
|
|
{
|
|
Locked, Unlocked
|
|
}
|
|
|
|
public delegate void DoorEventHandler(DoorModule source, DoorEventType e);
|
|
|
|
public class DoorState : ModuleState
|
|
{
|
|
public event DoorEventHandler DoorEvent;
|
|
|
|
private new DoorModule Module { get; set; }
|
|
public bool Unlocked
|
|
{
|
|
get => _unlocked;
|
|
private set
|
|
{
|
|
var type =
|
|
!_unlocked && value ? Some<DoorEventType>.Of(DoorEventType.Unlocked)
|
|
: _unlocked && !value ? Some<DoorEventType>.Of(DoorEventType.Locked)
|
|
: None<DoorEventType>.New();
|
|
_unlocked = value;
|
|
type.Match(some: OnDoorEvent);
|
|
}
|
|
}
|
|
|
|
private bool _unlocked;
|
|
|
|
private void OnDoorEvent(DoorEventType type)
|
|
{
|
|
Logger.Log($"{Module} has been {type}", LogType.PuzzleFlow);
|
|
|
|
DoorEvent?.Invoke(Module, type);
|
|
}
|
|
|
|
public override void SetModule(Module module)
|
|
{
|
|
if (module is DoorModule doorModule)
|
|
{
|
|
Module = doorModule;
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("Tried to set wrong type of module.");
|
|
}
|
|
}
|
|
|
|
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
|
internal void Unlock()
|
|
{
|
|
Unlocked = true;
|
|
}
|
|
|
|
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
|
internal void Lock()
|
|
{
|
|
Unlocked = false;
|
|
}
|
|
}
|
|
} |