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 System.Runtime.CompilerServices;
using EscapeRoomEngine.Engine.Runtime.Utilities;
using NaughtyAttributes;
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
@@ -58,14 +59,7 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
public override void SetModule(Module module)
{
if (module is PuzzleModule puzzleModule)
{
Module = puzzleModule;
}
else
{
throw new Exception($"Tried to set wrong type of module ({module.GetType()} instead of PuzzleModule)");
}
Module = PuzzleModule.FromModule(module);
}
[Button(enabledMode: EButtonEnableMode.Playmode)]
@@ -88,5 +82,15 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
OnPuzzleEvent(PuzzleEventType.WrongInput);
}
}
public static PuzzleState FromState(ModuleState state)
{
if (state is PuzzleState puzzleState)
{
return puzzleState;
}
throw new WrongTypeException(typeof(PuzzleState), state.GetType(), typeof(ModuleState));
}
}
}