From 36065fd3a55e179c71b5ef1e1f5b276a86255315 Mon Sep 17 00:00:00 2001 From: TerrificTrifid <99054745+TerrificTrifid@users.noreply.github.com> Date: Thu, 19 Dec 2024 22:57:31 -0600 Subject: [PATCH 01/10] fix the heightmap proxy caster guy --- NewHorizons/Builder/Body/HeightMapBuilder.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Builder/Body/HeightMapBuilder.cs b/NewHorizons/Builder/Body/HeightMapBuilder.cs index 55b6f58c..cc6f84b5 100644 --- a/NewHorizons/Builder/Body/HeightMapBuilder.cs +++ b/NewHorizons/Builder/Body/HeightMapBuilder.cs @@ -91,14 +91,14 @@ namespace NewHorizons.Builder.Body level2.name += "1"; LODGroup.RecalculateBounds(); + + var superGroup = planetGO.GetComponent(); + if (superGroup != null) level2.gameObject.AddComponent()._superGroup = superGroup; } var cubeSphereSC = cubeSphere.AddComponent(); cubeSphereSC.radius = Mathf.Min(module.minHeight, module.maxHeight) * Mathf.Min(stretch.x, stretch.y, stretch.z); - var superGroup = planetGO.GetComponent(); - if (superGroup != null) cubeSphere.AddComponent()._superGroup = superGroup; - cubeSphere.SetActive(true); // Now that we've made the mesh we can delete the heightmap texture From da50a411710bd8a94029fa51417eedae86dd46df Mon Sep 17 00:00:00 2001 From: TerrificTrifid <99054745+TerrificTrifid@users.noreply.github.com> Date: Wed, 25 Dec 2024 15:23:08 -0600 Subject: [PATCH 02/10] more asteroid belt options --- .../Builder/Body/AsteroidBeltBuilder.cs | 37 ++++++++++++++----- .../External/Modules/AsteroidBeltModule.cs | 33 +++++++++++++++-- 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs index 01fd7f18..22dbe716 100644 --- a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs +++ b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs @@ -1,6 +1,7 @@ using NewHorizons.External; using NewHorizons.External.Configs; using NewHorizons.External.Modules; +using NewHorizons.External.Modules.Props; using NewHorizons.External.SerializableData; using NewHorizons.Handlers; using NewHorizons.Utility.OWML; @@ -36,7 +37,7 @@ namespace NewHorizons.Builder.Body config.Base = new BaseModule() { - surfaceGravity = 1, + surfaceGravity = belt.gravity, surfaceSize = size, gravityFallOff = GravityFallOff.InverseSquared }; @@ -49,7 +50,8 @@ namespace NewHorizons.Builder.Body trueAnomaly = 360f * (i + Random.Range(-0.2f, 0.2f)) / (float)count, primaryBody = bodyName, semiMajorAxis = Random.Range(belt.innerRadius, belt.outerRadius), - showOrbitLine = false + showOrbitLine = false, + isTidallyLocked = true }; config.ReferenceFrame = new ReferenceFrameModule() @@ -62,8 +64,30 @@ namespace NewHorizons.Builder.Body enabled = false }; - config.ProcGen = belt.procGen; - if (config.ProcGen == null) + if (belt.assetBundle != null || belt.path != null) + { + config.Props = new PropModule() + { + details = new DetailInfo[1] + { + new DetailInfo() + { + assetBundle = belt.assetBundle, + path = belt.path, + scale = size, + rotation = belt.randomOrientation ? Random.rotation.eulerAngles : Vector3.zero, + keepLoaded = true + } + } + }; + + } + else if (belt.procGen != null) + { + config.ProcGen = belt.procGen; + config.ProcGen.scale = size; + } + else { config.ProcGen = new ProcGenModule() { @@ -71,11 +95,6 @@ namespace NewHorizons.Builder.Body color = new MColor(126, 94, 73) }; } - else - { - // Still update the size - config.ProcGen.scale = size; - } var asteroid = new NewHorizonsBody(config, mod); PlanetCreationHandler.GenerateBody(asteroid); diff --git a/NewHorizons/External/Modules/AsteroidBeltModule.cs b/NewHorizons/External/Modules/AsteroidBeltModule.cs index 29588801..5f2f0388 100644 --- a/NewHorizons/External/Modules/AsteroidBeltModule.cs +++ b/NewHorizons/External/Modules/AsteroidBeltModule.cs @@ -1,4 +1,4 @@ -using System.ComponentModel; +using System.ComponentModel; using System.ComponentModel.DataAnnotations; using Newtonsoft.Json; @@ -13,7 +13,7 @@ namespace NewHorizons.External.Modules [Range(-1, 200)] [DefaultValue(-1)] public int amount = -1; /// - /// Angle between the rings and the equatorial plane of the planet. + /// Angle between the belt and the equatorial plane of the planet. /// public float inclination; @@ -23,7 +23,7 @@ namespace NewHorizons.External.Modules [Range(0f, double.MaxValue)] public float innerRadius; /// - /// Angle defining the point where the rings rise up from the planet's equatorial plane if inclination is nonzero. + /// Angle defining the point where the belt rises up from the planet's equatorial plane if inclination is nonzero. /// public float longitudeOfAscendingNode; @@ -45,7 +45,7 @@ namespace NewHorizons.External.Modules [Range(0f, double.MaxValue)] public float outerRadius; /// - /// How the asteroids are generated + /// How the asteroids are generated, unless you supply a detail yourself using "assetBundle" and "path" /// public ProcGenModule procGen; @@ -53,5 +53,30 @@ namespace NewHorizons.External.Modules /// Number used to randomize asteroid positions /// public int randomSeed; + + /// + /// You can use this to load a custom asset or ingame object, instead of using ProcGen. It will be scaled by "minSize" and "maxSize", so ideally it should be near a 1 meter radius. + /// This is a relative filepath to an asset-bundle to load the prefab defined in `path` from. + /// + public string assetBundle; + + /// + /// You can use this to load a custom asset or ingame object, instead of using ProcGen. It will be scaled by "minSize" and "maxSize", so ideally it should be near a 1 meter radius. + /// This is either the path in the scene hierarchy of the item to copy or the path to the object in the supplied asset bundle. + /// + public string path; + + /// + /// Surface gravity of the asteroids. + /// + [Range(0f, double.MaxValue)] + [DefaultValue(1)] + public float gravity = 1f; + + /// + /// Should they be randomly oriented, or all pointing towards the center. + /// + [DefaultValue(true)] + public bool randomOrientation = true; } } \ No newline at end of file From aaeb529eb6ca7aac9509c17f6a19b3f8179b594a Mon Sep 17 00:00:00 2001 From: Ben C Date: Wed, 25 Dec 2024 21:24:59 +0000 Subject: [PATCH 03/10] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index cf035d00..ab06ca7b 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -280,7 +280,7 @@ }, "inclination": { "type": "number", - "description": "Angle between the rings and the equatorial plane of the planet.", + "description": "Angle between the belt and the equatorial plane of the planet.", "format": "float" }, "innerRadius": { @@ -291,7 +291,7 @@ }, "longitudeOfAscendingNode": { "type": "number", - "description": "Angle defining the point where the rings rise up from the planet's equatorial plane if inclination is nonzero.", + "description": "Angle defining the point where the belt rises up from the planet's equatorial plane if inclination is nonzero.", "format": "float" }, "maxSize": { @@ -315,13 +315,33 @@ "minimum": 0.0 }, "procGen": { - "description": "How the asteroids are generated", + "description": "How the asteroids are generated, unless you supply a detail yourself using \"assetBundle\" and \"path\"", "$ref": "#/definitions/ProcGenModule" }, "randomSeed": { "type": "integer", "description": "Number used to randomize asteroid positions", "format": "int32" + }, + "assetBundle": { + "type": "string", + "description": "You can use this to load a custom asset or ingame object, instead of using ProcGen. It will be scaled by \"minSize\" and \"maxSize\", so ideally it should be near a 1 meter radius.\nThis is a relative filepath to an asset-bundle to load the prefab defined in `path` from." + }, + "path": { + "type": "string", + "description": "You can use this to load a custom asset or ingame object, instead of using ProcGen. It will be scaled by \"minSize\" and \"maxSize\", so ideally it should be near a 1 meter radius.\nThis is either the path in the scene hierarchy of the item to copy or the path to the object in the supplied asset bundle. " + }, + "gravity": { + "type": "number", + "description": "Surface gravity of the asteroids.", + "format": "float", + "default": 1, + "minimum": 0.0 + }, + "randomOrientation": { + "type": "boolean", + "description": "Should they be randomly oriented, or all pointing towards the center.", + "default": true } } }, From 664eb0f2dd28c60b3bef3ef135d2d25cece2d5d4 Mon Sep 17 00:00:00 2001 From: TerrificTrifid <99054745+TerrificTrifid@users.noreply.github.com> Date: Sun, 5 Jan 2025 20:26:52 -0600 Subject: [PATCH 04/10] requested changes --- NewHorizons/Builder/Body/AsteroidBeltBuilder.cs | 2 +- NewHorizons/Builder/Body/HeightMapBuilder.cs | 1 + NewHorizons/External/Modules/AsteroidBeltModule.cs | 12 ++++++------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs index 22dbe716..fdc893c7 100644 --- a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs +++ b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs @@ -64,7 +64,7 @@ namespace NewHorizons.Builder.Body enabled = false }; - if (belt.assetBundle != null || belt.path != null) + if (!string.IsNullOrEmpty(belt.assetBundle) || !string.IsNullOrEmpty(belt.path)) { config.Props = new PropModule() { diff --git a/NewHorizons/Builder/Body/HeightMapBuilder.cs b/NewHorizons/Builder/Body/HeightMapBuilder.cs index cc6f84b5..02190def 100644 --- a/NewHorizons/Builder/Body/HeightMapBuilder.cs +++ b/NewHorizons/Builder/Body/HeightMapBuilder.cs @@ -92,6 +92,7 @@ namespace NewHorizons.Builder.Body LODGroup.RecalculateBounds(); + // do this only for LOD because only the main body uses LOD, while title screen and proxies dont var superGroup = planetGO.GetComponent(); if (superGroup != null) level2.gameObject.AddComponent()._superGroup = superGroup; } diff --git a/NewHorizons/External/Modules/AsteroidBeltModule.cs b/NewHorizons/External/Modules/AsteroidBeltModule.cs index 5f2f0388..b6ac9111 100644 --- a/NewHorizons/External/Modules/AsteroidBeltModule.cs +++ b/NewHorizons/External/Modules/AsteroidBeltModule.cs @@ -20,7 +20,7 @@ namespace NewHorizons.External.Modules /// /// Lowest distance from the planet asteroids can spawn /// - [Range(0f, double.MaxValue)] public float innerRadius; + [Range(0f, float.MaxValue)] public float innerRadius; /// /// Angle defining the point where the belt rises up from the planet's equatorial plane if inclination is nonzero. @@ -30,19 +30,19 @@ namespace NewHorizons.External.Modules /// /// Maximum size of the asteroids. /// - [Range(0f, double.MaxValue)] [DefaultValue(50)] + [Range(0f, float.MaxValue)] [DefaultValue(50)] public float maxSize = 50f; /// /// Minimum size of the asteroids. /// - [Range(0f, double.MaxValue)] [DefaultValue(20)] + [Range(0f, float.MaxValue)] [DefaultValue(20)] public float minSize = 20; /// /// Greatest distance from the planet asteroids can spawn /// - [Range(0f, double.MaxValue)] public float outerRadius; + [Range(0f, float.MaxValue)] public float outerRadius; /// /// How the asteroids are generated, unless you supply a detail yourself using "assetBundle" and "path" @@ -69,12 +69,12 @@ namespace NewHorizons.External.Modules /// /// Surface gravity of the asteroids. /// - [Range(0f, double.MaxValue)] + [Range(0f, float.MaxValue)] [DefaultValue(1)] public float gravity = 1f; /// - /// Should they be randomly oriented, or all pointing towards the center. + /// Should the detail of the asteroid be randomly oriented, or should it point towards the center. /// [DefaultValue(true)] public bool randomOrientation = true; From 1e9e3d832cb39b8b5e865385cf7f2759e6b2834b Mon Sep 17 00:00:00 2001 From: xen-42 Date: Sun, 5 Jan 2025 22:15:12 -0500 Subject: [PATCH 05/10] It was double for a reason my bad --- NewHorizons/External/Modules/AsteroidBeltModule.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/NewHorizons/External/Modules/AsteroidBeltModule.cs b/NewHorizons/External/Modules/AsteroidBeltModule.cs index b6ac9111..d042a9fc 100644 --- a/NewHorizons/External/Modules/AsteroidBeltModule.cs +++ b/NewHorizons/External/Modules/AsteroidBeltModule.cs @@ -20,7 +20,7 @@ namespace NewHorizons.External.Modules /// /// Lowest distance from the planet asteroids can spawn /// - [Range(0f, float.MaxValue)] public float innerRadius; + [Range(0f, double.MaxValue)] public float innerRadius; /// /// Angle defining the point where the belt rises up from the planet's equatorial plane if inclination is nonzero. @@ -30,19 +30,19 @@ namespace NewHorizons.External.Modules /// /// Maximum size of the asteroids. /// - [Range(0f, float.MaxValue)] [DefaultValue(50)] + [Range(0f, double.MaxValue)] [DefaultValue(50)] public float maxSize = 50f; /// /// Minimum size of the asteroids. /// - [Range(0f, float.MaxValue)] [DefaultValue(20)] + [Range(0f, double.MaxValue)] [DefaultValue(20)] public float minSize = 20; /// /// Greatest distance from the planet asteroids can spawn /// - [Range(0f, float.MaxValue)] public float outerRadius; + [Range(0f, double.MaxValue)] public float outerRadius; /// /// How the asteroids are generated, unless you supply a detail yourself using "assetBundle" and "path" @@ -69,7 +69,7 @@ namespace NewHorizons.External.Modules /// /// Surface gravity of the asteroids. /// - [Range(0f, float.MaxValue)] + [Range(0f, double.MaxValue)] [DefaultValue(1)] public float gravity = 1f; From 11d58e0632c8407d6ef2e9e5565bb577fd24fdba Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 6 Jan 2025 03:17:02 +0000 Subject: [PATCH 06/10] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index ab06ca7b..ca6c0b29 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -340,7 +340,7 @@ }, "randomOrientation": { "type": "boolean", - "description": "Should they be randomly oriented, or all pointing towards the center.", + "description": "Should the detail of the asteroid be randomly oriented, or should it point towards the center.", "default": true } } From e3f117c8d42bf9046f986697f5aa6da875f6725f Mon Sep 17 00:00:00 2001 From: xen-42 Date: Sun, 5 Jan 2025 23:16:32 -0500 Subject: [PATCH 07/10] Add selectable to map mode, fix an NRE, make auto map gen lines debug --- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 22 +++++++++++++++-- NewHorizons/External/Modules/ShipLogModule.cs | 6 +++++ .../ShipLogAstroObjectPatches.cs | 2 +- .../ShipLogPatches/ShipLogMapModePatches.cs | 24 +++++++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index f556072f..9d66447f 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -21,11 +21,25 @@ namespace NewHorizons.Builder.ShipLog { // Takes the game object because sometimes we change the AO to an NHAO and it breaks private static Dictionary _astroObjectToShipLog = new(); + private static Dictionary _astroObjectToMapModeInfo = new(); + + public static MapModeInfo GetMapModeInfoForAstroObject(ShipLogAstroObject slao) + { + if (_astroObjectToMapModeInfo.TryGetValue(slao, out var mapModeInfo)) + { + return mapModeInfo; + } + else + { + return null; + } + } #region General public static ShipLogAstroObject[][] ConstructMapMode(string systemName, GameObject transformParent, ShipLogAstroObject[][] currentNav, int layer) { _astroObjectToShipLog = new(); + _astroObjectToMapModeInfo = new(); // Add stock planets foreach (var shipLogAstroObject in currentNav.SelectMany(x => x)) @@ -65,7 +79,7 @@ namespace NewHorizons.Builder.ShipLog else { flagManualPositionUsed = true; - if (body.Config.ShipLog?.mapMode?.manualNavigationPosition == null) + if (body.Config.ShipLog?.mapMode != null && body.Config.ShipLog.mapMode.manualNavigationPosition == null && body.Config.ShipLog.mapMode.selectable) { NHLogger.LogError("Navigation position is missing for: " + body.Config.name); return null; @@ -172,6 +186,7 @@ namespace NewHorizons.Builder.ShipLog ShipLogAstroObject astroObject = gameObject.AddComponent(); astroObject._id = ShipLogHandler.GetAstroObjectId(body); _astroObjectToShipLog[body.Object] = astroObject; + _astroObjectToMapModeInfo[astroObject] = body.Config.ShipLog?.mapMode; Texture2D image = null; Texture2D outline = null; @@ -582,7 +597,10 @@ namespace NewHorizons.Builder.ShipLog astroObject._unviewedObj.GetComponent().enabled = false; } node.astroObject = astroObject; - if (node.lastSibling != null) ConnectNodeToLastSibling(node, greyScaleMaterial); + if (NewHorizons.Main.Debug) + { + if (node.lastSibling != null) ConnectNodeToLastSibling(node, greyScaleMaterial); + } MakeDetails(node.mainBody, newNodeGO.transform, greyScaleMaterial); } #endregion diff --git a/NewHorizons/External/Modules/ShipLogModule.cs b/NewHorizons/External/Modules/ShipLogModule.cs index ca4476b7..3b9e5615 100644 --- a/NewHorizons/External/Modules/ShipLogModule.cs +++ b/NewHorizons/External/Modules/ShipLogModule.cs @@ -79,6 +79,12 @@ namespace NewHorizons.External.Modules /// Scale to apply to the planet in map mode. /// [DefaultValue(1f)] public float scale = 1f; + + /// + /// Can this ship log map mode entry be selected + /// Ex) Set to false for stars with no entries on them so they are skipped in navigation + /// + [DefaultValue(true)] public bool selectable = true; } [JsonObject] diff --git a/NewHorizons/Patches/ShipLogPatches/ShipLogAstroObjectPatches.cs b/NewHorizons/Patches/ShipLogPatches/ShipLogAstroObjectPatches.cs index abfc67a8..dd1654bd 100644 --- a/NewHorizons/Patches/ShipLogPatches/ShipLogAstroObjectPatches.cs +++ b/NewHorizons/Patches/ShipLogPatches/ShipLogAstroObjectPatches.cs @@ -31,7 +31,7 @@ namespace NewHorizons.Patches.ShipLogPatches { // Custom astro objects might have no entries, in this case they will be permanently hidden // Just treat it as if it were revealed - if (__instance._entries.Count == 0) + if (__instance._entries == null || __instance._entries.Count == 0) { __instance._state = ShipLogEntry.State.Explored; __instance._imageObj.SetActive(true); diff --git a/NewHorizons/Patches/ShipLogPatches/ShipLogMapModePatches.cs b/NewHorizons/Patches/ShipLogPatches/ShipLogMapModePatches.cs index e6fd50ad..46411832 100644 --- a/NewHorizons/Patches/ShipLogPatches/ShipLogMapModePatches.cs +++ b/NewHorizons/Patches/ShipLogPatches/ShipLogMapModePatches.cs @@ -1,5 +1,6 @@ using HarmonyLib; using NewHorizons.Builder.ShipLog; +using NewHorizons.Components.Orbital; using NewHorizons.Handlers; using NewHorizons.Utility; using NewHorizons.Utility.OWML; @@ -19,6 +20,29 @@ namespace NewHorizons.Patches.ShipLogPatches GameObject panRoot = SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH); GameObject sunObject = SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/Sun"); ShipLogAstroObject[][] navMatrix = MapModeBuilder.ConstructMapMode(Main.Instance.CurrentStarSystem, panRoot, __instance._astroObjects, sunObject.layer); + // Remove anything that isnt meant to be selectable + var flagRemovedUnselectable = false; + for (int i = 0; i < navMatrix.Length; i++) + { + for (int j = 0; j < navMatrix[i].Length; j++) + { + if (!(MapModeBuilder.GetMapModeInfoForAstroObject(navMatrix[i][j])?.selectable ?? true)) + { + flagRemovedUnselectable = true; + navMatrix[i][j].UpdateState(); + navMatrix[i][j] = null; + } + } + } + if (flagRemovedUnselectable) + { + navMatrix = navMatrix.Where(a => a.Count(c => c != null) > 0).ToArray(); + for (var index = 0; index < navMatrix.Length; index++) + { + navMatrix[index] = navMatrix[index].Where(a => a != null).ToArray(); + } + } + if (navMatrix == null || navMatrix.Length <= 1) { NHLogger.LogWarning("Skipping Map Mode Generation."); From 60f4f00bc4d775fc186bdd57c81359b2634850ef Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 6 Jan 2025 04:17:54 +0000 Subject: [PATCH 08/10] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index cf035d00..b542d8e6 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -4067,6 +4067,11 @@ "description": "Scale to apply to the planet in map mode.", "format": "float", "default": 1.0 + }, + "selectable": { + "type": "boolean", + "description": "Can this ship log map mode entry be selected\nEx) Set to false for stars with no entries on them so they are skipped in navigation", + "default": true } } }, From de69e03b9d88aa594b6ec5b0d50c49a649198341 Mon Sep 17 00:00:00 2001 From: xen-42 Date: Sun, 5 Jan 2025 23:19:31 -0500 Subject: [PATCH 09/10] Update manifest.json --- NewHorizons/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index 51597e43..69de585e 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -4,7 +4,7 @@ "author": "xen, Bwc9876, JohnCorby, MegaPiggy, Trifid, and friends", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "1.24.6", + "version": "1.25.0", "owmlVersion": "2.12.1", "dependencies": [ "JohnCorby.VanillaFix", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ], "conflicts": [ "PacificEngine.OW_CommonResources" ], From 9b73dfe80abd09ec6b72efcab9213a172bbad076 Mon Sep 17 00:00:00 2001 From: xen-42 Date: Mon, 6 Jan 2025 00:23:24 -0500 Subject: [PATCH 10/10] Add option to toggle quantum object visualization separate from debug --- NewHorizons/Builder/Props/QuantumBuilder.cs | 68 ++++++++++--------- NewHorizons/Main.cs | 2 + .../Utility/Geometry/BoxShapeVisualizer.cs | 13 ++-- NewHorizons/default-config.json | 6 ++ 4 files changed, 52 insertions(+), 37 deletions(-) diff --git a/NewHorizons/Builder/Props/QuantumBuilder.cs b/NewHorizons/Builder/Props/QuantumBuilder.cs index dff1d3a7..0448eb7d 100644 --- a/NewHorizons/Builder/Props/QuantumBuilder.cs +++ b/NewHorizons/Builder/Props/QuantumBuilder.cs @@ -12,17 +12,17 @@ namespace NewHorizons.Builder.Props { public static class QuantumBuilder { - + public static void Make(GameObject go, Sector sector, PlanetConfig config, IModBehaviour mod, QuantumGroupInfo quantumGroup, GameObject[] propsInGroup) { - switch(quantumGroup.type) + switch (quantumGroup.type) { - case QuantumGroupType.Sockets: MakeSocketGroup (go, sector, config, mod, quantumGroup, propsInGroup); return; - case QuantumGroupType.States: MakeStateGroup (go, sector, config, mod, quantumGroup, propsInGroup); return; - // case PropModule.QuantumGroupType.Shuffle: MakeShuffleGroup(go, sector, config, mod, quantumGroup, propsInGroup); return; + case QuantumGroupType.Sockets: MakeSocketGroup(go, sector, config, mod, quantumGroup, propsInGroup); return; + case QuantumGroupType.States: MakeStateGroup(go, sector, config, mod, quantumGroup, propsInGroup); return; + // case PropModule.QuantumGroupType.Shuffle: MakeShuffleGroup(go, sector, config, mod, quantumGroup, propsInGroup); return; } } - + // TODO: Socket groups that have an equal number of props and sockets // Nice to have: socket groups that specify a filledSocketObject and an emptySocketObject (eg the archway in the giant's deep tower) public static void MakeSocketGroup(GameObject go, Sector sector, PlanetConfig config, IModBehaviour mod, QuantumGroupInfo quantumGroup, GameObject[] propsInGroup) @@ -31,7 +31,7 @@ namespace NewHorizons.Builder.Props groupRoot.transform.parent = sector?.transform ?? go.transform; groupRoot.transform.localPosition = Vector3.zero; groupRoot.transform.localEulerAngles = Vector3.zero; - + var sockets = new QuantumSocket[quantumGroup.sockets.Length]; for (int i = 0; i < quantumGroup.sockets.Length; i++) { @@ -44,7 +44,7 @@ namespace NewHorizons.Builder.Props socket.SetActive(true); } - foreach(var prop in propsInGroup) + foreach (var prop in propsInGroup) { prop.SetActive(false); var quantumObject = prop.AddComponent(); @@ -55,7 +55,7 @@ namespace NewHorizons.Builder.Props quantumObject._childSockets = new List(); // TODO: support _alignWithGravity? if (prop.GetComponentInChildren() == null) AddBoundsVisibility(prop); - prop.SetActive(true); + prop.SetActive(true); } } @@ -72,7 +72,7 @@ namespace NewHorizons.Builder.Props groupRoot.transform.localPosition = Vector3.zero; var states = new List(); - foreach(var prop in propsInGroup) + foreach (var prop in propsInGroup) { prop.transform.parent = groupRoot.transform; var state = prop.AddComponent(); @@ -87,7 +87,7 @@ namespace NewHorizons.Builder.Props if (quantumGroup.hasEmptyState) { var template = propsInGroup[0]; - + var empty = new GameObject("Empty State"); empty.transform.parent = groupRoot.transform; var state = empty.AddComponent(); @@ -97,8 +97,8 @@ namespace NewHorizons.Builder.Props var boxShape = empty.AddComponent(); boxShape.center = boxBounds.center; boxShape.extents = boxBounds.size; - if (Main.Debug) empty.AddComponent(); - + empty.AddComponent(); + empty.AddComponent(); } @@ -121,43 +121,43 @@ namespace NewHorizons.Builder.Props shuffleParent.SetActive(false); shuffleParent.transform.parent = sector?.transform ?? go.transform; shuffleParent.transform.localPosition = Vector3.zero; - propsInGroup.ToList().ForEach(p => p.transform.parent = shuffleParent.transform); + propsInGroup.ToList().ForEach(p => p.transform.parent = shuffleParent.transform); var shuffle = shuffleParent.AddComponent(); shuffle._shuffledObjects = propsInGroup.Select(p => p.transform).ToArray(); shuffle.Awake(); // this doesn't get called on its own for some reason. what? how? - + AddBoundsVisibility(shuffleParent); shuffleParent.SetActive(true); } - + struct BoxShapeReciever { public MeshFilter f; public SkinnedMeshRenderer s; - public GameObject g; + public GameObject gameObject; } public static void AddBoundsVisibility(GameObject g) { var meshFilters = g.GetComponentsInChildren(); var skinnedMeshRenderers = g.GetComponentsInChildren(); - + var boxShapeRecievers = meshFilters - .Select(f => new BoxShapeReciever() { f=f, g=f.gameObject }) - .Concat ( - skinnedMeshRenderers.Select(s => new BoxShapeReciever() { s=s, g=s.gameObject }) + .Select(f => new BoxShapeReciever() { f = f, gameObject = f.gameObject }) + .Concat( + skinnedMeshRenderers.Select(s => new BoxShapeReciever() { s = s, gameObject = s.gameObject }) ) .ToList(); - foreach(var boxshapeReciever in boxShapeRecievers) + foreach (var boxshapeReciever in boxShapeRecievers) { - var box = boxshapeReciever.g.AddComponent(); - boxshapeReciever.g.AddComponent(); - if (Main.Debug) boxshapeReciever.g.AddComponent(); + var box = boxshapeReciever.gameObject.AddComponent(); + boxshapeReciever.gameObject.AddComponent(); + boxshapeReciever.gameObject.AddComponent(); - var fixer = boxshapeReciever.g.AddComponent(); + var fixer = boxshapeReciever.gameObject.AddComponent(); fixer.shape = box; fixer.meshFilter = boxshapeReciever.f; fixer.skinnedMeshRenderer = boxshapeReciever.s; @@ -169,7 +169,7 @@ namespace NewHorizons.Builder.Props { var meshFilters = g.GetComponentsInChildren(); var corners = meshFilters.SelectMany(m => GetMeshCorners(m, g)).ToList(); - + Bounds b = new Bounds(corners[0], Vector3.zero); corners.ForEach(corner => b.Encapsulate(corner)); @@ -191,9 +191,9 @@ namespace NewHorizons.Builder.Props new Vector3(bounds.max.x, bounds.min.y, bounds.max.z), new Vector3(bounds.max.x, bounds.max.y, bounds.min.z), }; - + var globalCorners = localCorners.Select(localCorner => m.transform.TransformPoint(localCorner)).ToArray(); - + if (relativeTo == null) return globalCorners; return globalCorners.Select(globalCorner => relativeTo.transform.InverseTransformPoint(globalCorner)).ToArray(); @@ -213,9 +213,13 @@ namespace NewHorizons.Builder.Props public MeshFilter meshFilter; public SkinnedMeshRenderer skinnedMeshRenderer; - void Update() + public void Update() { - if (meshFilter == null && skinnedMeshRenderer == null) { NHLogger.LogVerbose("Useless BoxShapeFixer, destroying"); DestroyImmediate(this); } + if (meshFilter == null && skinnedMeshRenderer == null) + { + NHLogger.LogVerbose("Useless BoxShapeFixer, destroying"); + DestroyImmediate(this); + } Mesh sharedMesh = null; if (meshFilter != null) sharedMesh = meshFilter.sharedMesh; @@ -223,7 +227,7 @@ namespace NewHorizons.Builder.Props if (sharedMesh == null) return; if (sharedMesh.bounds.size == Vector3.zero) return; - + shape.size = sharedMesh.bounds.size; shape.center = sharedMesh.bounds.center; diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 97b861ab..20123633 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -47,6 +47,7 @@ namespace NewHorizons // Settings public static bool Debug { get; private set; } + public static bool VisualizeQuantumObjects { get; private set; } public static bool VerboseLogs { get; private set; } public static bool SequentialPreCaching { get; private set; } public static bool CustomTitleScreen { get; private set; } @@ -134,6 +135,7 @@ namespace NewHorizons var currentScene = SceneManager.GetActiveScene().name; Debug = config.GetSettingsValue(nameof(Debug)); + VisualizeQuantumObjects = config.GetSettingsValue(nameof(VisualizeQuantumObjects)); VerboseLogs = config.GetSettingsValue(nameof(VerboseLogs)); SequentialPreCaching = config.GetSettingsValue(nameof(SequentialPreCaching)); diff --git a/NewHorizons/Utility/Geometry/BoxShapeVisualizer.cs b/NewHorizons/Utility/Geometry/BoxShapeVisualizer.cs index 77dbf6cf..039e7bdc 100644 --- a/NewHorizons/Utility/Geometry/BoxShapeVisualizer.cs +++ b/NewHorizons/Utility/Geometry/BoxShapeVisualizer.cs @@ -4,16 +4,19 @@ namespace NewHorizons.Utility.Geometry { public class BoxShapeVisualizer : MonoBehaviour { - BoxShape box; + private BoxShape _box; - void Awake() + public void Awake() { - box = GetComponent(); + _box = GetComponent(); } - void OnRenderObject() + public void OnRenderObject() { - Popcron.Gizmos.Cube(transform.TransformPoint(box.center), transform.rotation, Vector3.Scale(box.size, transform.lossyScale)); + if (Main.Debug && Main.VisualizeQuantumObjects) + { + Popcron.Gizmos.Cube(transform.TransformPoint(_box.center), transform.rotation, Vector3.Scale(_box.size, transform.lossyScale)); + } } } } diff --git a/NewHorizons/default-config.json b/NewHorizons/default-config.json index e4b87a61..4f3239c2 100644 --- a/NewHorizons/default-config.json +++ b/NewHorizons/default-config.json @@ -16,6 +16,12 @@ "value": false, "tooltip": "Enables the debug raycast, visible quantum object colliders, and debug options menu." }, + "VisualizeQuantumObjects": { + "title": "Visualize Quantum Objects", + "type": "toggle", + "value": false, + "tooltip": "Draws boundaries around quantum objects when Debug mode is on." + }, "VerboseLogs": { "title": "Verbose Logs", "type": "toggle",