get theme colours from engine instead of storing reference to theme in module
This commit is contained in:
@@ -30,7 +30,6 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||
public class PuzzleState : ModuleState
|
||||
{
|
||||
public event PuzzleEventHandler PuzzleEvent;
|
||||
public EngineTheme theme;
|
||||
|
||||
protected PuzzleModule Module { get; private set; }
|
||||
public bool Solved
|
||||
|
||||
81
Assets/Engine/Runtime/Modules/StatePuzzle.cs
Normal file
81
Assets/Engine/Runtime/Modules/StatePuzzle.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||
{
|
||||
public class StatePuzzle : PuzzleState
|
||||
{
|
||||
[BoxGroup("State Puzzle")]
|
||||
[SerializeField]
|
||||
protected List<int> states, solution;
|
||||
[BoxGroup("Step 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;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_initialStates = states;
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
PuzzleEvent += (_, type) =>
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case PuzzleEventType.Restarted:
|
||||
states = _initialStates;
|
||||
break;
|
||||
case PuzzleEventType.Solved:
|
||||
states = solution;
|
||||
break;
|
||||
case PuzzleEventType.WrongInput:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void SetState(int index, int value)
|
||||
{
|
||||
if (index >= 0 && index < stateCount)
|
||||
{
|
||||
states[index] = value;
|
||||
StatesUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void StatesUpdate()
|
||||
{
|
||||
correctStates = 0;
|
||||
for (var i = 0; i < stateCount; i++)
|
||||
{
|
||||
if (states[i] == solution[i])
|
||||
{
|
||||
correctStates++;
|
||||
}
|
||||
}
|
||||
|
||||
if (correctStates == stateCount && correctStates > 0)
|
||||
{
|
||||
Solve();
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
private bool CorrectStateCount(int count) =>
|
||||
states != null && count == states.Count &&
|
||||
solution != null && count == solution.Count;
|
||||
}
|
||||
}
|
||||
3
Assets/Engine/Runtime/Modules/StatePuzzle.cs.meta
Normal file
3
Assets/Engine/Runtime/Modules/StatePuzzle.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 713782041b1d40a28cfe199081a4a009
|
||||
timeCreated: 1669687388
|
||||
Reference in New Issue
Block a user