custom exceptions, methods to create modules and states of specific type from generic ones
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||
@@ -14,18 +15,7 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||
public bool IsEntrance => IsType((ModuleType)DoorType.Entrance);
|
||||
public bool IsExit => IsType((ModuleType)DoorType.Exit);
|
||||
|
||||
internal DoorState DoorState
|
||||
{
|
||||
get
|
||||
{
|
||||
if (State is DoorState doorState)
|
||||
{
|
||||
return doorState;
|
||||
}
|
||||
|
||||
throw new Exception("DoorModule must contain a DoorState");
|
||||
}
|
||||
}
|
||||
internal DoorState DoorState => DoorState.FromState(State);
|
||||
|
||||
internal DoorModule(Space space, DoorModuleDescription description) : base(space, description)
|
||||
{
|
||||
@@ -43,5 +33,15 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
|
||||
{
|
||||
return $"{(IsEntrance ? "Entrance" : IsExit ? "Exit" : "Unknown")} door";
|
||||
}
|
||||
|
||||
public static DoorModule FromModule(Module module)
|
||||
{
|
||||
if (module is DoorModule doorModule)
|
||||
{
|
||||
return doorModule;
|
||||
}
|
||||
|
||||
throw new WrongTypeException(typeof(DoorModule), module.GetType(), typeof(Module));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user