Turn quantum lightning into a prop based thing, make quantum details build with the repeat-10-times-for-parent-to-exist thing for back compat

This commit is contained in:
xen-42 2025-01-07 16:48:56 -05:00
parent 82e4a8755d
commit 37c90f52f0
6 changed files with 40 additions and 40 deletions

View File

@ -22,6 +22,20 @@ namespace NewHorizons.Builder.Props
private static readonly Dictionary<(Sector, string), (GameObject prefab, bool isItem)> _fixedPrefabCache = new(); private static readonly Dictionary<(Sector, string), (GameObject prefab, bool isItem)> _fixedPrefabCache = new();
private static GameObject _emptyPrefab; private static GameObject _emptyPrefab;
private static readonly Dictionary<DetailInfo, GameObject> _detailInfoToGameObject = new();
public static GameObject GetGameObjectFromDetailInfo(DetailInfo info)
{
if (_detailInfoToGameObject.ContainsKey(info))
{
return _detailInfoToGameObject[info];
}
else
{
return null;
}
}
static DetailBuilder() static DetailBuilder()
{ {
SceneManager.sceneUnloaded += SceneManager_sceneUnloaded; SceneManager.sceneUnloaded += SceneManager_sceneUnloaded;
@ -47,6 +61,7 @@ namespace NewHorizons.Builder.Props
UnityEngine.Object.Destroy(prefab.prefab); UnityEngine.Object.Destroy(prefab.prefab);
} }
_fixedPrefabCache.Clear(); _fixedPrefabCache.Clear();
_detailInfoToGameObject.Clear();
} }
/// <summary> /// <summary>
@ -286,6 +301,8 @@ namespace NewHorizons.Builder.Props
ConditionalObjectActivation.SetUp(prop, detail.deactivationCondition, detail.blinkWhenActiveChanged, false); ConditionalObjectActivation.SetUp(prop, detail.deactivationCondition, detail.blinkWhenActiveChanged, false);
} }
_detailInfoToGameObject[detail] = prop;
return prop; return prop;
} }

View File

@ -6,15 +6,12 @@ using NewHorizons.Builder.ShipLog;
using NewHorizons.External; using NewHorizons.External;
using NewHorizons.External.Configs; using NewHorizons.External.Configs;
using NewHorizons.External.Modules; using NewHorizons.External.Modules;
using NewHorizons.External.Modules.Props;
using NewHorizons.External.Modules.Props.Quantum;
using NewHorizons.Utility; using NewHorizons.Utility;
using NewHorizons.Utility.OWML; using NewHorizons.Utility.OWML;
using OWML.Common; using OWML.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NewHorizons.External.Modules.Props;
using UnityEngine; using UnityEngine;
namespace NewHorizons.Builder.Props namespace NewHorizons.Builder.Props
@ -143,6 +140,10 @@ namespace NewHorizons.Builder.Props
MakeGeneralProps(go, config.Props.audioSources, (audioSource) => AudioSourceBuilder.Make(go, sector, audioSource, mod), (audioSource) => audioSource.audio); MakeGeneralProps(go, config.Props.audioSources, (audioSource) => AudioSourceBuilder.Make(go, sector, audioSource, mod), (audioSource) => audioSource.audio);
RemoteBuilder.MakeGeneralProps(go, sector, config.Props.remotes, nhBody); RemoteBuilder.MakeGeneralProps(go, sector, config.Props.remotes, nhBody);
if (Main.HasDLC) MakeGeneralProps(go, config.Props.projectionTotems, (totem) => ProjectionTotemBuilder.Make(go, sector, totem, mod)); if (Main.HasDLC) MakeGeneralProps(go, config.Props.projectionTotems, (totem) => ProjectionTotemBuilder.Make(go, sector, totem, mod));
// For quantum groups, make the details in advance
if (config.Props.socketQuantumGroups != null) MakeGeneralProps(go, config.Props.socketQuantumGroups.SelectMany(x => x.details), (detail) => DetailBuilder.Make(go, sector, mod, detail), (detail) => detail.path);
if (config.Props.stateQuantumGroups != null) MakeGeneralProps(go, config.Props.stateQuantumGroups.SelectMany(x => x.details), (detail) => DetailBuilder.Make(go, sector, mod, detail), (detail) => detail.path);
if (config.Props.lightningQuantumGroups != null) MakeGeneralProps(go, config.Props.lightningQuantumGroups, (lightning) => QuantumBuilder.MakeQuantumLightning(go, sector, mod, lightning));
RunMultiPass(); RunMultiPass();
@ -165,7 +166,6 @@ namespace NewHorizons.Builder.Props
} }
} }
if (config.Props.lightningQuantumGroups != null) QuantumBuilder.Make(go, sector, mod, config.Props.lightningQuantumGroups);
if (config.Props.socketQuantumGroups != null) QuantumBuilder.Make(go, sector, mod, config.Props.socketQuantumGroups); if (config.Props.socketQuantumGroups != null) QuantumBuilder.Make(go, sector, mod, config.Props.socketQuantumGroups);
if (config.Props.stateQuantumGroups != null) QuantumBuilder.Make(go, sector, mod, config.Props.stateQuantumGroups); if (config.Props.stateQuantumGroups != null) QuantumBuilder.Make(go, sector, mod, config.Props.stateQuantumGroups);
} }

