From 6951a40e58d93e0e607459382e0731adf4d2c77c Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 1 Jun 2024 22:58:43 -0400 Subject: [PATCH 1/2] Add map marker display distance overrides and make a map marker module --- .../Builder/Body/AsteroidBeltBuilder.cs | 6 ++++- .../Builder/General/AstroObjectBuilder.cs | 2 +- NewHorizons/Builder/General/MarkerBuilder.cs | 9 +++++-- NewHorizons/Components/NHMapMarker.cs | 27 +++++++++++++++++++ NewHorizons/External/Configs/PlanetConfig.cs | 8 ++++++ NewHorizons/External/Modules/BaseModule.cs | 8 +++--- .../External/Modules/MapMarkerModule.cs | 25 +++++++++++++++++ NewHorizons/Handlers/PlanetCreationHandler.cs | 4 +-- 8 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 NewHorizons/Components/NHMapMarker.cs create mode 100644 NewHorizons/External/Modules/MapMarkerModule.cs diff --git a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs index 8568f61b9..01fd7f188 100644 --- a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs +++ b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs @@ -36,7 +36,6 @@ public static void Make(string bodyName, PlanetConfig parentConfig, IModBehaviou config.Base = new BaseModule() { - hasMapMarker = false, surfaceGravity = 1, surfaceSize = size, gravityFallOff = GravityFallOff.InverseSquared @@ -58,6 +57,11 @@ public static void Make(string bodyName, PlanetConfig parentConfig, IModBehaviou enabled = false }; + config.MapMarker = new MapMarkerModule() + { + enabled = false + }; + config.ProcGen = belt.procGen; if (config.ProcGen == null) { diff --git a/NewHorizons/Builder/General/AstroObjectBuilder.cs b/NewHorizons/Builder/General/AstroObjectBuilder.cs index a2fc14106..21be35362 100644 --- a/NewHorizons/Builder/General/AstroObjectBuilder.cs +++ b/NewHorizons/Builder/General/AstroObjectBuilder.cs @@ -16,7 +16,7 @@ public static NHAstroObject Make(GameObject body, AstroObject primaryBody, NewHo var config = nhBody.Config; astroObject.isVanilla = isVanilla; - astroObject.HideDisplayName = !config.Base.hasMapMarker; + astroObject.HideDisplayName = !config.MapMarker.enabled; astroObject.invulnerableToSun = config.Base.invulnerableToSun; if (config.Orbit != null) astroObject.SetOrbitalParametersFromConfig(config.Orbit); diff --git a/NewHorizons/Builder/General/MarkerBuilder.cs b/NewHorizons/Builder/General/MarkerBuilder.cs index bcb945a91..ad17b1911 100644 --- a/NewHorizons/Builder/General/MarkerBuilder.cs +++ b/NewHorizons/Builder/General/MarkerBuilder.cs @@ -1,5 +1,6 @@ -#region +#region +using NewHorizons.Components; using NewHorizons.External.Configs; using NewHorizons.Handlers; using UnityEngine; @@ -12,7 +13,8 @@ static class MarkerBuilder { public static void Make(GameObject body, string name, PlanetConfig config) { - MapMarker mapMarker = body.AddComponent(); + var module = config.MapMarker; + NHMapMarker mapMarker = body.AddComponent(); mapMarker._labelID = (UITextType)TranslationHandler.AddUI(config.name); var markerType = MapMarker.MarkerType.Planet; @@ -37,6 +39,9 @@ public static void Make(GameObject body, string name, PlanetConfig config) */ mapMarker._markerType = markerType; + + mapMarker.minDisplayDistanceOverride = module.minDisplayDistanceOverride; + mapMarker.maxDisplayDistanceOverride = module.maxDisplayDistanceOverride; } } } diff --git a/NewHorizons/Components/NHMapMarker.cs b/NewHorizons/Components/NHMapMarker.cs new file mode 100644 index 000000000..501f18e7b --- /dev/null +++ b/NewHorizons/Components/NHMapMarker.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.Components +{ + public class NHMapMarker : MapMarker + { + public float minDisplayDistanceOverride = -1; + public float maxDisplayDistanceOverride = -1; + + public new void Awake() + { + base.Awake(); + if (minDisplayDistanceOverride >= 0) + { + _minDisplayDistance = minDisplayDistanceOverride; + } + if (maxDisplayDistanceOverride >= 0) + { + _maxDisplayDistance = maxDisplayDistanceOverride; + } + } + } +} diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index f29c511af..28f003181 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -113,6 +113,11 @@ public class PlanetConfig /// public LavaModule Lava; + /// + /// Map marker properties of this body + /// + public MapMarkerModule MapMarker; + /// /// Describes this Body's orbit (or lack there of) /// @@ -214,6 +219,7 @@ public PlanetConfig() if (Base == null) Base = new BaseModule(); if (Orbit == null) Orbit = new OrbitModule(); if (ReferenceFrame == null) ReferenceFrame = new ReferenceFrameModule(); + if (MapMarker == null) MapMarker = new MapMarkerModule(); } public void Validate() @@ -307,6 +313,8 @@ public void Migrate() if (!Base.hasReferenceFrame) ReferenceFrame.enabled = false; + if (Base.hasMapMarker) MapMarker.enabled = true; + if (childrenToDestroy != null) removeChildren = childrenToDestroy; if (Base.cloakRadius != 0) diff --git a/NewHorizons/External/Modules/BaseModule.cs b/NewHorizons/External/Modules/BaseModule.cs index 1e1c28d12..78a41fee2 100644 --- a/NewHorizons/External/Modules/BaseModule.cs +++ b/NewHorizons/External/Modules/BaseModule.cs @@ -36,11 +36,6 @@ public class BaseModule /// public float groundSize; - /// - /// If the body should have a marker on the map screen. - /// - public bool hasMapMarker; - /// /// Can this planet survive entering a star? /// @@ -108,6 +103,9 @@ public class BaseModule [Obsolete("AmbientLight is deprecated, please use AmbientLightModule instead")] public float ambientLight; + [Obsolete("HasMapMarker is deprecated, please use MapMarkerModule instead")] + public bool hasMapMarker; + [Obsolete("HasReferenceFrame is deprecated, please use ReferenceModule instead")] [DefaultValue(true)] public bool hasReferenceFrame = true; diff --git a/NewHorizons/External/Modules/MapMarkerModule.cs b/NewHorizons/External/Modules/MapMarkerModule.cs new file mode 100644 index 000000000..a1f91aad1 --- /dev/null +++ b/NewHorizons/External/Modules/MapMarkerModule.cs @@ -0,0 +1,25 @@ +using System.ComponentModel; +using NewHorizons.External.SerializableData; +using Newtonsoft.Json; + +namespace NewHorizons.External.Modules +{ + [JsonObject] + public class MapMarkerModule + { + /// + /// If the body should have a marker on the map screen. + /// + public bool enabled; + + /// + /// Lowest distance away from the body that the marker can be shown. This is automatically set to 0 for all bodies except focal points where it is 5,000. + /// + public float minDisplayDistanceOverride = -1; + + /// + /// Highest distance away from the body that the marker can be shown. For planets and focal points the automatic value is 50,000. Moons and planets in focal points are 5,000. Stars are 1E+10 (10,000,000,000). + /// + public float maxDisplayDistanceOverride = -1; + } +} \ No newline at end of file diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 75edb30a9..bd0a7dca7 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -366,7 +366,7 @@ public static GameObject GenerateBrambleDimensionBody(NewHorizonsBody body) go.SetActive(false); body.Config.Base.showMinimap = false; - body.Config.Base.hasMapMarker = false; + body.Config.MapMarker.enabled = false; const float sphereOfInfluence = 2000f; @@ -459,7 +459,7 @@ public static GameObject GenerateStandardBody(NewHorizonsBody body, bool default RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence, body.Config.ReferenceFrame); - if (body.Config.Base.hasMapMarker) + if (body.Config.MapMarker.enabled) { MarkerBuilder.Make(go, body.Config.name, body.Config); } From 2e7f1b750835205980dd8ca959b3519d9ae7415f Mon Sep 17 00:00:00 2001 From: Ben C Date: Sun, 2 Jun 2024 03:02:27 +0000 Subject: [PATCH 2/2] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 3e9321e86..3de0f3cc5 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -85,6 +85,10 @@ "description": "Add lava to this planet", "$ref": "#/definitions/LavaModule" }, + "MapMarker": { + "description": "Map marker properties of this body", + "$ref": "#/definitions/MapMarkerModule" + }, "Orbit": { "description": "Describes this Body's orbit (or lack there of)", "$ref": "#/definitions/OrbitModule" @@ -543,10 +547,6 @@ "description": "Radius of a simple sphere used as the ground for the planet. If you want to use more complex terrain, leave this as\n0.", "format": "float" }, - "hasMapMarker": { - "type": "boolean", - "description": "If the body should have a marker on the map screen." - }, "invulnerableToSun": { "type": "boolean", "description": "Can this planet survive entering a star?" @@ -1022,6 +1022,26 @@ } } }, + "MapMarkerModule": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { + "type": "boolean", + "description": "If the body should have a marker on the map screen." + }, + "minDisplayDistanceOverride": { + "type": "number", + "description": "Lowest distance away from the body that the marker can be shown. This is automatically set to 0 for all bodies except focal points where it is 5,000.", + "format": "float" + }, + "maxDisplayDistanceOverride": { + "type": "number", + "description": "Highest distance away from the body that the marker can be shown. For planets and focal points the automatic value is 50,000. Moons and planets in focal points are 5,000. Stars are 1E+10 (10,000,000,000).", + "format": "float" + } + } + }, "OrbitModule": { "type": "object", "additionalProperties": false,