add StepPuzzle and CyclicStepPuzzle

This commit is contained in:
2022-11-21 20:38:30 +01:00
parent 4aa429d87d
commit 3fe201b852
5 changed files with 124 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4551ae21288a497dac75931c56f86409
timeCreated: 1669057382

View File

@@ -5,5 +5,10 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
public abstract class ModuleState : MonoBehaviour public abstract class ModuleState : MonoBehaviour
{ {
public abstract void SetModule(Module module); public abstract void SetModule(Module module);
public override string ToString()
{
return name;
}
} }
} }

View File

@@ -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
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5095ea3f77724269857f7275fbf7159b
timeCreated: 1669052447