Files
modular-vr/Assets/Engine/Runtime/Passage.cs
2022-11-27 12:12:02 +01:00

60 lines
1.8 KiB
C#

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
{
public class Passage
{
internal readonly DoorModule fromOut;
internal DoorModule toIn;
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 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);
}
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");
}
}
}