make sure every module is accessible

This commit is contained in:
2022-11-07 20:51:00 +01:00
parent aae5e78082
commit 648919cf5a
13 changed files with 100 additions and 30 deletions

View File

@@ -15,8 +15,8 @@ MonoBehaviour:
types: 00000000 types: 00000000
modulePrefab: {fileID: 5399176795272327488, guid: da9b7a57e7c37d149827fe17188bdeea, modulePrefab: {fileID: 5399176795272327488, guid: da9b7a57e7c37d149827fe17188bdeea,
type: 3} type: 3}
requirements: placementRequirements:
- {fileID: 11400000, guid: ed4830127e9381245a6af07e42c52422, type: 2} - {fileID: 11400000, guid: 43eb2a566a244964aa3a3319eaafe1a8, type: 2}
- {fileID: 11400000, guid: 1f1825b71bae09c438a1cb52603347d6, type: 2} orientationRequirements: []
connectedDoorDescription: {fileID: 11400000, guid: 29e2ae36585f4e65966bc9ea2f95ac4a, connectedDoorDescription: {fileID: 11400000, guid: 29e2ae36585f4e65966bc9ea2f95ac4a,
type: 2} type: 2}

View File

@@ -15,8 +15,10 @@ MonoBehaviour:
types: 01000000 types: 01000000
modulePrefab: {fileID: 5399176795272327488, guid: d877ee36ba6ace440aebce2c20cf70d6, modulePrefab: {fileID: 5399176795272327488, guid: d877ee36ba6ace440aebce2c20cf70d6,
type: 3} type: 3}
requirements: placementRequirements:
- {fileID: 11400000, guid: 43eb2a566a244964aa3a3319eaafe1a8, type: 2}
- {fileID: 11400000, guid: ed4830127e9381245a6af07e42c52422, type: 2} - {fileID: 11400000, guid: ed4830127e9381245a6af07e42c52422, type: 2}
orientationRequirements:
- {fileID: 11400000, guid: 1f1825b71bae09c438a1cb52603347d6, type: 2} - {fileID: 11400000, guid: 1f1825b71bae09c438a1cb52603347d6, type: 2}
connectedDoorDescription: {fileID: 11400000, guid: a70cb93176094309a847f1928d6b950d, connectedDoorDescription: {fileID: 11400000, guid: a70cb93176094309a847f1928d6b950d,
type: 2} type: 2}

View File

@@ -15,4 +15,6 @@ MonoBehaviour:
types: types:
modulePrefab: {fileID: 3864228228344123331, guid: ad2655de8289afa40aa520f9fc474681, modulePrefab: {fileID: 3864228228344123331, guid: ad2655de8289afa40aa520f9fc474681,
type: 3} type: 3}
requirements: [] placementRequirements:
- {fileID: 11400000, guid: 43eb2a566a244964aa3a3319eaafe1a8, type: 2}
orientationRequirements: []

View File

@@ -15,6 +15,8 @@ MonoBehaviour:
types: 02000000 types: 02000000
modulePrefab: {fileID: 1780958886295268827, guid: e419cb35bd744b24ea973860d8b1405d, modulePrefab: {fileID: 1780958886295268827, guid: e419cb35bd744b24ea973860d8b1405d,
type: 3} type: 3}
requirements: placementRequirements:
- {fileID: 11400000, guid: 43eb2a566a244964aa3a3319eaafe1a8, type: 2}
- {fileID: 11400000, guid: ed4830127e9381245a6af07e42c52422, type: 2} - {fileID: 11400000, guid: ed4830127e9381245a6af07e42c52422, type: 2}
orientationRequirements:
- {fileID: 11400000, guid: 1f1825b71bae09c438a1cb52603347d6, type: 2} - {fileID: 11400000, guid: 1f1825b71bae09c438a1cb52603347d6, type: 2}

View File

@@ -15,6 +15,7 @@ MonoBehaviour:
types: 00000000 types: 00000000
modulePrefab: {fileID: 641449049689494886, guid: db5350cd22f3a0f4f818a5f985342136, modulePrefab: {fileID: 641449049689494886, guid: db5350cd22f3a0f4f818a5f985342136,
type: 3} type: 3}
requirements: [] placementRequirements:
doorType: 0 - {fileID: 11400000, guid: 43eb2a566a244964aa3a3319eaafe1a8, type: 2}
orientationRequirements: []
connectedDoorDescription: {fileID: 11400000} connectedDoorDescription: {fileID: 11400000}

View File

@@ -12,3 +12,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 58ae9c09c887475d833d2cd4ee4ccffb, type: 3} m_Script: {fileID: 11500000, guid: 58ae9c09c887475d833d2cd4ee4ccffb, type: 3}
m_Name: No Overlap m_Name: No Overlap
m_EditorClassIdentifier: m_EditorClassIdentifier:
mrReservedPositions:
- {x: 1, y: 0}
- {x: 0, y: 1}
- {x: -1, y: 0}
- {x: 0, y: -1}

View File

