diff --git a/NewHorizons/Builder/Props/PropBuildManager.cs b/NewHorizons/Builder/Props/PropBuildManager.cs index de3b7073..cb889884 100644 --- a/NewHorizons/Builder/Props/PropBuildManager.cs +++ b/NewHorizons/Builder/Props/PropBuildManager.cs @@ -6,6 +6,7 @@ using NewHorizons.Builder.ShipLog; using NewHorizons.External; using NewHorizons.External.Configs; using NewHorizons.External.Modules; +using NewHorizons.External.Modules.Props; using NewHorizons.External.Modules.Props.Quantum; using NewHorizons.Utility; using NewHorizons.Utility.OWML; @@ -163,46 +164,7 @@ namespace NewHorizons.Builder.Props } } - var quantumPropsByGroup = new Dictionary>(); - foreach (var detail in config.Props?.details) - { - if (detail.quantumGroupID != null) - { - if (!quantumPropsByGroup.ContainsKey(detail.quantumGroupID)) - { - quantumPropsByGroup[detail.quantumGroupID] = new List(); - } - quantumPropsByGroup[detail.quantumGroupID].Add(DetailBuilder.GetSpawnedGameObjectByDetailInfo(detail)); - } - } - - void MakeQuantumGroup(BaseQuantumGroupInfo[] group) - { - foreach (var quantumGroup in group) - { - if (!quantumPropsByGroup.ContainsKey(quantumGroup.id)) continue; - var propsInGroup = quantumPropsByGroup[quantumGroup.id]; - - try - { - QuantumBuilder.Make(go, sector, quantumGroup, propsInGroup.ToArray()); - } - catch (Exception ex) - { - NHLogger.LogError($"Couldn't make quantum group [{quantumGroup.id}] for [{go.name}]:\n{ex}"); - } - } - } - - if (config.Props.socketQuantumGroups != null) - { - MakeQuantumGroup(config.Props.socketQuantumGroups); - } - - if (config.Props.stateQuantumGroups != null) - { - MakeQuantumGroup(config.Props.stateQuantumGroups); - } + QuantumBuilder.TryMake(go, sector, config); } private static bool _ignoreParent; diff --git a/NewHorizons/Builder/Props/QuantumBuilder.cs b/NewHorizons/Builder/Props/QuantumBuilder.cs index aa4e9461..15be5ebb 100644 --- a/NewHorizons/Builder/Props/QuantumBuilder.cs +++ b/NewHorizons/Builder/Props/QuantumBuilder.cs @@ -1,8 +1,12 @@ +using Epic.OnlineServices; using NewHorizons.Components.Quantum; +using NewHorizons.External.Configs; using NewHorizons.External.Modules.Props; using NewHorizons.External.Modules.Props.Quantum; +using NewHorizons.Utility.Files; using NewHorizons.Utility.Geometry; using NewHorizons.Utility.OWML; +using System; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -11,34 +15,101 @@ namespace NewHorizons.Builder.Props { public static class QuantumBuilder { - public static void Make(GameObject planetGO, Sector sector, BaseQuantumGroupInfo quantumGroup, GameObject[] propsInGroup) + public static void TryMake(GameObject go, Sector sector, PlanetConfig config) + { + if (config.Props != null && config.Props.details != null) + { + var quantumPropsByGroup = new Dictionary>(); + foreach (var detail in config.Props?.details) + { + if (detail.quantumGroupID != null) + { + if (!quantumPropsByGroup.ContainsKey(detail.quantumGroupID)) + { + quantumPropsByGroup[detail.quantumGroupID] = new(); + } + quantumPropsByGroup[detail.quantumGroupID].Add((DetailBuilder.GetSpawnedGameObjectByDetailInfo(detail), detail)); + } + } + + void MakeQuantumGroup(BaseQuantumGroupInfo[] group) + { + foreach (var quantumGroup in group) + { + if (!quantumPropsByGroup.ContainsKey(quantumGroup.id)) continue; + var propsInGroup = quantumPropsByGroup[quantumGroup.id]; + + try + { + QuantumBuilder.Make(go, sector, quantumGroup, propsInGroup.ToArray()); + } + catch (Exception ex) + { + NHLogger.LogError($"Couldn't make quantum group [{quantumGroup.id}] for [{go.name}]:\n{ex}"); + } + } + } + + if (config.Props.socketQuantumGroups != null) + { + MakeQuantumGroup(config.Props.socketQuantumGroups); + } + + if (config.Props.stateQuantumGroups != null) + { + MakeQuantumGroup(config.Props.stateQuantumGroups); + } + + if (config.Props.lightningQuantumGroups != null) + { + MakeQuantumGroup(config.Props.lightningQuantumGroups); + } + } + } + + public static void Make(GameObject planetGO, Sector sector, BaseQuantumGroupInfo quantumGroup, (GameObject go, DetailInfo detail)[] propsInGroup) { if (quantumGroup is SocketQuantumGroupInfo socketGroup) { - MakeSocketGroup(planetGO, sector, socketGroup, propsInGroup); + MakeSocketGroup(planetGO, sector, socketGroup, propsInGroup.Select(x => x.go).ToArray()); } else if (quantumGroup is StateQuantumGroupInfo stateGroup) { - MakeStateGroup(planetGO, sector, stateGroup, propsInGroup); + MakeStateGroup(planetGO, sector, stateGroup, propsInGroup.Select(x => x.go).ToArray()); + } + else if (quantumGroup is LightningQuantumGroupInfo lightningGroup) + { + MakeQuantumLightning(planetGO, sector, lightningGroup, propsInGroup); } } - /* - public static void MakeQuantumLightning(GameObject planetGO, Sector sector, GameObject[] propsInGroup) + public static void MakeQuantumLightning(GameObject planetGO, Sector sector, LightningQuantumGroupInfo quantumGroup, (GameObject go, DetailInfo detail)[] propsInGroup) { + // Bases its position off the first object with position set + 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.EyeLightning.LoadAsset("Prefab_EYE_QuantumLightningObject"), new DetailInfo()); - lightning.transform.position = prop.transform.position; - lightning.transform.rotation = prop.transform.rotation; - lightning.transform.parent = prop.transform.parent; + lightning.transform.position = rootGo.transform.position; + lightning.transform.rotation = rootGo.transform.rotation; + lightning.transform.parent = rootGo.transform.parent; var lightningStatesParent = lightning.transform.Find("Models"); - prop.transform.parent = lightningStatesParent; + foreach (var (go, _) in propsInGroup) + { + go.transform.parent = lightningStatesParent; + go.transform.localPosition = Vector3.zero; + go.transform.localRotation = Quaternion.identity; + } var lightningController = lightning.GetComponent(); - lightningController._models = new GameObject[] { prop }; + lightningController._models = propsInGroup.Select(x => x.go).ToArray(); lightningController.enabled = true; + + lightning.name = "Quantum Lightning - " + quantumGroup.id; + lightning.SetActive(true); } - */ // TODO: Socket groups that have an equal number of props and sockets // Nice to have: socket groups that specify a filledSocketObject and an emptySocketObject (eg the archway in the giant's deep tower) diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index f2304be0..b5b3d519 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -122,6 +122,8 @@ namespace NewHorizons.External.Modules public StateQuantumGroupInfo[] stateQuantumGroups; + public LightningQuantumGroupInfo[] lightningQuantumGroups; + /// /// 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. /// diff --git a/NewHorizons/External/Modules/Props/Quantum/LightningQuantumGroupInfo.cs b/NewHorizons/External/Modules/Props/Quantum/LightningQuantumGroupInfo.cs new file mode 100644 index 00000000..421c0d2e --- /dev/null +++ b/NewHorizons/External/Modules/Props/Quantum/LightningQuantumGroupInfo.cs @@ -0,0 +1,14 @@ +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 +{ + +}