43 lines
1.6 KiB
C#
43 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using EscapeRoomEngine.Engine.Runtime.Modules;
|
|
using EscapeRoomEngine.Engine.Runtime.Utilities;
|
|
using UnityEngine;
|
|
using Logger = EscapeRoomEngine.Engine.Runtime.Utilities.Logger;
|
|
using LogType = EscapeRoomEngine.Engine.Runtime.Utilities.LogType;
|
|
|
|
namespace EscapeRoomEngine.Engine.Runtime.Requirements
|
|
{
|
|
public abstract class PlacementRequirement : Requirement<Vector2Int>
|
|
{
|
|
protected abstract override IEnumerable<Vector2Int> GenerateCandidates(Module module, Space space);
|
|
|
|
public static bool TryPlacing(Module module, Space space)
|
|
{
|
|
if (module.description.placementRequirements.Count == 0)
|
|
{
|
|
// don't evaluate requirements if there are none
|
|
return true;
|
|
}
|
|
|
|
var placementCandidates = Candidates(
|
|
space.rrDimensions.EveryPosition,
|
|
module.description.placementRequirements,
|
|
module, space);
|
|
|
|
Logger.Log($"placement candidates: {string.Join(", ", placementCandidates.ToList().ConvertAll(c => c.ToString()))}", LogType.RequirementResolution);
|
|
|
|
if (placementCandidates.Count > 0)
|
|
{
|
|
module.Place(placementCandidates.RandomElement());
|
|
return true;
|
|
}
|
|
// ReSharper disable once RedundantIfElseBlock
|
|
else
|
|
{
|
|
Logger.Log($"Could not find suitable placement for {module}", LogType.RequirementResolution);
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
} |