diff --git a/Assets/Engine/Runtime/Modules/CyclicStepPuzzle.cs b/Assets/Engine/Runtime/Modules/CyclicStepPuzzle.cs new file mode 100644 index 0000000..4497158 --- /dev/null +++ b/Assets/Engine/Runtime/Modules/CyclicStepPuzzle.cs @@ -0,0 +1,35 @@ +using NaughtyAttributes; +using UnityEngine; + +namespace EscapeRoomEngine.Engine.Runtime.Modules +{ + public class CyclicStepPuzzle : StepPuzzle + { + [BoxGroup("Step Puzzle")] [Min(0)] public int cycleStep; + + protected override void CheckStep(int step) + { + if (!Solved) + { + if (currentStep == 0) + { + // begin at any step + cycleStep = NextInCycle(step); + Step(); + } + else if (step == cycleStep) + { + // next step in cycle + cycleStep = NextInCycle(cycleStep); + Step(); + } + else + { + WrongInput(); + } + } + } + + private int NextInCycle(int step) => (step + 1) % totalSteps; + } +} \ No newline at end of file diff --git a/Assets/Engine/Runtime/Modules/CyclicStepPuzzle.cs.meta b/Assets/Engine/Runtime/Modules/CyclicStepPuzzle.cs.meta new file mode 100644 index 0000000..01a63f4 --- /dev/null +++ b/Assets/Engine/Runtime/Modules/CyclicStepPuzzle.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4551ae21288a497dac75931c56f86409 +timeCreated: 1669057382 \ No newline at end of file diff --git a/Assets/Engine/Runtime/Modules/ModuleState.cs b/Assets/Engine/Runtime/Modules/ModuleState.cs index 5d97b65..cd4ab7e 100644 --- a/Assets/Engine/Runtime/Modules/ModuleState.cs +++ b/Assets/Engine/Runtime/Modules/ModuleState.cs @@ -5,5 +5,10 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules public abstract class ModuleState : MonoBehaviour { public abstract void SetModule(Module module); + + public override string ToString() + { + return name; + } } } \ No newline at end of file diff --git a/Assets/Engine/Runtime/Modules/StepPuzzle.cs b/Assets/Engine/Runtime/Modules/StepPuzzle.cs new file mode 100644 index 0000000..da8eab7 --- /dev/null +++ b/Assets/Engine/Runtime/Modules/StepPuzzle.cs @@ -0,0 +1,78 @@ +using System; +using NaughtyAttributes; +using UnityEngine; +using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger; +using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType; + +namespace EscapeRoomEngine.Engine.Runtime.Modules +{ + public abstract class StepPuzzle : PuzzleState + { + [BoxGroup("Step Puzzle")] + [InfoBox("In easy mode, the step puzzle will not reset if a wrong input is made.")] + public bool easyMode; + [BoxGroup("Step Puzzle")] [Min(0)] public int totalSteps; + [BoxGroup("Step Puzzle")] [ProgressBar("Step", "totalSteps", EColor.Orange)] + public int currentStep; + + protected virtual void Start() + { + PuzzleEvent += (_, type) => + { + switch (type) + { + case PuzzleEventType.Restarted: + currentStep = 0; + break; + case PuzzleEventType.Solved: + currentStep = totalSteps; + break; + case PuzzleEventType.WrongInput: + if (!easyMode) + { + currentStep = 0; + } + break; + default: + throw new ArgumentOutOfRangeException(nameof(type), type, null); + } + }; + } + + protected virtual void CheckStep(int step) + { + if (!Solved) + { + if (step == currentStep) + { + Step(); + } + else + { + WrongInput(); + } + } + } + + #region Debug Buttons + + [Button(enabledMode: EButtonEnableMode.Playmode)] + protected void Step() + { + if (!Solved) + { + currentStep++; + if (currentStep >= totalSteps) + { + Solve(); + } + else + { + Logger.Log($"{this} step {currentStep}/{totalSteps}", LogType.PuzzleDetail); + } + } + } + + #endregion + } +} \ No newline at end of file diff --git a/Assets/Engine/Runtime/Modules/StepPuzzle.cs.meta b/Assets/Engine/Runtime/Modules/StepPuzzle.cs.meta new file mode 100644 index 0000000..81965d0 --- /dev/null +++ b/Assets/Engine/Runtime/Modules/StepPuzzle.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5095ea3f77724269857f7275fbf7159b +timeCreated: 1669052447 \ No newline at end of file