puzzle flow
This commit is contained in:
@@ -6,7 +6,7 @@ namespace Escape_Room_Engine.Engine.Scripts.Editor
|
|||||||
{
|
{
|
||||||
public class EngineEditor : EditorWindow
|
public class EngineEditor : EditorWindow
|
||||||
{
|
{
|
||||||
private Button _generateRoomButton;
|
private Button _generateRoomButton, _skipCurrentRoomButton;
|
||||||
|
|
||||||
[MenuItem("Window/Engine/Engine Editor")]
|
[MenuItem("Window/Engine/Engine Editor")]
|
||||||
public static void ShowEditor()
|
public static void ShowEditor()
|
||||||
@@ -21,9 +21,13 @@ namespace Escape_Room_Engine.Engine.Scripts.Editor
|
|||||||
{
|
{
|
||||||
text = "Generate Room"
|
text = "Generate Room"
|
||||||
};
|
};
|
||||||
|
|
||||||
rootVisualElement.Add(_generateRoomButton);
|
rootVisualElement.Add(_generateRoomButton);
|
||||||
|
_skipCurrentRoomButton = new Button(SkipCurrentRoom)
|
||||||
|
{
|
||||||
|
text = "Skip Current Room"
|
||||||
|
};
|
||||||
|
rootVisualElement.Add(_skipCurrentRoomButton);
|
||||||
|
|
||||||
EditorApplication.playModeStateChanged += _ => UpdateUI();
|
EditorApplication.playModeStateChanged += _ => UpdateUI();
|
||||||
UpdateUI();
|
UpdateUI();
|
||||||
}
|
}
|
||||||
@@ -38,9 +42,19 @@ namespace Escape_Room_Engine.Engine.Scripts.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SkipCurrentRoom()
|
||||||
|
{
|
||||||
|
if (EditorApplication.isPlaying)
|
||||||
|
{
|
||||||
|
Engine.DefaultEngine.CurrentRoom.Match(some: room => room.SkipRoom());
|
||||||
|
UpdateUI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateUI()
|
private void UpdateUI()
|
||||||
{
|
{
|
||||||
_generateRoomButton.SetEnabled(EditorApplication.isPlaying);
|
_generateRoomButton.SetEnabled(EditorApplication.isPlaying);
|
||||||
|
_skipCurrentRoomButton.SetEnabled(EditorApplication.isPlaying && Engine.DefaultEngine.NumberOfRooms > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,9 +27,10 @@ namespace Escape_Room_Engine.Engine.Scripts
|
|||||||
|
|
||||||
[Required] public EngineConfiguration config;
|
[Required] public EngineConfiguration config;
|
||||||
|
|
||||||
private int NumberOfRooms => _rooms.Count;
|
public int NumberOfRooms => _rooms.Count;
|
||||||
|
public IOption<Room> CurrentRoom => NumberOfRooms > 0 ? Some<Room>.Of(_rooms[^1]) : None<Room>.New();
|
||||||
|
|
||||||
private readonly List<Room> _rooms = new(1);
|
private readonly List<Room> _rooms = new();
|
||||||
private GameObject _playSpaceOrigin;
|
private GameObject _playSpaceOrigin;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
@@ -59,7 +60,7 @@ namespace Escape_Room_Engine.Engine.Scripts
|
|||||||
Logger.Log("Generating space...", LogType.RoomGeneration);
|
Logger.Log("Generating space...", LogType.RoomGeneration);
|
||||||
|
|
||||||
// create space
|
// create space
|
||||||
var space = new Space(entrance);
|
var space = new Space(room, entrance);
|
||||||
|
|
||||||
// add exit
|
// add exit
|
||||||
var exitDoor = new DoorModule(space, config.exitDoorTypes.RandomElement());
|
var exitDoor = new DoorModule(space, config.exitDoorTypes.RandomElement());
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using LogType = Escape_Room_Engine.Engine.Scripts.Utilities.LogType;
|
||||||
|
|
||||||
namespace Escape_Room_Engine.Engine.Scripts.Modules
|
namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||||
{
|
{
|
||||||
@@ -13,12 +14,21 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
|||||||
{
|
{
|
||||||
public bool IsEntrance => IsType((ModuleType)DoorType.Entrance);
|
public bool IsEntrance => IsType((ModuleType)DoorType.Entrance);
|
||||||
public bool IsExit => IsType((ModuleType)DoorType.Exit);
|
public bool IsExit => IsType((ModuleType)DoorType.Exit);
|
||||||
|
|
||||||
|
private bool _unlocked;
|
||||||
|
|
||||||
internal DoorModule(Space space, DoorModuleDescription description) : base(space, description)
|
internal DoorModule(Space space, DoorModuleDescription description) : base(space, description)
|
||||||
{
|
{
|
||||||
srDimensions.Size = Vector2Int.one; // door always has size 1x1
|
srDimensions.Size = Vector2Int.one; // door always has size 1x1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void Unlock()
|
||||||
|
{
|
||||||
|
_unlocked = true;
|
||||||
|
|
||||||
|
Utilities.Logger.Log($"{this} has been unlocked", LogType.PuzzleFlow);
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{(IsEntrance ? "Entrance" : IsExit ? "Exit" : "Unknown")} door";
|
return $"{(IsEntrance ? "Entrance" : IsExit ? "Exit" : "Unknown")} door";
|
||||||
|
|||||||
@@ -1,12 +1,57 @@
|
|||||||
using UnityEngine;
|
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
||||||
|
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.Modules
|
namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||||
{
|
{
|
||||||
|
public enum PuzzleEventType
|
||||||
|
{
|
||||||
|
Reset, Solved
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void PuzzleEventHandler(PuzzleModule source, PuzzleEventType e);
|
||||||
|
|
||||||
public class PuzzleModule : Module
|
public class PuzzleModule : Module
|
||||||
{
|
{
|
||||||
|
internal event PuzzleEventHandler PuzzleEvent;
|
||||||
|
|
||||||
|
internal bool Solved
|
||||||
|
{
|
||||||
|
get => _solved;
|
||||||
|
private set
|
||||||
|
{
|
||||||
|
var type =
|
||||||
|
!_solved && value ? Some<PuzzleEventType>.Of(PuzzleEventType.Solved)
|
||||||
|
: _solved && value ? Some<PuzzleEventType>.Of(PuzzleEventType.Reset)
|
||||||
|
: None<PuzzleEventType>.New();
|
||||||
|
_solved = value;
|
||||||
|
type.Match(some: OnPuzzleEvent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool _solved;
|
||||||
|
|
||||||
internal PuzzleModule(Space space, PuzzleModuleDescription description) : base(space, description)
|
internal PuzzleModule(Space space, PuzzleModuleDescription description) : base(space, description)
|
||||||
{
|
{
|
||||||
srDimensions.Size = Vector2Int.one; // TODO: larger modules
|
srDimensions.Size = Vector2Int.one; // TODO: larger modules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void OnPuzzleEvent(PuzzleEventType type)
|
||||||
|
{
|
||||||
|
Logger.Log($"{this} has been {type}", LogType.PuzzleFlow);
|
||||||
|
|
||||||
|
PuzzleEvent?.Invoke(this, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Solve()
|
||||||
|
{
|
||||||
|
Solved = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"Puzzle module ({(Solved ? "" : "not ")}solved)";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Escape_Room_Engine.Engine.Scripts.Modules;
|
||||||
using UnityEngine;
|
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
|
namespace Escape_Room_Engine.Engine.Scripts
|
||||||
{
|
{
|
||||||
@@ -8,7 +12,8 @@ namespace Escape_Room_Engine.Engine.Scripts
|
|||||||
internal Passage entrance, exit;
|
internal Passage entrance, exit;
|
||||||
internal GameObject roomObject;
|
internal GameObject roomObject;
|
||||||
|
|
||||||
private List<Space> _spaces = new();
|
private readonly List<Space> _spaces = new();
|
||||||
|
private readonly List<PuzzleModule> _puzzles = new();
|
||||||
|
|
||||||
internal Room(Passage entrance)
|
internal Room(Passage entrance)
|
||||||
{
|
{
|
||||||
@@ -21,6 +26,33 @@ namespace Escape_Room_Engine.Engine.Scripts
|
|||||||
exit = spaceExit;
|
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)
|
internal void InstantiateRoom(Transform parent, string name)
|
||||||
{
|
{
|
||||||
roomObject = new GameObject($"Room {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)
|
return roomObject.name;
|
||||||
{
|
|
||||||
space.Destroy();
|
|
||||||
}
|
|
||||||
Object.Destroy(roomObject);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,11 @@ namespace Escape_Room_Engine.Engine.Scripts
|
|||||||
internal List<Module> Modules { get; } = new(2);
|
internal List<Module> Modules { get; } = new(2);
|
||||||
|
|
||||||
private GameObject _spaceObject;
|
private GameObject _spaceObject;
|
||||||
|
private readonly Room _room;
|
||||||
|
|
||||||
internal Space(Passage entrance)
|
internal Space(Room room, Passage entrance)
|
||||||
{
|
{
|
||||||
|
_room = room;
|
||||||
rrDimensions = GenerateSpaceDimensions(
|
rrDimensions = GenerateSpaceDimensions(
|
||||||
entrance,
|
entrance,
|
||||||
Engine.DefaultEngine.config.minRoomSize,
|
Engine.DefaultEngine.config.minRoomSize,
|
||||||
@@ -34,6 +36,11 @@ namespace Escape_Room_Engine.Engine.Scripts
|
|||||||
internal void AddModule(Module module)
|
internal void AddModule(Module module)
|
||||||
{
|
{
|
||||||
Modules.Add(module);
|
Modules.Add(module);
|
||||||
|
|
||||||
|
if (module is PuzzleModule puzzleModule)
|
||||||
|
{
|
||||||
|
_room.AddPuzzle(puzzleModule);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool AddModuleWithRequirements(Module module)
|
internal bool AddModuleWithRequirements(Module module)
|
||||||
@@ -95,11 +102,6 @@ namespace Escape_Room_Engine.Engine.Scripts
|
|||||||
/// <param name="rrPosition">The room relative (<i>RR</i>) position that should be converted to a space relative (<i>SR</i>) position.</param>
|
/// <param name="rrPosition">The room relative (<i>RR</i>) position that should be converted to a space relative (<i>SR</i>) position.</param>
|
||||||
internal Vector2Int ToSpaceRelative(Vector2Int rrPosition) => rrPosition - rrDimensions.Position;
|
internal Vector2Int ToSpaceRelative(Vector2Int rrPosition) => rrPosition - rrDimensions.Position;
|
||||||
|
|
||||||
internal void Destroy()
|
|
||||||
{
|
|
||||||
Object.Destroy(_spaceObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate space dimensions that fit the required size constraints and cover the position of the entrance.
|
/// Generate space dimensions that fit the required size constraints and cover the position of the entrance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -5,7 +5,13 @@ namespace Escape_Room_Engine.Engine.Scripts.Utilities
|
|||||||
{
|
{
|
||||||
public enum LogType
|
public enum LogType
|
||||||
{
|
{
|
||||||
Important, ModulePlacement, PassageConnection, RoomGeneration, PuzzleGeneration, RequirementResolution
|
Important,
|
||||||
|
ModulePlacement,
|
||||||
|
PassageConnection,
|
||||||
|
RoomGeneration,
|
||||||
|
PuzzleGeneration,
|
||||||
|
RequirementResolution,
|
||||||
|
PuzzleFlow
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Logger : MonoBehaviour
|
public class Logger : MonoBehaviour
|
||||||
|
|||||||
@@ -1233,7 +1233,6 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
config: {fileID: 11400000, guid: 568d9a7d70f3edb4cb6db66a0010f105, type: 2}
|
config: {fileID: 11400000, guid: 568d9a7d70f3edb4cb6db66a0010f105, type: 2}
|
||||||
roomMaterial: {fileID: 2100000, guid: 39e2ed014eda5d6408c16fbf0fa80781, type: 2}
|
|
||||||
--- !u!4 &1568048335
|
--- !u!4 &1568048335
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -1262,7 +1261,7 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
loggingEnabled: 1
|
loggingEnabled: 1
|
||||||
typeFilter: 000000000100000002000000030000000400000005000000
|
typeFilter: 00000000010000000200000003000000040000000500000006000000
|
||||||
--- !u!1 &1718957584
|
--- !u!1 &1718957584
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user