From 624f5ae6c6c45c91ec6d0602539254bcd90e82de Mon Sep 17 00:00:00 2001 From: milan Date: Thu, 10 Nov 2022 20:38:32 +0100 Subject: [PATCH] split engine configuration from engine --- .../Engine/Engine Configuration.asset | 23 ++++++++++++ .../Engine/Engine Configuration.asset.meta | 8 +++++ .../Engine/Scripts/Engine.cs | 34 ++++-------------- .../Engine/Scripts/EngineConfiguration.cs | 35 +++++++++++++++++++ .../Scripts/EngineConfiguration.cs.meta | 3 ++ .../Engine/Scripts/Space.cs | 5 ++- Assets/Scenes/TestScene.unity | 10 +----- 7 files changed, 80 insertions(+), 38 deletions(-) create mode 100644 Assets/Escape Room Engine/Engine/Engine Configuration.asset create mode 100644 Assets/Escape Room Engine/Engine/Engine Configuration.asset.meta create mode 100644 Assets/Escape Room Engine/Engine/Scripts/EngineConfiguration.cs create mode 100644 Assets/Escape Room Engine/Engine/Scripts/EngineConfiguration.cs.meta diff --git a/Assets/Escape Room Engine/Engine/Engine Configuration.asset b/Assets/Escape Room Engine/Engine/Engine Configuration.asset new file mode 100644 index 0000000..d60a208 --- /dev/null +++ b/Assets/Escape Room Engine/Engine/Engine Configuration.asset @@ -0,0 +1,23 @@ +%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: 28d04249c1c4438da94b524e7d4afff2, type: 3} + m_Name: Engine Configuration + m_EditorClassIdentifier: + minRoomSize: {x: 3, y: 3} + playSpace: {x: 4, y: 6} + spawnDoor: {fileID: 11400000, guid: 6e937b2e9f774999b5962c4b40947165, type: 2} + exitDoorTypes: + - {fileID: 11400000, guid: 29e2ae36585f4e65966bc9ea2f95ac4a, type: 2} + puzzleCount: {x: 2, y: 5} + puzzleTypes: + - {fileID: 11400000, guid: 2a6dd6683bdc4db9b200ccfab1dd4bed, type: 2} + genericModule: {fileID: 11400000, guid: cba85a4318ad4750860b84245d9685c4, type: 2} diff --git a/Assets/Escape Room Engine/Engine/Engine Configuration.asset.meta b/Assets/Escape Room Engine/Engine/Engine Configuration.asset.meta new file mode 100644 index 0000000..ca6728e --- /dev/null +++ b/Assets/Escape Room Engine/Engine/Engine Configuration.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 568d9a7d70f3edb4cb6db66a0010f105 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Escape Room Engine/Engine/Scripts/Engine.cs b/Assets/Escape Room Engine/Engine/Scripts/Engine.cs index cb822c4..afd0d59 100644 --- a/Assets/Escape Room Engine/Engine/Scripts/Engine.cs +++ b/Assets/Escape Room Engine/Engine/Scripts/Engine.cs @@ -24,31 +24,9 @@ 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 exitDoorTypes; - - [BoxGroup("Puzzles")] - [MinMaxSlider(0, 10)] public Vector2Int puzzleCount; - - [BoxGroup("Puzzles")] - public List puzzleTypes; + [Required] public EngineConfiguration config; public Material roomMaterial; - public ModuleDescription genericModule; private int NumberOfRooms => _rooms.Count; @@ -59,7 +37,7 @@ namespace Escape_Room_Engine.Engine.Scripts { _playSpaceOrigin = new GameObject("Play Space Origin"); _playSpaceOrigin.transform.SetParent(transform); - _playSpaceOrigin.transform.localPosition = new Vector3(-playSpace.x / 2f, 0, -playSpace.y / 2f); + _playSpaceOrigin.transform.localPosition = new Vector3(-config.playSpace.x / 2f, 0, -config.playSpace.y / 2f); } public void GenerateRoom() @@ -67,7 +45,7 @@ namespace Escape_Room_Engine.Engine.Scripts Logger.Log("Generating room...", LogType.RoomGeneration); // get the last entrance from the newest room or create a spawn passage with no entrance door for where the player will start - var entrance = NumberOfRooms > 0 ? _rooms.Last().exit : new Passage(new DoorModule(null, spawnDoor), true); + var entrance = NumberOfRooms > 0 ? _rooms.Last().exit : new Passage(new DoorModule(null, config.spawnDoor), true); var room = new Room(entrance); _rooms.Add(room); @@ -85,15 +63,15 @@ namespace Escape_Room_Engine.Engine.Scripts var space = new Space(entrance); // add exit - var exitDoor = new DoorModule(space, exitDoorTypes.RandomElement()); + var exitDoor = new DoorModule(space, config.exitDoorTypes.RandomElement()); if (!space.AddModuleWithRequirements(exitDoor)) throw new Exception("Could not satisfy requirements for exit door."); var exit = new Passage(exitDoor); // add puzzles - for (var i = 0; i < Utilities.Utilities.RandomInclusive(puzzleCount.x, puzzleCount.y); i++) + for (var i = 0; i < Utilities.Utilities.RandomInclusive(config.puzzleCount.x, config.puzzleCount.y); i++) { - space.AddModuleWithRequirements(new PuzzleModule(space, puzzleTypes.RandomElement())); + space.AddModuleWithRequirements(new PuzzleModule(space, config.puzzleTypes.RandomElement())); } room.AddSpace(space, exit); diff --git a/Assets/Escape Room Engine/Engine/Scripts/EngineConfiguration.cs b/Assets/Escape Room Engine/Engine/Scripts/EngineConfiguration.cs new file mode 100644 index 0000000..8ac70e0 --- /dev/null +++ b/Assets/Escape Room Engine/Engine/Scripts/EngineConfiguration.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using Escape_Room_Engine.Engine.Scripts.Modules; +using NaughtyAttributes; +using UnityEngine; + +namespace Escape_Room_Engine.Engine.Scripts +{ + [CreateAssetMenu(menuName = "Engine Config")] + public class EngineConfiguration : ScriptableObject + { + [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 exitDoorTypes; + + [BoxGroup("Puzzles")] + [MinMaxSlider(0, 10)] public Vector2Int puzzleCount; + + [BoxGroup("Puzzles")] + public List puzzleTypes; + + public ModuleDescription genericModule; + } +} \ No newline at end of file diff --git a/Assets/Escape Room Engine/Engine/Scripts/EngineConfiguration.cs.meta b/Assets/Escape Room Engine/Engine/Scripts/EngineConfiguration.cs.meta new file mode 100644 index 0000000..4f29140 --- /dev/null +++ b/Assets/Escape Room Engine/Engine/Scripts/EngineConfiguration.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 28d04249c1c4438da94b524e7d4afff2 +timeCreated: 1668108442 \ No newline at end of file diff --git a/Assets/Escape Room Engine/Engine/Scripts/Space.cs b/Assets/Escape Room Engine/Engine/Scripts/Space.cs index d43f710..2720ee4 100644 --- a/Assets/Escape Room Engine/Engine/Scripts/Space.cs +++ b/Assets/Escape Room Engine/Engine/Scripts/Space.cs @@ -20,7 +20,10 @@ namespace Escape_Room_Engine.Engine.Scripts internal Space(Passage entrance) { - rrDimensions = GenerateSpaceDimensions(entrance, Engine.DefaultEngine.minRoomSize, Engine.DefaultEngine.playSpace); + rrDimensions = GenerateSpaceDimensions( + entrance, + Engine.DefaultEngine.config.minRoomSize, + Engine.DefaultEngine.config.playSpace); // connect the space to its passage entrance.ConnectTo(new DoorModule(this, diff --git a/Assets/Scenes/TestScene.unity b/Assets/Scenes/TestScene.unity index 6eb39a8..dd780af 100644 --- a/Assets/Scenes/TestScene.unity +++ b/Assets/Scenes/TestScene.unity @@ -1232,16 +1232,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 9a9b6b8b557abbb4ab172444615ebf23, type: 3} m_Name: m_EditorClassIdentifier: - minRoomSize: {x: 3, y: 3} - playSpace: {x: 4, y: 6} - spawnDoor: {fileID: 11400000, guid: 6e937b2e9f774999b5962c4b40947165, type: 2} - exitDoorTypes: - - {fileID: 11400000, guid: 29e2ae36585f4e65966bc9ea2f95ac4a, type: 2} - puzzleCount: {x: 2, y: 5} - puzzleTypes: - - {fileID: 11400000, guid: 2a6dd6683bdc4db9b200ccfab1dd4bed, type: 2} + config: {fileID: 11400000, guid: 568d9a7d70f3edb4cb6db66a0010f105, type: 2} roomMaterial: {fileID: 2100000, guid: 39e2ed014eda5d6408c16fbf0fa80781, type: 2} - genericModule: {fileID: 11400000, guid: cba85a4318ad4750860b84245d9685c4, type: 2} --- !u!4 &1568048335 Transform: m_ObjectHideFlags: 0