From e44efdbcca537305d21d70739da5b78c74ccbeec Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 26 Aug 2023 15:36:01 -0400 Subject: [PATCH] Add custom builders --- NewHorizons/Handlers/PlanetCreationHandler.cs | 19 ++++++++++++++++++- NewHorizons/INewHorizons.cs | 6 ++++++ NewHorizons/NewHorizonsApi.cs | 7 +++++++ NewHorizons/manifest.json | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 686abcfb..1e6a917c 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -16,7 +16,7 @@ using System; using System.Collections.Generic; using System.Linq; using UnityEngine; - +using Newtonsoft.Json; namespace NewHorizons.Handlers { @@ -34,6 +34,8 @@ namespace NewHorizons.Handlers public static float SolarSystemRadius { get; private set; } public static float DefaultFurthestOrbit => 30000f; + public static List> CustomBuilders; + public static void Init(List bodies) { // Start by destroying all planets if need be @@ -701,6 +703,21 @@ namespace NewHorizons.Handlers FunnelBuilder.Make(go, sector, rb, body.Config.Funnel); } + if (body.Config.extras != null) + { + foreach (var customBuilder in CustomBuilders) + { + try + { + customBuilder.Invoke(go, JsonConvert.SerializeObject(body.Config.extras)); + } + catch + { + NHLogger.LogError($"Failed to use custom builder on body {body.Config.name}"); + } + } + } + // Has to go last probably if (willHaveCloak) { diff --git a/NewHorizons/INewHorizons.cs b/NewHorizons/INewHorizons.cs index c4447d28..903b76e5 100644 --- a/NewHorizons/INewHorizons.cs +++ b/NewHorizons/INewHorizons.cs @@ -1,3 +1,4 @@ +using NewHorizons.Handlers; using OWML.Common; using System; using System.Collections.Generic; @@ -92,6 +93,11 @@ namespace NewHorizons /// Uses JSONPath to query the current star system /// T QuerySystem(string path); + + /// + /// Register your own builder that will act on the given GameObject by reading the json string of its "extras" module + /// + void RegisterCustomBuilder(Action builder); #endregion #region Spawn props diff --git a/NewHorizons/NewHorizonsApi.cs b/NewHorizons/NewHorizonsApi.cs index 5eaf322e..0b25a339 100644 --- a/NewHorizons/NewHorizonsApi.cs +++ b/NewHorizons/NewHorizonsApi.cs @@ -10,6 +10,7 @@ using NewHorizons.External.Modules.Props.Audio; using NewHorizons.External.Modules.Props.Dialogue; using NewHorizons.External.Modules.TranslatorText; using NewHorizons.External.SerializableData; +using NewHorizons.Handlers; using NewHorizons.Utility; using NewHorizons.Utility.OWML; using Newtonsoft.Json; @@ -315,5 +316,11 @@ namespace NewHorizons RumorModeBuilder.AddShipLogXML(GameObject.FindObjectOfType(), xml, body); } + + /// + /// Register your own builder that will act on the given GameObject by reading its raw json string + /// + /// + public void RegisterCustomBuilder(Action builder) => PlanetCreationHandler.CustomBuilders.Add(builder); } } diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index 24971a5e..ff707cb8 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -4,7 +4,7 @@ "author": "xen, Bwc9876, clay, MegaPiggy, John, Trifid, Hawkbar, Book", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "1.15.1", + "version": "1.16.0", "owmlVersion": "2.9.3", "dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ], "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ],