using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.Utilities;
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
namespace EscapeRoomEngine.Engine.Runtime
{
///
/// The passage handles the two door modules that connect two spaces.
///
public class Passage
{
///
/// The exit door in the previous room.
///
internal readonly DoorModule fromOut;
///
/// The entrance door in the next room.
///
internal DoorModule toIn;
internal Passage(DoorModule from)
{
if (!from.IsExit && !from.description.Equals(Engine.Theme.spawnDoor))
{
throw new WrongTypeException(DoorType.Exit, DoorType.Entrance);
}
fromOut = from;
}
///
/// Place an entrance door in the same position relative to the room origin as the exit 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($"Placed entrance {toIn} at {toIn.RrPosition} (RR)", LogType.ModulePlacement);
}
///
/// Connect the two doors in this passage.
///
internal void ConnectDoors()
{
toIn.Passage = this;
fromOut.Passage = this;
Logger.Log($"Connected passage from {fromOut} to {toIn}", LogType.PassageConnection);
}
///
/// Return the door connected to a given door in this passage.
///
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");
}
}
}