refactor modules

This commit is contained in:
2023-03-22 17:03:55 +01:00
parent 52cf3a7fbd
commit 128ab216d2
503 changed files with 1835 additions and 379 deletions

View File

@@ -0,0 +1,85 @@
using System;
using EscapeRoomEngine.Engine.Runtime.Modules.State;
using NaughtyAttributes;
using UnityEngine;
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
namespace Station46.Runtime
{
/// <summary>
/// The <see cref="PuzzleState"/> of a puzzle that includes a number of steps that need to be completed to solve it.
/// </summary>
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 override 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);
}
};
base.Start();
}
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
}
}