orientation requirements
This commit is contained in:
@@ -15,6 +15,8 @@ MonoBehaviour:
|
|||||||
types: 00000000
|
types: 00000000
|
||||||
modulePrefab: {fileID: 5399176795272327488, guid: da9b7a57e7c37d149827fe17188bdeea,
|
modulePrefab: {fileID: 5399176795272327488, guid: da9b7a57e7c37d149827fe17188bdeea,
|
||||||
type: 3}
|
type: 3}
|
||||||
requirements: []
|
requirements:
|
||||||
|
- {fileID: 11400000, guid: ed4830127e9381245a6af07e42c52422, type: 2}
|
||||||
|
- {fileID: 11400000, guid: 1f1825b71bae09c438a1cb52603347d6, type: 2}
|
||||||
connectedDoorDescription: {fileID: 11400000, guid: 29e2ae36585f4e65966bc9ea2f95ac4a,
|
connectedDoorDescription: {fileID: 11400000, guid: 29e2ae36585f4e65966bc9ea2f95ac4a,
|
||||||
type: 2}
|
type: 2}
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ MonoBehaviour:
|
|||||||
types: 01000000
|
types: 01000000
|
||||||
modulePrefab: {fileID: 5399176795272327488, guid: d877ee36ba6ace440aebce2c20cf70d6,
|
modulePrefab: {fileID: 5399176795272327488, guid: d877ee36ba6ace440aebce2c20cf70d6,
|
||||||
type: 3}
|
type: 3}
|
||||||
requirements: []
|
requirements:
|
||||||
doorType: 1
|
- {fileID: 11400000, guid: ed4830127e9381245a6af07e42c52422, type: 2}
|
||||||
|
- {fileID: 11400000, guid: 1f1825b71bae09c438a1cb52603347d6, type: 2}
|
||||||
connectedDoorDescription: {fileID: 11400000, guid: a70cb93176094309a847f1928d6b950d,
|
connectedDoorDescription: {fileID: 11400000, guid: a70cb93176094309a847f1928d6b950d,
|
||||||
type: 2}
|
type: 2}
|
||||||
|
|||||||
@@ -16,4 +16,5 @@ MonoBehaviour:
|
|||||||
modulePrefab: {fileID: 1780958886295268827, guid: e419cb35bd744b24ea973860d8b1405d,
|
modulePrefab: {fileID: 1780958886295268827, guid: e419cb35bd744b24ea973860d8b1405d,
|
||||||
type: 3}
|
type: 3}
|
||||||
requirements:
|
requirements:
|
||||||
- {fileID: 11400000, guid: d34a7e9c8d3eaf946ade02be9eff0041, type: 2}
|
- {fileID: 11400000, guid: ed4830127e9381245a6af07e42c52422, type: 2}
|
||||||
|
- {fileID: 11400000, guid: 1f1825b71bae09c438a1cb52603347d6, type: 2}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!114 &11400000
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 0}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 872da92bb04647e3bd6e741e6bb0a976, type: 3}
|
||||||
|
m_Name: Face Space Center
|
||||||
|
m_EditorClassIdentifier:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1f1825b71bae09c438a1cb52603347d6
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Escape_Room_Engine.Engine.Scripts.Modules;
|
using Escape_Room_Engine.Engine.Scripts.Modules;
|
||||||
|
using Escape_Room_Engine.Engine.Scripts.Requirements;
|
||||||
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Logger = Escape_Room_Engine.Engine.Scripts.Utilities.Logger;
|
using Logger = Escape_Room_Engine.Engine.Scripts.Utilities.Logger;
|
||||||
@@ -94,17 +95,40 @@ namespace Escape_Room_Engine.Engine.Scripts
|
|||||||
|
|
||||||
// place puzzle
|
// place puzzle
|
||||||
var placementCandidates = space.rrDimensions.EveryPosition;
|
var placementCandidates = space.rrDimensions.EveryPosition;
|
||||||
puzzle._description.PlacementRequirements.ForEach(requirement =>
|
puzzle._description.RequirementsOfType<PlacementRequirement>().ForEach(requirement =>
|
||||||
placementCandidates.IntersectWith(requirement.PlacementCandidates(puzzle, space)));
|
placementCandidates.IntersectWith(requirement.PlacementCandidates(puzzle, space)));
|
||||||
|
|
||||||
|
Logger.Log($"placement candidates: {string.Join(", ", placementCandidates.ToList().ConvertAll(c => c.ToString()))}", LogType.RequirementResolution);
|
||||||
|
|
||||||
if (placementCandidates.Count > 0)
|
if (placementCandidates.Count > 0)
|
||||||
{
|
{
|
||||||
puzzle.Place(placementCandidates.RandomElement());
|
puzzle.Place(placementCandidates.RandomElement());
|
||||||
space.AddModule(puzzle);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Logger.Log("Could not find suitable placement for puzzle", LogType.PuzzleGeneration);
|
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>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -15,6 +16,11 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
|||||||
|
|
||||||
public class Module
|
public class Module
|
||||||
{
|
{
|
||||||
|
public static HashSet<Orientation> EveryOrientation => new(new[]
|
||||||
|
{
|
||||||
|
Orientation.North, Orientation.East, Orientation.South, Orientation.West
|
||||||
|
});
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the space relative (<i>SR</i>) position of this module.
|
/// Get the space relative (<i>SR</i>) position of this module.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -67,6 +73,11 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
|||||||
Logger.Log($"{this} has been placed at {srPosition} (SR)", LogType.ModulePlacement);
|
Logger.Log($"{this} has been placed at {srPosition} (SR)", LogType.ModulePlacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void Orient(Orientation o)
|
||||||
|
{
|
||||||
|
orientation = o;
|
||||||
|
}
|
||||||
|
|
||||||
internal void InstantiateModule(Transform parent)
|
internal void InstantiateModule(Transform parent)
|
||||||
{
|
{
|
||||||
_moduleObject = new GameObject(ToString());
|
_moduleObject = new GameObject(ToString());
|
||||||
@@ -79,7 +90,7 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"Module ({string.Join(',', _description.types.ToList().ConvertAll(type => type.ToString()))})";
|
return $"Module ({string.Join(", ", _description.types.ToList().ConvertAll(type => type.ToString()))})";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
|||||||
public GameObject modulePrefab;
|
public GameObject modulePrefab;
|
||||||
public List<Requirement> requirements = new();
|
public List<Requirement> requirements = new();
|
||||||
|
|
||||||
public List<PlacementRequirement> PlacementRequirements => requirements
|
public List<T> RequirementsOfType<T>() where T : Requirement
|
||||||
.FindAll(requirement => requirement is PlacementRequirement)
|
{
|
||||||
.ConvertAll(requirement => (PlacementRequirement)requirement);
|
return requirements.FindAll(requirement => requirement is T).ConvertAll(requirement => (T)requirement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Escape_Room_Engine.Engine.Scripts.Modules;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Escape_Room_Engine.Engine.Scripts.Requirements
|
||||||
|
{
|
||||||
|
public abstract class OrientationRequirement : Requirement
|
||||||
|
{
|
||||||
|
public abstract IEnumerable<Orientation> OrientationCandidates(Module module, Space space);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0704ea5393394baf921f68d2dcbdfaec
|
||||||
|
timeCreated: 1667878220
|
||||||
@@ -7,19 +7,19 @@ namespace Escape_Room_Engine.Engine.Scripts.Requirements
|
|||||||
[CreateAssetMenu(menuName = "Requirements/Place Along Space Edges")]
|
[CreateAssetMenu(menuName = "Requirements/Place Along Space Edges")]
|
||||||
public class PlaceAlongSpaceEdges : PlacementRequirement
|
public class PlaceAlongSpaceEdges : PlacementRequirement
|
||||||
{
|
{
|
||||||
public override HashSet<Vector2Int> PlacementCandidates(Module module, Space space)
|
public override IEnumerable<Vector2Int> PlacementCandidates(Module module, Space space)
|
||||||
{
|
{
|
||||||
var edgePositions = new HashSet<Vector2Int>();
|
var edgePositions = new HashSet<Vector2Int>();
|
||||||
|
|
||||||
for (var x = 0; x < space.rrDimensions.width; x++)
|
for (var x = 0; x < space.rrDimensions.width; x++)
|
||||||
{
|
{
|
||||||
edgePositions.Add(new Vector2Int(x, 0));
|
edgePositions.Add(new Vector2Int(x, 0));
|
||||||
edgePositions.Add(new Vector2Int(x, space.rrDimensions.length));
|
edgePositions.Add(new Vector2Int(x, space.rrDimensions.length - 1));
|
||||||
}
|
}
|
||||||
for (var z = 0; z < space.rrDimensions.length; z++)
|
for (var z = 0; z < space.rrDimensions.length; z++)
|
||||||
{
|
{
|
||||||
edgePositions.Add(new Vector2Int(0, z));
|
edgePositions.Add(new Vector2Int(0, z));
|
||||||
edgePositions.Add(new Vector2Int(space.rrDimensions.width, z));
|
edgePositions.Add(new Vector2Int(space.rrDimensions.width - 1, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
return edgePositions;
|
return edgePositions;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace Escape_Room_Engine.Engine.Scripts.Requirements
|
|||||||
[CreateAssetMenu(menuName = "Requirements/Place Anywhere")]
|
[CreateAssetMenu(menuName = "Requirements/Place Anywhere")]
|
||||||
public class PlaceAnywhere : PlacementRequirement
|
public class PlaceAnywhere : PlacementRequirement
|
||||||
{
|
{
|
||||||
public override HashSet<Vector2Int> PlacementCandidates(Module module, Space space)
|
public override IEnumerable<Vector2Int> PlacementCandidates(Module module, Space space)
|
||||||
{
|
{
|
||||||
return space.rrDimensions.EveryPosition;
|
return space.rrDimensions.EveryPosition;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ namespace Escape_Room_Engine.Engine.Scripts.Requirements
|
|||||||
{
|
{
|
||||||
public abstract class PlacementRequirement : Requirement
|
public abstract class PlacementRequirement : Requirement
|
||||||
{
|
{
|
||||||
public abstract HashSet<Vector2Int> PlacementCandidates(Module module, Space space);
|
public abstract IEnumerable<Vector2Int> PlacementCandidates(Module module, Space space);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ namespace Escape_Room_Engine.Engine.Scripts.Utilities
|
|||||||
{
|
{
|
||||||
public enum LogType
|
public enum LogType
|
||||||
{
|
{
|
||||||
Important, ModulePlacement, PassageConnection, RoomGeneration, PuzzleGeneration
|
Important, ModulePlacement, PassageConnection, RoomGeneration, PuzzleGeneration, RequirementResolution
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Logger : MonoBehaviour
|
public class Logger : MonoBehaviour
|
||||||
|
|||||||
@@ -1233,8 +1233,8 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
roomMaterial: {fileID: 2100000, guid: 39e2ed014eda5d6408c16fbf0fa80781, type: 2}
|
roomMaterial: {fileID: 2100000, guid: 39e2ed014eda5d6408c16fbf0fa80781, type: 2}
|
||||||
minPuzzleCount: 2
|
minPuzzleCount: 1
|
||||||
maxPuzzleCount: 5
|
maxPuzzleCount: 1
|
||||||
minRoomSize: {x: 3, y: 3}
|
minRoomSize: {x: 3, y: 3}
|
||||||
playSpace: {x: 4, y: 6}
|
playSpace: {x: 4, y: 6}
|
||||||
genericModule: {fileID: 11400000, guid: cba85a4318ad4750860b84245d9685c4, type: 2}
|
genericModule: {fileID: 11400000, guid: cba85a4318ad4750860b84245d9685c4, type: 2}
|
||||||
@@ -1271,7 +1271,7 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
loggingEnabled: 1
|
loggingEnabled: 1
|
||||||
typeFilter: 0000000001000000020000000300000004000000
|
typeFilter: 000000000100000002000000030000000400000005000000
|
||||||
--- !u!1 &1718957584
|
--- !u!1 &1718957584
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user