custom exceptions, methods to create modules and states of specific type from generic ones

This commit is contained in:
2022-11-20 22:17:32 +01:00
parent 8ee43d6823
commit b0df3f303a
9 changed files with 92 additions and 54 deletions

View File

@@ -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));
}
}
}