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 { public class Room { internal Passage entrance, exit; internal GameObject roomObject; private readonly List _spaces = new(); private readonly List _puzzles = new(); internal Room(Passage entrance) { this.entrance = entrance; } internal void AddSpace(Space space, Passage spaceExit) { _spaces.Add(space); exit = spaceExit; } internal void AddPuzzle(PuzzleModule puzzle) { _puzzles.Add(puzzle); puzzle.PuzzleEvent += OnPuzzleEvent; } /// /// Solves all puzzles in this room. /// 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}"); roomObject.transform.SetParent(parent, false); for (var i = 0; i < _spaces.Count; i++) { _spaces[i].InstantiateSpace(roomObject.transform, i.ToString()); } } public override string ToString() { return roomObject.name; } } }