From 9e748a0f388b595d4011e3adfed01106fee0a6c2 Mon Sep 17 00:00:00 2001 From: milan Date: Mon, 7 Nov 2022 16:22:00 +0100 Subject: [PATCH] orient entrance to reflect previous exit orientation --- .../Engine/Scripts/Engine.cs | 8 +++--- .../Engine/Scripts/Modules/Module.cs | 25 +++++++++---------- .../Engine/Scripts/Passage.cs | 3 ++- .../Engine/Scripts/Space.cs | 2 +- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Assets/Escape Room Engine/Engine/Scripts/Engine.cs b/Assets/Escape Room Engine/Engine/Scripts/Engine.cs index 0b1699b..03b0ac6 100644 --- a/Assets/Escape Room Engine/Engine/Scripts/Engine.cs +++ b/Assets/Escape Room Engine/Engine/Scripts/Engine.cs @@ -77,6 +77,7 @@ namespace Escape_Room_Engine.Engine.Scripts Random.Range(0, rrDimensions.width), Random.Range(0, rrDimensions.length) )); + exitDoor.orientation = Module.EveryOrientation.RandomElement(); var exit = new Passage(exitDoor); space.AddModule(exitDoor); @@ -95,7 +96,7 @@ namespace Escape_Room_Engine.Engine.Scripts // place puzzle var placementCandidates = space.rrDimensions.EveryPosition; - puzzle._description.RequirementsOfType().ForEach(requirement => + puzzle.description.RequirementsOfType().ForEach(requirement => placementCandidates.IntersectWith(requirement.PlacementCandidates(puzzle, space))); Logger.Log($"placement candidates: {string.Join(", ", placementCandidates.ToList().ConvertAll(c => c.ToString()))}", LogType.RequirementResolution); @@ -112,15 +113,14 @@ namespace Escape_Room_Engine.Engine.Scripts // orient puzzle var orientationCandidates = Module.EveryOrientation; - Logger.Log($"orientation candidatesA: {string.Join(",", orientationCandidates.ToList().ConvertAll(c => c.ToString()))}", LogType.RequirementResolution); - puzzle._description.RequirementsOfType().ForEach(requirement => + puzzle.description.RequirementsOfType().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()); + puzzle.orientation = orientationCandidates.RandomElement(); } else { diff --git a/Assets/Escape Room Engine/Engine/Scripts/Modules/Module.cs b/Assets/Escape Room Engine/Engine/Scripts/Modules/Module.cs index 1977597..a09ec17 100644 --- a/Assets/Escape Room Engine/Engine/Scripts/Modules/Module.cs +++ b/Assets/Escape Room Engine/Engine/Scripts/Modules/Module.cs @@ -30,25 +30,26 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules /// internal Vector2Int RrPosition => _space.ToRoomRelative(SrPosition); - internal readonly ModuleDescription _description; - protected GameObject _moduleObject; + internal readonly ModuleDescription description; + internal Orientation orientation; + /// /// The space relative (SR) dimensions of this module. /// protected Dimensions srDimensions; - protected Orientation orientation; + private GameObject _moduleObject, _orientationObject; private readonly Space _space; internal Module(Space space, ModuleDescription description) { _space = space; - _description = description; + this.description = description; } internal bool IsType(ModuleType type) { - return _description.types.Contains(type); + return description.types.Contains(type); } /// @@ -73,24 +74,22 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules Logger.Log($"{this} has been placed at {srPosition} (SR)", LogType.ModulePlacement); } - internal void Orient(Orientation o) - { - orientation = o; - } - internal void InstantiateModule(Transform parent) { _moduleObject = new GameObject(ToString()); _moduleObject.transform.SetParent(parent, false); _moduleObject.transform.localPosition = new Vector3(srDimensions.x + .5f, 0, srDimensions.z + .5f); - _moduleObject.transform.Rotate(Vector3.up, (float)orientation); - Object.Instantiate(_description.modulePrefab, _moduleObject.transform, false); + _orientationObject = new GameObject("Orientation"); + _orientationObject.transform.SetParent(_moduleObject.transform, false); + _orientationObject.transform.Rotate(Vector3.up, (float)orientation); + + Object.Instantiate(description.modulePrefab, _orientationObject.transform, false); } 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()))})"; } } } diff --git a/Assets/Escape Room Engine/Engine/Scripts/Passage.cs b/Assets/Escape Room Engine/Engine/Scripts/Passage.cs index 5f70b3c..bbb02a6 100644 --- a/Assets/Escape Room Engine/Engine/Scripts/Passage.cs +++ b/Assets/Escape Room Engine/Engine/Scripts/Passage.cs @@ -38,8 +38,9 @@ namespace Escape_Room_Engine.Engine.Scripts { toIn = door; - // to make sure the origin of the player doesn't move, the two doors must be placed in the same location + // to make sure the origin of the player doesn't move, the two doors must be placed in the same location in the same orientation toIn.PlaceRoomRelative(rrPosition); + toIn.orientation = fromOut.orientation; Logger.Log($"Connected passage to {door} at {rrPosition} (RR)", LogType.PassageConnection); } diff --git a/Assets/Escape Room Engine/Engine/Scripts/Space.cs b/Assets/Escape Room Engine/Engine/Scripts/Space.cs index 1dd2be1..d17d78c 100644 --- a/Assets/Escape Room Engine/Engine/Scripts/Space.cs +++ b/Assets/Escape Room Engine/Engine/Scripts/Space.cs @@ -20,7 +20,7 @@ namespace Escape_Room_Engine.Engine.Scripts // connect the space to its passage entrance.ConnectTo(new DoorModule(this, - ((DoorModuleDescription)entrance.fromOut._description).connectedDoorDescription)); + ((DoorModuleDescription)entrance.fromOut.description).connectedDoorDescription)); AddModule(entrance.toIn); }