orientation requirements
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Escape_Room_Engine.Engine.Scripts.Modules;
|
||||
using Escape_Room_Engine.Engine.Scripts.Requirements;
|
||||
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
||||
using UnityEngine;
|
||||
using Logger = Escape_Room_Engine.Engine.Scripts.Utilities.Logger;
|
||||
@@ -94,17 +95,40 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
|
||||
// place puzzle
|
||||
var placementCandidates = space.rrDimensions.EveryPosition;
|
||||
puzzle._description.PlacementRequirements.ForEach(requirement =>
|
||||
puzzle._description.RequirementsOfType<PlacementRequirement>().ForEach(requirement =>
|
||||
placementCandidates.IntersectWith(requirement.PlacementCandidates(puzzle, space)));
|
||||
|
||||
Logger.Log($"placement candidates: {string.Join(", ", placementCandidates.ToList().ConvertAll(c => c.ToString()))}", LogType.RequirementResolution);
|
||||
|
||||
if (placementCandidates.Count > 0)
|
||||
{
|
||||
puzzle.Place(placementCandidates.RandomElement());
|
||||
space.AddModule(puzzle);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Log("Could not find suitable placement for puzzle", LogType.PuzzleGeneration);
|
||||
return;
|
||||
}
|
||||
|
||||
// orient puzzle
|
||||
HashSet<Orientation> orientationCandidates = Module.EveryOrientation;
|
||||
Logger.Log($"orientation candidatesA: {string.Join(",", orientationCandidates.ToList().ConvertAll(c => c.ToString()))}", LogType.RequirementResolution);
|
||||
puzzle._description.RequirementsOfType<OrientationRequirement>().ForEach(requirement =>
|
||||
orientationCandidates.IntersectWith(requirement.OrientationCandidates(puzzle, space)));
|
||||
|
||||
Logger.Log($"orientation candidates: {string.Join(",", orientationCandidates.ToList().ConvertAll(c => c.ToString()))}", LogType.RequirementResolution);
|
||||
|
||||
if (orientationCandidates.Count > 0)
|
||||
{
|
||||
puzzle.Orient(orientationCandidates.RandomElement());
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Log("Could not find suitable orientation for puzzle", LogType.PuzzleGeneration);
|
||||
return;
|
||||
}
|
||||
|
||||
space.AddModule(puzzle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user