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
{
///
/// Get the space relative (SR) position of this module.
///
internal Vector2Int SrPosition => srDimensions.Position;
///
/// Get the room relative (RR) position of this module.
///
internal Vector2Int RrPosition => space.ToRoomRelative(SrPosition);
internal readonly Space space;
protected GameObject _moduleObject;
protected readonly List types = new();
///
/// The space relative (SR) dimensions of this module.
///
protected Dimensions srDimensions;
internal Module(Space space)
{
this.space = space;
}
internal bool IsType(ModuleType type)
{
return types.Contains(type);
}
///
/// Place this module with a position relative to the room.
///
/// The room relative (RR) position of this module. Must be inside the space dimensions.
/// If the position is not inside the space dimensions.
internal void PlaceRoomRelative(Vector2Int rrPosition) => Place(space.ToSpaceRelative(rrPosition));
///
/// Place this module with a position relative to the space it is in.
///
/// The space relative (SR) position of this module. Must be inside the space dimensions.
/// If the position is not inside the space dimensions.
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()))})";
}
}
}