desert portal
This commit is contained in:
@@ -29,6 +29,7 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
|
||||
[InfoBox("If a space was generated without any puzzles in it, the engine will try generating another new space. To prevent infinite loops, the amount of retries is bound.")]
|
||||
public int maxSpaceGenerationTries;
|
||||
public Vector3 roomOffset;
|
||||
[Required] public EngineTheme theme;
|
||||
|
||||
public int NumberOfRooms => _rooms.Count;
|
||||
@@ -62,8 +63,9 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
_rooms.Add(room);
|
||||
|
||||
GenerateSpace(room, entrance); // TODO: rooms with more than one space
|
||||
|
||||
room.InstantiateRoom(_playSpaceOrigin.transform, (_rooms.Count - 1).ToString());
|
||||
|
||||
var roomId = _rooms.Count - 1;
|
||||
room.InstantiateRoom(_playSpaceOrigin.transform, roomId * roomOffset, roomId.ToString());
|
||||
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,31 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||
public bool IsEntrance => IsType((ModuleType)DoorType.Entrance);
|
||||
public bool IsExit => IsType((ModuleType)DoorType.Exit);
|
||||
|
||||
internal DoorState DoorState => DoorState.FromState(State);
|
||||
public DoorState DoorState => DoorState.FromState(State);
|
||||
public DoorState ConnectedDoorState => Passage.Other(this).DoorState;
|
||||
|
||||
/// <summary>
|
||||
/// Once this property is set, the door is considered to be connected. This property must only be set once.
|
||||
/// </summary>
|
||||
internal Passage Passage
|
||||
{
|
||||
get => _passage;
|
||||
set
|
||||
{
|
||||
if (_passage != null)
|
||||
{
|
||||
throw new EngineException($"{this} is already connected");
|
||||
}
|
||||
|
||||
_passage = value;
|
||||
if (State != null)
|
||||
{
|
||||
DoorState.Connect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Passage _passage;
|
||||
|
||||
internal DoorModule(Space space, DoorModuleDescription description) : base(space, description) {}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||
{
|
||||
public enum DoorEventType
|
||||
{
|
||||
Locked, Unlocked
|
||||
Locked, Unlocked, Connected
|
||||
}
|
||||
|
||||
public delegate void DoorEventHandler(DoorModule source, DoorEventType e);
|
||||
@@ -14,7 +14,7 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||
{
|
||||
public event DoorEventHandler DoorEvent;
|
||||
|
||||
private DoorModule Module { get; set; }
|
||||
protected DoorModule Module { get; set; }
|
||||
public bool Unlocked
|
||||
{
|
||||
get => _unlocked;
|
||||
@@ -43,17 +43,17 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||
Module = DoorModule.FromModule(module);
|
||||
}
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
internal void Unlock()
|
||||
{
|
||||
Unlocked = true;
|
||||
}
|
||||
public void Connect() => OnDoorEvent(DoorEventType.Connected);
|
||||
|
||||
#region Debug Buttons
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
internal void Lock()
|
||||
{
|
||||
Unlocked = false;
|
||||
}
|
||||
internal void Unlock() => Unlocked = true;
|
||||
|
||||
[Button(enabledMode: EButtonEnableMode.Playmode)]
|
||||
internal void Lock() => Unlocked = false;
|
||||
|
||||
#endregion
|
||||
|
||||
public static DoorState FromState(ModuleState state)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
||||
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
|
||||
|
||||
@@ -11,17 +12,49 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
|
||||
internal Passage(DoorModule from)
|
||||
{
|
||||
if (!from.IsExit && !from.description.Equals(Engine.DefaultEngine.theme.spawnDoor))
|
||||
{
|
||||
throw new WrongTypeException(DoorType.Exit, DoorType.Entrance);
|
||||
}
|
||||
|
||||
fromOut = from;
|
||||
}
|
||||
|
||||
internal void ConnectTo(DoorModule door)
|
||||
internal void PlaceEntrance(DoorModule door)
|
||||
{
|
||||
if (!door.IsEntrance)
|
||||
{
|
||||
throw new WrongTypeException(DoorType.Entrance, DoorType.Exit);
|
||||
}
|
||||
|
||||
toIn = door;
|
||||
|
||||
// to make sure the origin of the player doesn't move, the two doors must be placed in the same location in the same orientation
|
||||
toIn.PlaceRoomRelative(fromOut.RrPosition, fromOut.Orientation);
|
||||
|
||||
Logger.Log($"Connected passage from {fromOut} to {toIn} at {toIn.RrPosition} (RR)", LogType.PassageConnection);
|
||||
Logger.Log($"Placed entrance {toIn} at {toIn.RrPosition} (RR)", LogType.ModulePlacement);
|
||||
}
|
||||
|
||||
internal void ConnectDoors()
|
||||
{
|
||||
toIn.Passage = this;
|
||||
fromOut.Passage = this;
|
||||
|
||||
Logger.Log($"Connected passage from {fromOut} to {toIn}", LogType.PassageConnection);
|
||||
}
|
||||
|
||||
internal DoorModule Other(DoorModule of)
|
||||
{
|
||||
if (of.Equals(fromOut))
|
||||
{
|
||||
return toIn;
|
||||
}
|
||||
if(of.Equals(toIn))
|
||||
{
|
||||
return fromOut;
|
||||
}
|
||||
|
||||
throw new EngineException($"{of} is not connected to this passage");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,15 +73,18 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
}
|
||||
}
|
||||
|
||||
internal void InstantiateRoom(Transform parent, string name)
|
||||
internal void InstantiateRoom(Transform parent, Vector3 offset, string name)
|
||||
{
|
||||
roomObject = new GameObject($"Room {name}");
|
||||
roomObject.transform.SetParent(parent, false);
|
||||
roomObject.transform.localPosition = offset;
|
||||
|
||||
for (var i = 0; i < _spaces.Count; i++)
|
||||
{
|
||||
_spaces[i].InstantiateSpace(roomObject.transform, i.ToString());
|
||||
}
|
||||
|
||||
entrance.ConnectDoors();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace EscapeRoomEngine.Engine.Runtime
|
||||
Engine.DefaultEngine.theme.playSpace.ProjectAtFloor());
|
||||
|
||||
// connect the space to its passage
|
||||
entrance.ConnectTo(new DoorModule(this,
|
||||
entrance.PlaceEntrance(new DoorModule(this,
|
||||
((DoorModuleDescription)entrance.fromOut.description).connectedDoorDescription));
|
||||
Modules.Add(entrance.toIn);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime.Utilities
|
||||
{
|
||||
@@ -11,6 +12,8 @@ namespace EscapeRoomEngine.Engine.Runtime.Utilities
|
||||
{
|
||||
public WrongTypeException(Type expected, Type found, Type baseType) : base($"Wrong type of {baseType} ({found} instead of {expected})") {}
|
||||
|
||||
public WrongTypeException(DoorType expected, DoorType found) : base($"Wrong door type ({found} instead of {expected})") {}
|
||||
|
||||
public WrongTypeException(string message) : base(message) {}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user