From 75ce7349cfb6ad96d2c3d4091d1e4f10ec909e82 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 29 May 2022 19:20:19 -0400 Subject: [PATCH] Reference Frame Module --- .../Builder/Body/AsteroidBeltBuilder.cs | 8 ++++-- .../Builder/General/RFVolumeBuilder.cs | 9 +++--- .../Builder/Orbital/FocalPointBuilder.cs | 4 +-- NewHorizons/External/Configs/PlanetConfig.cs | 8 ++++++ NewHorizons/External/Modules/BaseModule.cs | 8 ++---- .../External/Modules/ReferenceFrameModule.cs | 28 +++++++++++++++++++ NewHorizons/Handlers/PlanetCreationHandler.cs | 6 ++-- NewHorizons/Schemas/body_schema.json | 25 +++++++++++++---- 8 files changed, 75 insertions(+), 21 deletions(-) create mode 100644 NewHorizons/External/Modules/ReferenceFrameModule.cs diff --git a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs index 64543600..5e71238f 100644 --- a/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs +++ b/NewHorizons/Builder/Body/AsteroidBeltBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.External.Configs; +using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Handlers; using NewHorizons.Utility; @@ -34,7 +34,6 @@ namespace NewHorizons.Builder.Body hasMapMarker = false, surfaceGravity = 1, surfaceSize = size, - hasReferenceFrame = false, gravityFallOff = GravityFallOff.InverseSquared }; @@ -49,6 +48,11 @@ namespace NewHorizons.Builder.Body showOrbitLine = false }; + config.ReferenceFrame = new ReferenceFrameModule() + { + hideInMap = true + }; + config.ProcGen = belt.procGen; if (config.ProcGen == null) { diff --git a/NewHorizons/Builder/General/RFVolumeBuilder.cs b/NewHorizons/Builder/General/RFVolumeBuilder.cs index f6831bb7..83e76cb5 100644 --- a/NewHorizons/Builder/General/RFVolumeBuilder.cs +++ b/NewHorizons/Builder/General/RFVolumeBuilder.cs @@ -1,10 +1,11 @@ using NewHorizons.External.Configs; +using NewHorizons.External.Modules; using UnityEngine; namespace NewHorizons.Builder.General { public static class RFVolumeBuilder { - public static void Make(GameObject planetGO, OWRigidbody owrb, float sphereOfInfluence, bool hide = false) + public static void Make(GameObject planetGO, OWRigidbody owrb, float sphereOfInfluence, ReferenceFrameModule module) { var rfGO = new GameObject("RFVolume"); rfGO.transform.parent = planetGO.transform; @@ -19,7 +20,7 @@ namespace NewHorizons.Builder.General var RFV = rfGO.AddComponent(); var RV = new ReferenceFrame(owrb); - RV._minSuitTargetDistance = sphereOfInfluence; + RV._minSuitTargetDistance = module.targetWhenClose ? 0 : sphereOfInfluence; RV._maxTargetDistance = 0; RV._autopilotArrivalDistance = 2.0f * sphereOfInfluence; RV._autoAlignmentDistance = sphereOfInfluence * 1.5f; @@ -28,7 +29,7 @@ namespace NewHorizons.Builder.General RV._matchAngularVelocity = true; RV._minMatchAngularVelocityDistance = 70; RV._maxMatchAngularVelocityDistance = 400; - RV._bracketsRadius = sphereOfInfluence; + RV._bracketsRadius = module.bracketRadius > -1 ? module.bracketRadius : sphereOfInfluence; RFV._referenceFrame = RV; RFV._minColliderRadius = sphereOfInfluence; @@ -38,7 +39,7 @@ namespace NewHorizons.Builder.General owrb.SetAttachedReferenceFrameVolume(RFV); - rfGO.SetActive(!hide); + rfGO.SetActive(!module.hideInMap); } } } diff --git a/NewHorizons/Builder/Orbital/FocalPointBuilder.cs b/NewHorizons/Builder/Orbital/FocalPointBuilder.cs index c217664e..98a51bd9 100644 --- a/NewHorizons/Builder/Orbital/FocalPointBuilder.cs +++ b/NewHorizons/Builder/Orbital/FocalPointBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components.Orbital; +using NewHorizons.Components.Orbital; using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Handlers; @@ -59,7 +59,7 @@ namespace NewHorizons.Builder.Orbital fakeMassConfig.name = config.name + "_FakeBarycenterMass"; fakeMassConfig.Base.sphereOfInfluence = 0; fakeMassConfig.Base.hasMapMarker = false; - fakeMassConfig.Base.hasReferenceFrame = false; + fakeMassConfig.ReferenceFrame.hideInMap = true; fakeMassConfig.Orbit = new OrbitModule(); fakeMassConfig.Orbit.CopyPropertiesFrom(config.Orbit); diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index bd748a62..ee652297 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -101,6 +101,11 @@ namespace NewHorizons.External.Configs /// public PropModule Props; + /// + /// Reference frame properties of this body + /// + public ReferenceFrameModule ReferenceFrame; + /// /// A list of paths to child GameObjects to destroy on this planet /// @@ -162,6 +167,7 @@ namespace NewHorizons.External.Configs if (Base == null) Base = new BaseModule(); if (Orbit == null) Orbit = new OrbitModule(); if (ShipLog == null) ShipLog = new ShipLogModule(); + if (ReferenceFrame == null) ReferenceFrame = new ReferenceFrameModule(); } public void MigrateAndValidate() @@ -195,6 +201,8 @@ namespace NewHorizons.External.Configs if (Base.isSatellite) Base.showMinimap = false; + if (!Base.hasReferenceFrame) ReferenceFrame.hideInMap = 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 20645d16..b0e81c1a 100644 --- a/NewHorizons/External/Modules/BaseModule.cs +++ b/NewHorizons/External/Modules/BaseModule.cs @@ -56,11 +56,6 @@ namespace NewHorizons.External.Modules /// public bool hasMapMarker; - /// - /// Allows the object to be targeted on the map. - /// - [DefaultValue(true)] public bool hasReferenceFrame = true; - /// /// Can this planet survive entering a star? /// @@ -106,6 +101,9 @@ namespace NewHorizons.External.Modules [Obsolete("HasAmbientLight is deprecated, please use AmbientLight instead")] public bool hasAmbientLight; + [Obsolete("HasReferenceFrame is deprecated, please use ReferenceModule instead")] + [DefaultValue(true)] public bool hasReferenceFrame = true; + [Obsolete("CloakRadius is deprecated, please use CloakModule instead")] public float cloakRadius; diff --git a/NewHorizons/External/Modules/ReferenceFrameModule.cs b/NewHorizons/External/Modules/ReferenceFrameModule.cs new file mode 100644 index 00000000..e9dc02a4 --- /dev/null +++ b/NewHorizons/External/Modules/ReferenceFrameModule.cs @@ -0,0 +1,28 @@ +using System; +using System.ComponentModel; +using System.Runtime.Serialization; +using NewHorizons.Utility; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace NewHorizons.External.Modules +{ + [JsonObject] + public class ReferenceFrameModule + { + /// + /// Stop the object from being targeted on the map. + /// + public bool hideInMap; + + /// + /// Radius of the brackets that show up when you target this. Defaults to the sphereOfInfluence. + /// + [DefaultValue(-1)] public float bracketRadius = -1; + + /// + /// If it should be targetable even when super close. + /// + public bool targetWhenClose; + } +} \ No newline at end of file diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 77ca0ebe..1cb8f3d2 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Builder.Atmosphere; +using NewHorizons.Builder.Atmosphere; using NewHorizons.Builder.Body; using NewHorizons.Builder.General; using NewHorizons.Builder.Orbital; @@ -306,7 +306,7 @@ namespace NewHorizons.Handlers GravityBuilder.Make(go, ao, owRigidBody, body.Config); } - RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence, !body.Config.Base.hasReferenceFrame); + RFVolumeBuilder.Make(go, owRigidBody, sphereOfInfluence, body.Config.ReferenceFrame); if (body.Config.Base.hasMapMarker) { @@ -482,7 +482,7 @@ namespace NewHorizons.Handlers // Has to go last probably if (body.Config.Cloak != null && body.Config.Cloak.radius != 0f) { - CloakBuilder.Make(go, sector, rb, body.Config.Cloak, body.Config.Base.hasReferenceFrame, body.Mod); + CloakBuilder.Make(go, sector, rb, body.Config.Cloak, !body.Config.ReferenceFrame.hideInMap, body.Mod); } return go; diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 5f1f9bdd..3badb0eb 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -428,11 +428,6 @@ "type": "boolean", "description": "If the body should have a marker on the map screen." }, - "hasReferenceFrame": { - "type": "boolean", - "description": "Allows the object to be targeted on the map.", - "default": true - }, "invulnerableToSun": { "type": "boolean", "description": "Can this planet survive entering a star?" @@ -459,6 +454,26 @@ } } }, + "ReferenceFrameModule": { + "type": "object", + "additionalProperties": false, + "properties": { + "hideInMap": { + "type": "boolean", + "description": "Stop the object from being targeted on the map." + }, + "bracketRadius": { + "type": "number", + "description": "Radius of the brackets that show up when you target this. Defaults to the sphereOfInfluence.", + "format": "float", + "default": -1 + }, + "targetWhenClose": { + "type": "boolean", + "description": "If it should be targetable even when super close." + } + } + }, "MVector3": { "type": "object", "additionalProperties": false,