@@ -3,6 +3,7 @@ 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.Utilities; using Escape_Room_Engine.Engine.Scripts.Utilities;
using NaughtyAttributes;
using UnityEngine; using UnityEngine;
using Logger = Escape_Room_Engine.Engine.Scripts.Utilities.Logger; using Logger = Escape_Room_Engine.Engine.Scripts.Utilities.Logger;
using LogType = Escape_Room_Engine.Engine.Scripts.Utilities.LogType; using LogType = Escape_Room_Engine.Engine.Scripts.Utilities.LogType;
@@ -24,16 +25,31 @@ namespace Escape_Room_Engine.Engine.Scripts
} }
private static Engine _foundEngine; private static Engine _foundEngine;
public Material roomMaterial; [BoxGroup("Size")]
[Tooltip("The minimum size that should be allowed for rooms.")]
public Vector2Int minRoomSize;
[Range(0, 10)] public int minPuzzleCount, maxPuzzleCount; [BoxGroup("Size")]
[Tooltip("The minimum size that should be allowed for rooms.")] public Vector2Int minRoomSize; [Tooltip("The size of the physical play space available to the engine.")]
[Tooltip("The size of the physical play space available to the engine.")] public Vector2Int playSpace; public Vector2Int playSpace;
public ModuleDescription genericModule;
[BoxGroup("Doors")]
[Required]
public DoorModuleDescription spawnDoor; public DoorModuleDescription spawnDoor;
[BoxGroup("Doors")]
[ValidateInput("IsNotEmpty", "At least one exit door type is required")]
public List<DoorModuleDescription> exitDoorTypes; public List<DoorModuleDescription> exitDoorTypes;
[BoxGroup("Puzzles")]
[MinMaxSlider(0, 10)] public Vector2Int puzzleCount;
[BoxGroup("Puzzles")]
public List<PuzzleModuleDescription> puzzleTypes; public List<PuzzleModuleDescription> puzzleTypes;
public Material roomMaterial;
public ModuleDescription genericModule;
private int NumberOfRooms => _rooms.Count; private int NumberOfRooms => _rooms.Count;
private readonly List<Room> _rooms = new(1); private readonly List<Room> _rooms = new(1);
@@ -75,7 +91,7 @@ namespace Escape_Room_Engine.Engine.Scripts
var exit = new Passage(exitDoor); var exit = new Passage(exitDoor);
// add puzzles // add puzzles
for (var i = 0; i < Utilities.Utilities.RandomInclusive(minPuzzleCount, maxPuzzleCount); i++) for (var i = 0; i < Utilities.Utilities.RandomInclusive(puzzleCount.x, puzzleCount.y); i++)
{ {
space.AddModuleWithRequirements(new PuzzleModule(space, puzzleTypes.RandomElement())); space.AddModuleWithRequirements(new PuzzleModule(space, puzzleTypes.RandomElement()));
} }
@@ -90,5 +106,9 @@ namespace Escape_Room_Engine.Engine.Scripts
_rooms[NumberOfRooms - 1].roomObject.SetActive(false); _rooms[NumberOfRooms - 1].roomObject.SetActive(false);
} }
} }
// ReSharper disable once SuggestBaseTypeForParameter
// ReSharper disable once UnusedMember.Local
private bool IsNotEmpty(List<DoorModuleDescription> modules) => modules.Count > 0;
} }
} }

View File

@@ -74,6 +74,24 @@ 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);
} }
/// <summary>
/// Convert a position relative to this module to one relative to its space.
/// <example>The module relative position <c>(0, 1)</c> should always be in front of the module, wherever it faces.</example>
/// </summary>
/// <param name="mrPosition">The module relative (<i>MR</i>) position that should be converted to a space relative (<i>SR</i>) position.</param>
/// <returns></returns>
internal Vector2Int ToSpaceRelative(Vector2Int mrPosition)
{
return srDimensions.Position + orientation switch
{
Orientation.North => mrPosition,
Orientation.East => new Vector2Int(mrPosition.y, -mrPosition.x),
Orientation.South => -mrPosition,
Orientation.West => new Vector2Int(-mrPosition.y, mrPosition.x),
_ => throw new ArgumentOutOfRangeException()
};
}
internal void InstantiateModule(Transform parent) internal void InstantiateModule(Transform parent)
{ {
_moduleObject = new GameObject(ToString()); _moduleObject = new GameObject(ToString());

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Escape_Room_Engine.Engine.Scripts.Modules; using Escape_Room_Engine.Engine.Scripts.Modules;
using NaughtyAttributes;
using UnityEngine; using UnityEngine;
namespace Escape_Room_Engine.Engine.Scripts.Requirements namespace Escape_Room_Engine.Engine.Scripts.Requirements
@@ -7,13 +8,24 @@ namespace Escape_Room_Engine.Engine.Scripts.Requirements
[CreateAssetMenu(menuName = "Requirements/No Overlap")] [CreateAssetMenu(menuName = "Requirements/No Overlap")]
public class NoOverlap : PlacementRequirement 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) protected override IEnumerable<Vector2Int> GenerateCandidates(Module module, Space space)
{ {
var edgePositions = space.rrDimensions.EveryPosition; var candidates = space.rrDimensions.EveryPosition;
space.Modules.ForEach(m => edgePositions.Remove(m.SrPosition)); 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 edgePositions; return candidates;
} }
} }
} }