View File

@ -1,16 +1,13 @@
using NewHorizons.Components.Quantum; using NewHorizons.Components.Quantum;
using NewHorizons.External.Configs;
using NewHorizons.External.Modules.Props; using NewHorizons.External.Modules.Props;
using NewHorizons.External.Modules.Props.Quantum; using NewHorizons.External.Modules.Props.Quantum;
using NewHorizons.Utility.Files; using NewHorizons.Utility.Files;
using NewHorizons.Utility.Geometry; using NewHorizons.Utility.Geometry;
using NewHorizons.Utility.OWML; using NewHorizons.Utility.OWML;
using System; using OWML.Common;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NewHorizons.External.Modules.Props;
using UnityEngine; using UnityEngine;
using OWML.Common;
namespace NewHorizons.Builder.Props namespace NewHorizons.Builder.Props
{ {
@ -40,26 +37,14 @@ namespace NewHorizons.Builder.Props
{ {
MakeStateGroup(planetGO, sector, mod, stateGroup); MakeStateGroup(planetGO, sector, mod, stateGroup);
} }
else if (quantumGroup is LightningQuantumGroupInfo lightningGroup)
{
MakeQuantumLightning(planetGO, sector, mod, lightningGroup);
}
} }
public static void MakeQuantumLightning(GameObject planetGO, Sector sector, IModBehaviour mod, LightningQuantumGroupInfo quantumGroup) public static void MakeQuantumLightning(GameObject planetGO, Sector sector, IModBehaviour mod, LightningQuantumInfo quantumGroup)
{ {
(GameObject go, QuantumDetailInfo detail)[] propsInGroup = quantumGroup.details.Select(x => (DetailBuilder.Make(planetGO, sector, mod, x), x)).ToArray(); (GameObject go, DetailInfo detail)[] propsInGroup = quantumGroup.details.Select(x => (DetailBuilder.Make(planetGO, sector, mod, x), x)).ToArray();
// Bases its position off the first object with position set var lightning = DetailBuilder.Make(planetGO, sector, Main.Instance, AssetBundleUtilities.NHPrivateAssetBundle.LoadAsset<GameObject>("Prefab_EYE_QuantumLightningObject"), new DetailInfo(quantumGroup));
var root = propsInGroup.FirstOrDefault(x => x.detail.position != null || x.detail.rotation != null || x.detail.isRelativeToParent);
var rootGo = root == default ? sector.gameObject : root.go;
var lightning = DetailBuilder.Make(planetGO, sector, Main.Instance, AssetBundleUtilities.NHPrivateAssetBundle.LoadAsset<GameObject>("Prefab_EYE_QuantumLightningObject"), new DetailInfo());
AssetBundleUtilities.ReplaceShaders(lightning); AssetBundleUtilities.ReplaceShaders(lightning);
lightning.transform.position = rootGo.transform.position;
lightning.transform.rotation = rootGo.transform.rotation;
lightning.transform.parent = rootGo.transform.parent;
foreach (var (go, _) in propsInGroup) foreach (var (go, _) in propsInGroup)
{ {
@ -82,7 +67,7 @@ namespace NewHorizons.Builder.Props
// Nice to have: socket groups that specify a filledSocketObject and an emptySocketObject (eg the archway in the giant's deep tower) // Nice to have: socket groups that specify a filledSocketObject and an emptySocketObject (eg the archway in the giant's deep tower)
public static void MakeSocketGroup(GameObject planetGO, Sector sector, IModBehaviour mod, SocketQuantumGroupInfo quantumGroup) public static void MakeSocketGroup(GameObject planetGO, Sector sector, IModBehaviour mod, SocketQuantumGroupInfo quantumGroup)
{ {
(GameObject go, QuantumDetailInfo detail)[] propsInGroup = quantumGroup.details.Select(x => (DetailBuilder.Make(planetGO, sector, mod, x), x)).ToArray(); (GameObject go, QuantumDetailInfo detail)[] propsInGroup = quantumGroup.details.Select(x => (DetailBuilder.GetGameObjectFromDetailInfo(x), x)).ToArray();
GameObject specialProp = null; GameObject specialProp = null;
QuantumDetailInfo specialInfo = null; QuantumDetailInfo specialInfo = null;
@ -177,7 +162,7 @@ namespace NewHorizons.Builder.Props
// while states put the QuantumObject component (NHMultiStateQuantumObject) on the parent, which is located at the center of the planet // while states put the QuantumObject component (NHMultiStateQuantumObject) on the parent, which is located at the center of the planet
// this means that the distance measured by QuantumObject is not accurate, since it's not measuring from the active prop, but from the center of the planet // this means that the distance measured by QuantumObject is not accurate, since it's not measuring from the active prop, but from the center of the planet
var propsInGroup = quantumGroup.details.Select(x => DetailBuilder.Make(go, sector, mod, x)).ToArray(); var propsInGroup = quantumGroup.details.Select(x => DetailBuilder.GetGameObjectFromDetailInfo(x)).ToArray();
var groupRoot = new GameObject(quantumGroup.rename); var groupRoot = new GameObject(quantumGroup.rename);
groupRoot.transform.parent = sector?.transform ?? go.transform; groupRoot.transform.parent = sector?.transform ?? go.transform;

View File

@ -132,7 +132,7 @@ namespace NewHorizons.External.Modules
/// <summary> /// <summary>
/// Add quantum lightning to a planet. When lightning strikes, a different detail object is shown. The lightning will take the first defined position/rotation for all objects. /// Add quantum lightning to a planet. When lightning strikes, a different detail object is shown. The lightning will take the first defined position/rotation for all objects.
/// </summary> /// </summary>
public LightningQuantumGroupInfo[] lightningQuantumGroups; public LightningQuantumInfo[] lightningQuantumGroups;
/// <summary> /// <summary>
/// Add campfires that allow you to enter the dream world/simulation (requires Echoes of the Eye DLC). Must be paired with a dream arrival point, which can be placed on this planet or elsewhere. /// Add campfires that allow you to enter the dream world/simulation (requires Echoes of the Eye DLC). Must be paired with a dream arrival point, which can be placed on this planet or elsewhere.

View File

@ -1,14 +0,0 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.External.Modules.Props.Quantum;
[JsonObject]
public class LightningQuantumGroupInfo : BaseQuantumGroupInfo
{
}

View File

@ -0,0 +1,12 @@
using Newtonsoft.Json;
namespace NewHorizons.External.Modules.Props.Quantum;
[JsonObject]
public class LightningQuantumInfo : GeneralPropInfo
{
/// <summary>
/// List of props which will be alternated between during flashes of lightning
/// </summary>
public DetailInfo[] details;
}