connect multiple rooms with doors
This commit is contained in:
68
Assets/Escape Room Engine/Engine/Scripts/Modules/Module.cs
Normal file
68
Assets/Escape Room Engine/Engine/Scripts/Modules/Module.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
||||
using UnityEngine;
|
||||
using Logger = Escape_Room_Engine.Engine.Scripts.Utilities.Logger;
|
||||
using LogType = Escape_Room_Engine.Engine.Scripts.Utilities.LogType;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
{
|
||||
public class Module
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the space relative (<i>SR</i>) position of this module.
|
||||
/// </summary>
|
||||
internal Vector2Int SrPosition => srDimensions.Position;
|
||||
/// <summary>
|
||||
/// Get the room relative (<i>RR</i>) position of this module.
|
||||
/// </summary>
|
||||
internal Vector2Int RrPosition => space.ToRoomRelative(SrPosition);
|
||||
|
||||
internal readonly Space space;
|
||||
|
||||
protected GameObject _moduleObject;
|
||||
protected readonly List<ModuleType> types = new();
|
||||
/// <summary>
|
||||
/// The space relative (<i>SR</i>) dimensions of this module.
|
||||
/// </summary>
|
||||
protected Dimensions srDimensions;
|
||||
|
||||
internal Module(Space space)
|
||||
{
|
||||
this.space = space;
|
||||
}
|
||||
|
||||
internal bool IsType(ModuleType type)
|
||||
{
|
||||
return types.Contains(type);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Place this module with a position relative to the room.
|
||||
/// </summary>
|
||||
/// <param name="rrPosition">The room relative (<i>RR</i>) position of this module. Must be inside the space dimensions.</param>
|
||||
/// <exception cref="Exception">If the position is not inside the space dimensions.</exception>
|
||||
internal void PlaceRoomRelative(Vector2Int rrPosition) => Place(space.ToSpaceRelative(rrPosition));
|
||||
/// <summary>
|
||||
/// Place this module with a position relative to the space it is in.
|
||||
/// </summary>
|
||||
/// <param name="srPosition">The space relative (<i>SR</i>) position of this module. Must be inside the space dimensions.</param>
|
||||
/// <exception cref="Exception">If the position is not inside the space dimensions.</exception>
|
||||
internal void Place(Vector2Int srPosition) {
|
||||
if (space != null && !srPosition.IsInsideRelative(space.rrDimensions))
|
||||
{
|
||||
throw new Exception($"Trying to place {this} at {srPosition}, which is outside space dimensions {space.rrDimensions}.");
|
||||
}
|
||||
|
||||
srDimensions.Position = srPosition;
|
||||
|
||||
Logger.Log($"{this} has been placed at {srPosition} (SR)", LogType.ModulePlacement);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Module ({string.Join(',', types.ConvertAll(type => type.ToString()))})";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user