View File

@@ -35,13 +35,16 @@ namespace Escape_Room_Engine.Engine.Scripts
internal bool AddModuleWithRequirements(Module module) internal bool AddModuleWithRequirements(Module module)
{ {
var result = var requirementsFulfilled =
PlacementRequirement.TryPlacing(module, this) && PlacementRequirement.TryPlacing(module, this) &&
OrientationRequirement.TryOrienting(module, this); OrientationRequirement.TryOrienting(module, this);
if (requirementsFulfilled)
{
AddModule(module); AddModule(module);
}
return result; return requirementsFulfilled;
} }
internal void InstantiateSpace(Transform parent, string name) internal void InstantiateSpace(Transform parent, string name)
@@ -64,13 +67,11 @@ namespace Escape_Room_Engine.Engine.Scripts
/// Convert a position relative to this space to one relative to the room. /// Convert a position relative to this space to one relative to the room.
/// </summary> /// </summary>
/// <param name="srPosition">The space relative (<i>SR</i>) position that should be converted to a room relative (<i>RR</i>) position.</param> /// <param name="srPosition">The space relative (<i>SR</i>) position that should be converted to a room relative (<i>RR</i>) position.</param>
/// <returns></returns>
internal Vector2Int ToRoomRelative(Vector2Int srPosition) => srPosition + rrDimensions.Position; internal Vector2Int ToRoomRelative(Vector2Int srPosition) => srPosition + rrDimensions.Position;
/// <summary> /// <summary>
/// Convert a position relative to the room to one relative to this space. /// Convert a position relative to the room to one relative to this space.
/// </summary> /// </summary>
/// <param name="rrPosition">The room relative (<i>RR</i>) position that should be converted to a space relative (<i>SR</i>) position.</param> /// <param name="rrPosition">The room relative (<i>RR</i>) position that should be converted to a space relative (<i>SR</i>) position.</param>
/// <returns></returns>
internal Vector2Int ToSpaceRelative(Vector2Int rrPosition) => rrPosition - rrDimensions.Position; internal Vector2Int ToSpaceRelative(Vector2Int rrPosition) => rrPosition - rrDimensions.Position;
private Mesh GenerateMesh() private Mesh GenerateMesh()

View File

@@ -1232,17 +1232,16 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 9a9b6b8b557abbb4ab172444615ebf23, type: 3} m_Script: {fileID: 11500000, guid: 9a9b6b8b557abbb4ab172444615ebf23, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
roomMaterial: {fileID: 2100000, guid: 39e2ed014eda5d6408c16fbf0fa80781, type: 2}
minPuzzleCount: 2
maxPuzzleCount: 5
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}
spawnDoor: {fileID: 11400000, guid: 6e937b2e9f774999b5962c4b40947165, type: 2} spawnDoor: {fileID: 11400000, guid: 6e937b2e9f774999b5962c4b40947165, type: 2}
exitDoorTypes: exitDoorTypes:
- {fileID: 11400000, guid: 29e2ae36585f4e65966bc9ea2f95ac4a, type: 2} - {fileID: 11400000, guid: 29e2ae36585f4e65966bc9ea2f95ac4a, type: 2}
puzzleCount: {x: 2, y: 5}
puzzleTypes: puzzleTypes:
- {fileID: 11400000, guid: 2a6dd6683bdc4db9b200ccfab1dd4bed, type: 2} - {fileID: 11400000, guid: 2a6dd6683bdc4db9b200ccfab1dd4bed, type: 2}
roomMaterial: {fileID: 2100000, guid: 39e2ed014eda5d6408c16fbf0fa80781, type: 2}
genericModule: {fileID: 11400000, guid: cba85a4318ad4750860b84245d9685c4, type: 2}
--- !u!4 &1568048335 --- !u!4 &1568048335
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -1,5 +1,6 @@
{ {
"dependencies": { "dependencies": {
"com.dbrizov.naughtyattributes": "https://github.com/dbrizov/NaughtyAttributes.git#upm",
"com.unity.collab-proxy": "1.17.6", "com.unity.collab-proxy": "1.17.6",
"com.unity.ide.rider": "3.0.16", "com.unity.ide.rider": "3.0.16",
"com.unity.ide.visualstudio": "2.0.16", "com.unity.ide.visualstudio": "2.0.16",

View File

@@ -1,5 +1,12 @@
{ {
"dependencies": { "dependencies": {
"com.dbrizov.naughtyattributes": {
"version": "https://github.com/dbrizov/NaughtyAttributes.git#upm",
"depth": 0,
"source": "git",
"dependencies": {},
"hash": "8a8fa5a9659a6d63f196391c71e06c4286c8acd7"
},
"com.unity.burst": { "com.unity.burst": {
"version": "1.7.3", "version": "1.7.3",
"depth": 1, "depth": 1,