requirements for exit door
This commit is contained in:
@@ -1,24 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using Escape_Room_Engine.Engine.Scripts.Modules;
|
||||
using Unity.XR.CoreUtils;
|
||||
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.Requirements
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Requirements/Face Space Center")]
|
||||
public class FaceSpaceCenter : OrientationRequirement
|
||||
{
|
||||
public override IEnumerable<Orientation> OrientationCandidates(Module module, Space space)
|
||||
protected override IEnumerable<Orientation> GenerateCandidates(Module module, Space space)
|
||||
{
|
||||
var orientation = new HashSet<Orientation>(1);
|
||||
float width = space.rrDimensions.width;
|
||||
float length = space.rrDimensions.length;
|
||||
var xRel = module.SrPosition.x / (width - 1);
|
||||
var zRel = module.SrPosition.y / (length - 1);
|
||||
|
||||
Debug.Log($"{xRel}, {zRel}, {1 - xRel}");
|
||||
|
||||
if (zRel > xRel)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Escape_Room_Engine.Engine.Scripts.Requirements
|
||||
[CreateAssetMenu(menuName = "Requirements/No Overlap")]
|
||||
public class NoOverlap : PlacementRequirement
|
||||
{
|
||||
public override IEnumerable<Vector2Int> PlacementCandidates(Module module, Space space)
|
||||
protected override IEnumerable<Vector2Int> GenerateCandidates(Module module, Space space)
|
||||
{
|
||||
var edgePositions = space.rrDimensions.EveryPosition;
|
||||
|
||||
|
||||
@@ -1,10 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Escape_Room_Engine.Engine.Scripts.Modules;
|
||||
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts.Requirements
|
||||
{
|
||||
public abstract class OrientationRequirement : Requirement
|
||||
public abstract class OrientationRequirement : Requirement<Orientation>
|
||||
{
|
||||
public abstract IEnumerable<Orientation> OrientationCandidates(Module module, Space space);
|
||||
protected abstract override IEnumerable<Orientation> GenerateCandidates(Module module, Space space);
|
||||
|
||||
public static bool TryOrienting(Module module, Space space)
|
||||
{
|
||||
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.PuzzleGeneration);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace Escape_Room_Engine.Engine.Scripts.Requirements
|
||||
[CreateAssetMenu(menuName = "Requirements/Place Along Space Edges")]
|
||||
public class PlaceAlongSpaceEdges : PlacementRequirement
|
||||
{
|
||||
public override IEnumerable<Vector2Int> PlacementCandidates(Module module, Space space)
|
||||
protected override IEnumerable<Vector2Int> GenerateCandidates(Module module, Space space)
|
||||
{
|
||||
var edgePositions = new HashSet<Vector2Int>();
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Escape_Room_Engine.Engine.Scripts.Requirements
|
||||
[CreateAssetMenu(menuName = "Requirements/Place Anywhere")]
|
||||
public class PlaceAnywhere : PlacementRequirement
|
||||
{
|
||||
public override IEnumerable<Vector2Int> PlacementCandidates(Module module, Space space)
|
||||
protected override IEnumerable<Vector2Int> GenerateCandidates(Module module, Space space)
|
||||
{
|
||||
return space.rrDimensions.EveryPosition;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Escape_Room_Engine.Engine.Scripts.Modules;
|
||||
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts.Requirements
|
||||
{
|
||||
public abstract class PlacementRequirement : Requirement
|
||||
public abstract class PlacementRequirement : Requirement<Vector2Int>
|
||||
{
|
||||
public abstract IEnumerable<Vector2Int> PlacementCandidates(Module module, Space space);
|
||||
protected abstract override IEnumerable<Vector2Int> GenerateCandidates(Module module, Space space);
|
||||
|
||||
public static bool TryPlacing(Module module, Space space)
|
||||
{
|
||||
var placementCandidates = Candidates(
|
||||
space.rrDimensions.EveryPosition,
|
||||
module.description.placementRequirements,
|
||||
module, space);
|
||||
|
||||
Utilities.Logger.Log($"placement candidates: {string.Join(", ", placementCandidates.ToList().ConvertAll(c => c.ToString()))}", Utilities.LogType.RequirementResolution);
|
||||
|
||||
if (placementCandidates.Count > 0)
|
||||
{
|
||||
module.Place(placementCandidates.RandomElement());
|
||||
return true;
|
||||
}
|
||||
// ReSharper disable once RedundantIfElseBlock
|
||||
else
|
||||
{
|
||||
Utilities.Logger.Log("Could not find suitable placement for module", Utilities.LogType.PuzzleGeneration);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,27 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using Escape_Room_Engine.Engine.Scripts.Modules;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts.Requirements
|
||||
{
|
||||
public abstract class Requirement : ScriptableObject
|
||||
public abstract class Requirement<T> : ScriptableObject
|
||||
{
|
||||
|
||||
protected abstract IEnumerable<T> GenerateCandidates(Module module, Space space);
|
||||
|
||||
public void Restrict(HashSet<T> candidates, Module module, Space space) =>
|
||||
candidates.IntersectWith(GenerateCandidates(module, space));
|
||||
|
||||
public static HashSet<T> Candidates(
|
||||
HashSet<T> initialCandidates,
|
||||
IEnumerable<Requirement<T>> requirements,
|
||||
Module module, Space space)
|
||||
{
|
||||
foreach (var requirement in requirements)
|
||||
{
|
||||
requirement.Restrict(initialCandidates, module, space);
|
||||
}
|
||||
|
||||
return initialCandidates;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user