make sure every module is accessible
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Escape_Room_Engine.Engine.Scripts.Modules;
|
||||
using Escape_Room_Engine.Engine.Scripts.Utilities;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
using Logger = Escape_Room_Engine.Engine.Scripts.Utilities.Logger;
|
||||
using LogType = Escape_Room_Engine.Engine.Scripts.Utilities.LogType;
|
||||
@@ -23,16 +24,31 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
}
|
||||
}
|
||||
private static Engine _foundEngine;
|
||||
|
||||
[BoxGroup("Size")]
|
||||
[Tooltip("The minimum size that should be allowed for rooms.")]
|
||||
public Vector2Int minRoomSize;
|
||||
|
||||
[BoxGroup("Size")]
|
||||
[Tooltip("The size of the physical play space available to the engine.")]
|
||||
public Vector2Int playSpace;
|
||||
|
||||
[BoxGroup("Doors")]
|
||||
[Required]
|
||||
public DoorModuleDescription spawnDoor;
|
||||
|
||||
[BoxGroup("Doors")]
|
||||
[ValidateInput("IsNotEmpty", "At least one exit door type is required")]
|
||||
public List<DoorModuleDescription> exitDoorTypes;
|
||||
|
||||
[BoxGroup("Puzzles")]
|
||||
[MinMaxSlider(0, 10)] public Vector2Int puzzleCount;
|
||||
|
||||
[BoxGroup("Puzzles")]
|
||||
public List<PuzzleModuleDescription> puzzleTypes;
|
||||
|
||||
public Material roomMaterial;
|
||||
|
||||
[Range(0, 10)] public int minPuzzleCount, maxPuzzleCount;
|
||||
[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.")] public Vector2Int playSpace;
|
||||
public ModuleDescription genericModule;
|
||||
public DoorModuleDescription spawnDoor;
|
||||
public List<DoorModuleDescription> exitDoorTypes;
|
||||
public List<PuzzleModuleDescription> puzzleTypes;
|
||||
|
||||
private int NumberOfRooms => _rooms.Count;
|
||||
|
||||
@@ -75,7 +91,7 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
var exit = new Passage(exitDoor);
|
||||
|
||||
// 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()));
|
||||
}
|
||||
@@ -90,5 +106,9 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
_rooms[NumberOfRooms - 1].roomObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once SuggestBaseTypeForParameter
|
||||
// ReSharper disable once UnusedMember.Local
|
||||
private bool IsNotEmpty(List<DoorModuleDescription> modules) => modules.Count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,24 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
|
||||
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)
|
||||
{
|
||||
_moduleObject = new GameObject(ToString());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Escape_Room_Engine.Engine.Scripts.Modules;
|
||||
using NaughtyAttributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Escape_Room_Engine.Engine.Scripts.Requirements
|
||||
@@ -7,13 +8,24 @@ namespace Escape_Room_Engine.Engine.Scripts.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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,13 +35,16 @@ namespace Escape_Room_Engine.Engine.Scripts
|
||||
|
||||
internal bool AddModuleWithRequirements(Module module)
|
||||
{
|
||||
var result =
|
||||
var requirementsFulfilled =
|
||||
PlacementRequirement.TryPlacing(module, this) &&
|
||||
OrientationRequirement.TryOrienting(module, this);
|
||||
|
||||
AddModule(module);
|
||||
|
||||
return result;
|
||||
|
||||
if (requirementsFulfilled)
|
||||
{
|
||||
AddModule(module);
|
||||
}
|
||||
|
||||
return requirementsFulfilled;
|
||||
}
|
||||
|
||||
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.
|
||||
/// </summary>
|
||||
/// <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;
|
||||
/// <summary>
|
||||
/// Convert a position relative to the room to one relative to this space.
|
||||
/// </summary>
|
||||
/// <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;
|
||||
|
||||
private Mesh GenerateMesh()
|
||||
|
||||
Reference in New Issue
Block a user