split into multiple assemblies
This commit is contained in:
30
Assets/Engine/Runtime/Requirements/FaceSpaceCenter.cs
Normal file
30
Assets/Engine/Runtime/Requirements/FaceSpaceCenter.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime.Requirements
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Requirements/Face Space Center")]
|
||||
public class FaceSpaceCenter : OrientationRequirement
|
||||
{
|
||||
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);
|
||||
|
||||
if (zRel > xRel)
|
||||
{
|
||||
orientation.Add(zRel > 1 - xRel ? Orientation.South : Orientation.East);
|
||||
}
|
||||
else
|
||||
{
|
||||
orientation.Add(zRel > 1 - xRel ? Orientation.West : Orientation.North);
|
||||
}
|
||||
|
||||
return orientation;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 872da92bb04647e3bd6e741e6bb0a976
|
||||
timeCreated: 1667878978
|
||||
31
Assets/Engine/Runtime/Requirements/NoOverlap.cs
Normal file
31
Assets/Engine/Runtime/Requirements/NoOverlap.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime.Requirements
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Requirements/No Overlap")]
|
||||
public class NoOverlap : PlacementRequirement
|
||||
{
|
||||
[InfoBox("A module relative position will be oriented with the module (e.g. (0, 1) is always in front of the module).")]
|
||||
[Label("Reserved Positions (Module Relative)")]
|
||||
public List<Vector2Int> mrReservedPositions;
|
||||
|
||||
protected override IEnumerable<Vector2Int> GenerateCandidates(Module module, Space space)
|
||||
{
|
||||
var candidates = space.rrDimensions.EveryPosition;
|
||||
|
||||
space.Modules.ForEach(m =>
|
||||
{
|
||||
candidates.Remove(m.SrPosition);
|
||||
m.description.placementRequirements
|
||||
.FindAll(r => r is NoOverlap)
|
||||
.ForEach(r => ((NoOverlap)r).mrReservedPositions
|
||||
.ForEach(p => candidates.Remove(m.ToSpaceRelative(p))));
|
||||
});
|
||||
|
||||
return candidates;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Engine/Runtime/Requirements/NoOverlap.cs.meta
Normal file
3
Assets/Engine/Runtime/Requirements/NoOverlap.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58ae9c09c887475d833d2cd4ee4ccffb
|
||||
timeCreated: 1667881856
|
||||
34
Assets/Engine/Runtime/Requirements/OrientationRequirement.cs
Normal file
34
Assets/Engine/Runtime/Requirements/OrientationRequirement.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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)
|
||||
{
|
||||
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.ModulePlacement);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0704ea5393394baf921f68d2dcbdfaec
|
||||
timeCreated: 1667878220
|
||||
28
Assets/Engine/Runtime/Requirements/PlaceAlongSpaceEdges.cs
Normal file
28
Assets/Engine/Runtime/Requirements/PlaceAlongSpaceEdges.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime.Requirements
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Requirements/Place Along Space Edges")]
|
||||
public class PlaceAlongSpaceEdges : PlacementRequirement
|
||||
{
|
||||
protected override IEnumerable<Vector2Int> GenerateCandidates(Module module, Space space)
|
||||
{
|
||||
var edgePositions = new HashSet<Vector2Int>();
|
||||
|
||||
for (var x = 0; x < space.rrDimensions.width; x++)
|
||||
{
|
||||
edgePositions.Add(new Vector2Int(x, 0));
|
||||
edgePositions.Add(new Vector2Int(x, space.rrDimensions.length - 1));
|
||||
}
|
||||
for (var z = 0; z < space.rrDimensions.length; z++)
|
||||
{
|
||||
edgePositions.Add(new Vector2Int(0, z));
|
||||
edgePositions.Add(new Vector2Int(space.rrDimensions.width - 1, z));
|
||||
}
|
||||
|
||||
return edgePositions;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ec2cdf0145347e18e7c68221333be2c
|
||||
timeCreated: 1667876484
|
||||
15
Assets/Engine/Runtime/Requirements/PlaceAnywhere.cs
Normal file
15
Assets/Engine/Runtime/Requirements/PlaceAnywhere.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime.Requirements
|
||||
{
|
||||
[CreateAssetMenu(menuName = "Requirements/Place Anywhere")]
|
||||
public class PlaceAnywhere : PlacementRequirement
|
||||
{
|
||||
protected override IEnumerable<Vector2Int> GenerateCandidates(Module module, Space space)
|
||||
{
|
||||
return space.rrDimensions.EveryPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Engine/Runtime/Requirements/PlaceAnywhere.cs.meta
Normal file
3
Assets/Engine/Runtime/Requirements/PlaceAnywhere.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa4ff365b4e844e782cd12d8aeebd3d4
|
||||
timeCreated: 1667876850
|
||||
37
Assets/Engine/Runtime/Requirements/PlacementRequirement.cs
Normal file
37
Assets/Engine/Runtime/Requirements/PlacementRequirement.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
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)
|
||||
{
|
||||
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.ModulePlacement);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 65f297b8d32b4f09b89c21b88b43b646
|
||||
timeCreated: 1667876036
|
||||
27
Assets/Engine/Runtime/Requirements/Requirement.cs
Normal file
27
Assets/Engine/Runtime/Requirements/Requirement.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
using EscapeRoomEngine.Engine.Runtime.Modules;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EscapeRoomEngine.Engine.Runtime.Requirements
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Engine/Runtime/Requirements/Requirement.cs.meta
Normal file
3
Assets/Engine/Runtime/Requirements/Requirement.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9123b592f74444c8b6225f725b6407b3
|
||||
timeCreated: 1667874140
|
||||
Reference in New Issue
Block a user