move puzzle implementations out of engine
This commit is contained in:
@@ -12,8 +12,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 28d04249c1c4438da94b524e7d4afff2, type: 3}
|
||||
m_Name: Station 46
|
||||
m_EditorClassIdentifier:
|
||||
minRoomSize: {x: 3, y: 3}
|
||||
playSpace: {x: 4, y: 3}
|
||||
minRoomSize: {x: 4, y: 2}
|
||||
playSpace: {x: 4, y: 2}
|
||||
spaceTile: {fileID: 3229991053255736984, guid: b8f192f7cebe686468af6b1a71c4605b,
|
||||
type: 3}
|
||||
environment: {fileID: 5743657079028767629, guid: 17ecdbaca50efaa4ab503614dfec54a8,
|
||||
|
||||
40
Assets/Station46/Runtime/CyclicStepPuzzle.cs
Normal file
40
Assets/Station46/Runtime/CyclicStepPuzzle.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Station46.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="StepPuzzle"/> whose steps are considered a cycle that can be started anywhere and must be stepped through once.
|
||||
/// </summary>
|
||||
public class CyclicStepPuzzle : StepPuzzle
|
||||
{
|
||||
[Tooltip("The current step in the cycle.")]
|
||||
[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;
|
||||
}
|
||||
}
|
||||
3
Assets/Station46/Runtime/CyclicStepPuzzle.cs.meta
Normal file
3
Assets/Station46/Runtime/CyclicStepPuzzle.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4551ae21288a497dac75931c56f86409
|
||||
timeCreated: 1669057382
|
||||
@@ -1,4 +1,5 @@
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules.State;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules.State;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using EscapeRoomEngine.Station46.Runtime.Dispenser;
|
||||
using NaughtyAttributes;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules.State;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Station46.Runtime.Portal
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules.State;
|
||||
using NaughtyAttributes;
|
||||
|
||||
namespace EscapeRoomEngine.Station46.Runtime.Puzzle_A
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules.State;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using JetBrains.Annotations;
|
||||
using NaughtyAttributes;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules.State;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using EscapeRoomEngine.Station46.Runtime.Puzzle_A;
|
||||
using JetBrains.Annotations;
|
||||
using NaughtyAttributes;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules.State;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
94
Assets/Station46/Runtime/StatePuzzle.cs
Normal file
94
Assets/Station46/Runtime/StatePuzzle.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules.State;
|
||||
using JetBrains.Annotations;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Station46.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="PuzzleState"/> of a puzzle that requires a specific state to be solved.
|
||||
/// </summary>
|
||||
public class StatePuzzle : PuzzleState
|
||||
{
|
||||
[Tooltip("The state this puzzle starts at.")]
|
||||
[BoxGroup("State Puzzle")]
|
||||
[SerializeField]
|
||||
protected List<int> states;
|
||||
[Tooltip("The state that needs to be reached for this puzzle to be solved.")]
|
||||
[BoxGroup("State Puzzle")]
|
||||
[SerializeField]
|
||||
protected List<int> solution;
|
||||
[Tooltip("Set this to the total number of states this puzzle has.")]
|
||||
[BoxGroup("State Puzzle")]
|
||||
[SerializeField]
|
||||
[ValidateInput("CorrectStateCount", "States count must be equal to the number of states and the length of the solution.")]
|
||||
[Min(0)]
|
||||
protected int stateCount;
|
||||
[BoxGroup("State Puzzle")]
|
||||
[ProgressBar("Correct States", "stateCount", EColor.Orange)]
|
||||
public int correctStates;
|
||||
|
||||
private List<int> _initialStates;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
_initialStates = new List<int>(states);
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
PuzzleEvent += (_, type) =>
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case PuzzleEventType.Restarted:
|
||||
for (var i = 0; i < stateCount; i++)
|
||||
{
|
||||
SetState(i, _initialStates[i], false);
|
||||
}
|
||||
break;
|
||||
case PuzzleEventType.Solved:
|
||||
for (var i = 0; i < stateCount; i++)
|
||||
{
|
||||
SetState(i, solution[i], false);
|
||||
}
|
||||
break;
|
||||
case PuzzleEventType.WrongInput:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
};
|
||||
|
||||
base.Start();
|
||||
}
|
||||
|
||||
protected virtual void SetState(int index, int value, bool checkSolution)
|
||||
{
|
||||
if (index >= 0 && index < stateCount)
|
||||
{
|
||||
states[index] = value;
|
||||
correctStates = 0;
|
||||
for (var i = 0; i < stateCount; i++)
|
||||
{
|
||||
if (states[i] == solution[i])
|
||||
{
|
||||
correctStates++;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkSolution && correctStates == stateCount && correctStates > 0)
|
||||
{
|
||||
Solve();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly] // used for field validation
|
||||
private bool CorrectStateCount(int count) =>
|
||||
states != null && count == states.Count &&
|
||||
solution != null && count == solution.Count;
|
||||
}
|
||||
}
|
||||
3
Assets/Station46/Runtime/StatePuzzle.cs.meta
Normal file
3
Assets/Station46/Runtime/StatePuzzle.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 713782041b1d40a28cfe199081a4a009
|
||||
timeCreated: 1669687388
|
||||
85
Assets/Station46/Runtime/StepPuzzle.cs
Normal file
85
Assets/Station46/Runtime/StepPuzzle.cs
Normal 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 EscapeRoomEngine.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
|
||||
}
|
||||
}
|
||||
3
Assets/Station46/Runtime/StepPuzzle.cs.meta
Normal file
3
Assets/Station46/Runtime/StepPuzzle.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5095ea3f77724269857f7275fbf7159b
|
||||
timeCreated: 1669052447
|
||||
Reference in New Issue
Block a user