puzzle flow

This commit is contained in:
2022-11-11 16:25:25 +01:00
parent c4f63ce3be
commit 990c7205ba
8 changed files with 128 additions and 23 deletions

View File

@@ -1,5 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using Escape_Room_Engine.Engine.Scripts.Modules;
using UnityEngine;
using Logger = Escape_Room_Engine.Engine.Scripts.Utilities.Logger;
using LogType = Escape_Room_Engine.Engine.Scripts.Utilities.LogType;
namespace Escape_Room_Engine.Engine.Scripts
{
@@ -8,7 +12,8 @@ namespace Escape_Room_Engine.Engine.Scripts
internal Passage entrance, exit;
internal GameObject roomObject;
private List<Space> _spaces = new();
private readonly List<Space> _spaces = new();
private readonly List<PuzzleModule> _puzzles = new();
internal Room(Passage entrance)
{
@@ -21,6 +26,33 @@ namespace Escape_Room_Engine.Engine.Scripts
exit = spaceExit;
}
internal void AddPuzzle(PuzzleModule puzzle)
{
_puzzles.Add(puzzle);
puzzle.PuzzleEvent += OnPuzzleEvent;
}
/// <summary>
/// Solves all puzzles in this room.
/// </summary>
public void SkipRoom()
{
Logger.Log($"Skipping {this}...", LogType.PuzzleFlow);
_puzzles.ForEach(puzzle => puzzle.Solve());
}
private void OnPuzzleEvent(PuzzleModule puzzle, PuzzleEventType type)
{
if (type == PuzzleEventType.Solved)
{
if (_puzzles.All(p => p.Solved))
{
exit.fromOut.Unlock();
}
}
}
internal void InstantiateRoom(Transform parent, string name)
{
roomObject = new GameObject($"Room {name}");
@@ -32,13 +64,9 @@ namespace Escape_Room_Engine.Engine.Scripts
}
}
internal void Destroy()
public override string ToString()
{
foreach (var space in _spaces)
{
space.Destroy();
}
Object.Destroy(roomObject);
return roomObject.name;
}
}
}