using System; using System.Collections.Generic; using EscapeRoomEngine.Engine.Runtime.Modules; using EscapeRoomEngine.Engine.Runtime.Utilities; using NaughtyAttributes; using UnityEngine; namespace EscapeRoomEngine.Desert.Runtime.Puzzle_A { [RequireComponent(typeof(Animator))] public class Terminal : PuzzleState { private static readonly int LightFlash = Animator.StringToHash("Light Flash"); [BoxGroup("Internal")] [Required] public Emission terminalLight; [BoxGroup("Internal")] public List symbols; private Animator _animator; private Ball _ball; private void Awake() { _animator = GetComponent(); } private void Start() { PuzzleEvent += (_, type) => { switch (type) { case PuzzleEventType.Restarted: _ball.ringLight.color = theme.puzzleColor; terminalLight.color = theme.puzzleColor; symbols.ForEach(symbol => symbol.Enable()); _ball.ring.Solved = false; break; case PuzzleEventType.Solved: _ball.ringLight.color = theme.solvedColor; terminalLight.color = theme.solvedColor; symbols.ForEach(symbol => symbol.Disable()); _ball.ring.Solved = true; break; case PuzzleEventType.WrongInput: _animator.SetTrigger(LightFlash); break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }; } public override void SetModule(Module module) { base.SetModule(module); var firstRelatedModule = Module.relatedModules[0]; if (firstRelatedModule.State is Ball ball) { _ball = ball; } else { throw new EngineException("Terminal was not assigned a related Ball."); } TurnOnLights(); } // required in animation internal void TurnOnLights() { terminalLight.active = true; _ball.ringLight.active = true; } // required in animation internal void TurnOffLights() { terminalLight.active = false; _ball.ringLight.active = false; } } }