From 855a4caa2f40218c3227aa3daaed64352056502b Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 27 May 2022 06:04:32 -0400 Subject: [PATCH] Cloak Module --- NewHorizons/Builder/Body/CloakBuilder.cs | 4 +++- NewHorizons/External/Configs/PlanetConfig.cs | 13 +++++++++++- NewHorizons/External/Modules/BaseModule.cs | 11 ++++------ NewHorizons/External/Modules/CloakModule.cs | 19 ++++++++++++++++++ NewHorizons/Handlers/PlanetCreationHandler.cs | 4 ++-- NewHorizons/Schemas/body_schema.json | 20 ++++++++++++++----- 6 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 NewHorizons/External/Modules/CloakModule.cs diff --git a/NewHorizons/Builder/Body/CloakBuilder.cs b/NewHorizons/Builder/Body/CloakBuilder.cs index ffafc769..b0197bc4 100644 --- a/NewHorizons/Builder/Body/CloakBuilder.cs +++ b/NewHorizons/Builder/Body/CloakBuilder.cs @@ -1,12 +1,14 @@ using NewHorizons.Components; +using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; namespace NewHorizons.Builder.Body { public static class CloakBuilder { - public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, float radius, bool keepReferenceFrame) + public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, CloakModule module, bool keepReferenceFrame) { + var radius = module.radius; var cloak = SearchUtilities.Find("RingWorld_Body/CloakingField_IP"); var newCloak = GameObject.Instantiate(cloak, sector?.transform ?? planetGO.transform); diff --git a/NewHorizons/External/Configs/PlanetConfig.cs b/NewHorizons/External/Configs/PlanetConfig.cs index 74c82151..bd748a62 100644 --- a/NewHorizons/External/Configs/PlanetConfig.cs +++ b/NewHorizons/External/Configs/PlanetConfig.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using NewHorizons.External.Modules; @@ -45,6 +45,11 @@ namespace NewHorizons.External.Configs #endregion Obsolete + /// + /// Add a cloaking field to this planet + /// + public CloakModule Cloak; + /// /// `true` if you want to delete this planet /// @@ -192,6 +197,12 @@ namespace NewHorizons.External.Configs if (childrenToDestroy != null) removeChildren = childrenToDestroy; + if (Base.cloakRadius != 0) + Cloak = new CloakModule + { + radius = Base.cloakRadius + }; + if (Base.hasAmbientLight) Base.ambientLight = 0.5f; if (Atmosphere != null) diff --git a/NewHorizons/External/Modules/BaseModule.cs b/NewHorizons/External/Modules/BaseModule.cs index 28f2f8ba..20645d16 100644 --- a/NewHorizons/External/Modules/BaseModule.cs +++ b/NewHorizons/External/Modules/BaseModule.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.ComponentModel; using System.Runtime.Serialization; using NewHorizons.Utility; @@ -30,12 +30,6 @@ namespace NewHorizons.External.Modules /// public bool centerOfSolarSystem; - /// - /// Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you - /// don't want a cloak, leave this as 0. - /// - public float cloakRadius; - /// /// If it has a comet tail, it'll be oriented according to these Euler angles. /// @@ -112,6 +106,9 @@ namespace NewHorizons.External.Modules [Obsolete("HasAmbientLight is deprecated, please use AmbientLight instead")] public bool hasAmbientLight; + [Obsolete("CloakRadius is deprecated, please use CloakModule instead")] + public float cloakRadius; + #endregion Obsolete } } \ No newline at end of file diff --git a/NewHorizons/External/Modules/CloakModule.cs b/NewHorizons/External/Modules/CloakModule.cs new file mode 100644 index 00000000..87f6dbf7 --- /dev/null +++ b/NewHorizons/External/Modules/CloakModule.cs @@ -0,0 +1,19 @@ +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 CloakModule + { + /// + /// Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you + /// don't want a cloak, leave this as 0. + /// + public float radius; + } +} \ No newline at end of file diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 46cbacf4..a6324b55 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -480,9 +480,9 @@ namespace NewHorizons.Handlers } // Has to go last probably - if (body.Config.Base.cloakRadius != 0f) + if (body.Config.Cloak != null && body.Config.Cloak.radius != 0f) { - CloakBuilder.Make(go, sector, rb, body.Config.Base.cloakRadius, body.Config.Base.hasReferenceFrame); + CloakBuilder.Make(go, sector, rb, body.Config.Cloak, body.Config.Base.hasReferenceFrame); } return go; diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index b52e6823..5856cea7 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -30,6 +30,10 @@ "type": "boolean", "description": "Should this planet ever be shown on the title screen?" }, + "Cloak": { + "description": "Add a cloaking field to this planet", + "$ref": "#/definitions/CloakModule" + }, "destroy": { "type": "boolean", "description": "`true` if you want to delete this planet" @@ -285,6 +289,17 @@ } } }, + "CloakModule": { + "type": "object", + "additionalProperties": false, + "properties": { + "radius": { + "type": "number", + "description": "Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you\ndon't want a cloak, leave this as 0.", + "format": "float" + } + } + }, "CloudInfo": { "type": "object", "additionalProperties": false, @@ -384,11 +399,6 @@ "type": "boolean", "description": "Set this to true if you are replacing the sun with a different body. Only one object in a star system should ever\nhave this set to true." }, - "cloakRadius": { - "type": "number", - "description": "Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you\ndon't want a cloak, leave this as 0.", - "format": "float" - }, "cometTailRotation": { "description": "If it has a comet tail, it'll be oriented according to these Euler angles.", "$ref": "#/definitions/MVector3"