Add custom builders

This commit is contained in:
Nick 2023-08-26 15:36:01 -04:00
parent 8dabc7934e
commit e44efdbcca
4 changed files with 32 additions and 2 deletions

View File

@ -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<Action<GameObject, string>> CustomBuilders;
public static void Init(List<NewHorizonsBody> 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)
{

View File

@ -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
///</summary>
T QuerySystem<T>(string path);
/// <summary>
/// Register your own builder that will act on the given GameObject by reading the json string of its "extras" module
/// </summary>
void RegisterCustomBuilder(Action<GameObject, string> builder);
#endregion
#region Spawn props

View File

@ -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<ShipLogManager>(), xml, body);
}
/// <summary>
/// Register your own builder that will act on the given GameObject by reading its raw json string
/// </summary>
/// <param name="builder"></param>
public void RegisterCustomBuilder(Action<GameObject, string> builder) => PlanetCreationHandler.CustomBuilders.Add(builder);
}
}

View File

@ -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" ],