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