finish puzzle a logic
This commit is contained in:
@@ -4,17 +4,20 @@ using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
||||
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
|
||||
|
||||
namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
{
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class Terminal : PuzzleState
|
||||
public class Terminal : CyclicStepPuzzle
|
||||
{
|
||||
private static readonly int LightFlash = Animator.StringToHash("Light Flash");
|
||||
|
||||
[BoxGroup("Internal")] [Required] public Emission terminalLight;
|
||||
[BoxGroup("Internal")] public List<SymbolButton> symbols;
|
||||
|
||||
|
||||
private int _activeSymbol, _lastPressedSymbol;
|
||||
private Animator _animator;
|
||||
private Ball _ball;
|
||||
|
||||
@@ -23,23 +26,23 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
_animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
PuzzleEvent += (_, type) =>
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case PuzzleEventType.Restarted:
|
||||
_ball.ringLight.color = theme.puzzleColor;
|
||||
_ball.Active = true;
|
||||
terminalLight.color = theme.puzzleColor;
|
||||
symbols.ForEach(symbol => symbol.Enable());
|
||||
_ball.ring.Solved = false;
|
||||
break;
|
||||
case PuzzleEventType.Solved:
|
||||
_ball.ringLight.color = theme.solvedColor;
|
||||
_ball.Active = false;
|
||||
terminalLight.color = theme.solvedColor;
|
||||
symbols.ForEach(symbol => symbol.Disable());
|
||||
_ball.ring.Solved = true;
|
||||
break;
|
||||
case PuzzleEventType.WrongInput:
|
||||
_animator.SetTrigger(LightFlash);
|
||||
@@ -48,6 +51,23 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
};
|
||||
|
||||
symbols.ForEach(symbol =>
|
||||
{
|
||||
symbol.ButtonEvent += (_, type) =>
|
||||
{
|
||||
if (type == ButtonEventType.Pressed)
|
||||
{
|
||||
PressedSymbol(symbol.symbolNumber);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
_ball.ring.symbols.ForEach(symbol =>
|
||||
{
|
||||
symbol.SymbolEvent += type =>
|
||||
_activeSymbol = type == SymbolEventType.Activated ? symbol.symbolNumber : -1;
|
||||
});
|
||||
}
|
||||
|
||||
public override void SetModule(Module module)
|
||||
@@ -71,14 +91,39 @@ namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A
|
||||
internal void TurnOnLights()
|
||||
{
|
||||
terminalLight.active = true;
|
||||
_ball.ringLight.active = true;
|
||||
_ball.StatusLight = true;
|
||||
}
|
||||
|
||||
// required in animation
|
||||
internal void TurnOffLights()
|
||||
{
|
||||
terminalLight.active = false;
|
||||
_ball.ringLight.active = false;
|
||||
_ball.StatusLight = false;
|
||||
}
|
||||
|
||||
internal void PressedSymbol(int number)
|
||||
{
|
||||
if (!Solved)
|
||||
{
|
||||
Logger.Log($"Pressed symbol {number} on {this}", LogType.PuzzleDetail);
|
||||
|
||||
if (number == _activeSymbol)
|
||||
{
|
||||
CheckStep(number);
|
||||
}
|
||||
else
|
||||
{
|
||||
WrongInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Debug Buttons
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)] public void PressSymbol0() => PressedSymbol(0);
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)] public void PressSymbol1() => PressedSymbol(1);
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)] public void PressSymbol2() => PressedSymbol(2);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user