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,23 +1,12 @@
using System;
using EscapeRoomEngine.Engine.Runtime.Utilities;
using UnityEngine;
namespace EscapeRoomEngine.Engine.Runtime.Modules
{
public class PuzzleModule : Module
{
internal PuzzleState PuzzleState
{
get
{
if (State is PuzzleState puzzleState)
{
return puzzleState;
}
internal PuzzleState PuzzleState => PuzzleState.FromState(State);
throw new Exception("PuzzleModule must contain a PuzzleState");
}
}
internal PuzzleModule(Space space, PuzzleModuleDescription description) : base(space, description)
{
srDimensions.Size = Vector2Int.one; // TODO: larger modules
@@ -29,5 +18,15 @@ namespace EscapeRoomEngine.Engine.Runtime.Modules
space.room.AddPuzzle(this);
}
public static PuzzleModule FromModule(Module module)
{
if (module is PuzzleModule puzzleModule)
{
return puzzleModule;
}
throw new WrongTypeException(typeof(PuzzleModule), module.GetType(), typeof(Module));
}
}
}