orient entrance to reflect previous exit orientation

This commit is contained in:
2022-11-07 16:22:00 +01:00
parent 1a1e7f87a0
commit 9e748a0f38
4 changed files with 19 additions and 19 deletions

View File

@@ -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<PlacementRequirement>().ForEach(requirement =>
puzzle.description.RequirementsOfType<PlacementRequirement>().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<OrientationRequirement>().ForEach(requirement =>
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());
puzzle.orientation = orientationCandidates.RandomElement();
}
else
{

View File

@@ -30,25 +30,26 @@ namespace Escape_Room_Engine.Engine.Scripts.Modules
/// </summary>
internal Vector2Int RrPosition => _space.ToRoomRelative(SrPosition);
internal readonly ModuleDescription _description;
protected GameObject _moduleObject;
internal readonly ModuleDescription description;
internal Orientation orientation;
/// <summary>
/// The space relative (<i>SR</i>) dimensions of this module.
/// </summary>
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);
}
/// <summary>
@@ -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()))})";
}
}
}

View File

@@ -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);
}

View File

@@ -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);
}