From b6e2c1906fb7e14d89ab585372a7986408c5cc09 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 15 May 2022 00:28:51 -0400 Subject: [PATCH] Add proxy details --- NewHorizons/Builder/Body/ProxyBuilder.cs | 14 +++- NewHorizons/Builder/Body/StarBuilder.cs | 6 +- NewHorizons/Builder/Props/DetailBuilder.cs | 94 +++++++++++----------- NewHorizons/External/PropModule.cs | 1 + NewHorizons/schema.json | 90 ++++++++++++--------- 5 files changed, 114 insertions(+), 91 deletions(-) diff --git a/NewHorizons/Builder/Body/ProxyBuilder.cs b/NewHorizons/Builder/Body/ProxyBuilder.cs index f4028c79..96c7f8e1 100644 --- a/NewHorizons/Builder/Body/ProxyBuilder.cs +++ b/NewHorizons/Builder/Body/ProxyBuilder.cs @@ -1,4 +1,5 @@ using NewHorizons.Builder.Atmosphere; +using NewHorizons.Builder.Props; using NewHorizons.Components; using NewHorizons.Components.SizeControllers; using NewHorizons.External.VariableSize; @@ -13,7 +14,7 @@ namespace NewHorizons.Builder.Body public static class ProxyBuilder { private static Material lavaMaterial; - + private static GameObject _blackHolePrefab; private static GameObject _whiteHolePrefab; @@ -23,7 +24,7 @@ namespace NewHorizons.Builder.Body public static void Make(GameObject gameObject, NewHorizonsBody body) { - if(lavaMaterial == null) lavaMaterial = SearchUtilities.FindObjectOfTypeAndName("VolcanicMoon_Body").transform.Find("LavaSphere").GetComponent().material; + if (lavaMaterial == null) lavaMaterial = SearchUtilities.FindObjectOfTypeAndName("VolcanicMoon_Body").transform.Find("LavaSphere").GetComponent().material; var proxyName = $"{body.Config.Name}_Proxy"; @@ -91,7 +92,7 @@ namespace NewHorizons.Builder.Body // Could improve this to actually use the proper renders and materials if (body.Config.Singularity != null) { - if(body.Config.Singularity.Type == "BlackHole") + if (body.Config.Singularity.Type == "BlackHole") { MakeBlackHole(newProxy, body.Config.Singularity.Size); } @@ -106,6 +107,13 @@ namespace NewHorizons.Builder.Body { CometTailBuilder.Make(newProxy, null, body.Config); } + if (body.Config.Props?.ProxyDetails != null) + { + foreach (var detailInfo in body.Config.Props.ProxyDetails) + { + DetailBuilder.Make(newProxy, null, body.Config, body.Mod, body.Mod.ModHelper.Manifest.UniqueName, detailInfo); + } + } // Remove all collisions if there are any foreach (var col in newProxy.GetComponentsInChildren()) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index a8c641d1..bd10bd3a 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -33,7 +33,7 @@ namespace NewHorizons.Builder.Body sunAudio.name = "Audio_Star"; - if(starModule.HasAtmosphere) + if (starModule.HasAtmosphere) { var sunAtmosphere = GameObject.Instantiate(GameObject.Find("Sun_Body/Atmosphere_SUN"), planetGO.transform); sunAtmosphere.transform.position = planetGO.transform.position; @@ -70,8 +70,8 @@ namespace NewHorizons.Builder.Body heatVolume.transform.localPosition = Vector3.zero; heatVolume.transform.localScale = Vector3.one; heatVolume.GetComponent().radius = 1f; - heatVolume.name = "HeatVolume"; - + heatVolume.name = "HeatVolume"; + var deathVolume = GameObject.Instantiate(GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN/ScaledVolumesRoot/DestructionFluidVolume"), starGO.transform); deathVolume.transform.localPosition = Vector3.zero; deathVolume.transform.localScale = Vector3.one; diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index d2a1b179..5a79cbdd 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -42,9 +42,9 @@ namespace NewHorizons.Builder.Props } else detailGO = MakeDetail(go, sector, detail.path, detail.position, detail.rotation, detail.scale, detail.alignToNormal); - if(detailGO != null && detail.removeChildren != null) + if (detailGO != null && detail.removeChildren != null) { - foreach(var childPath in detail.removeChildren) + foreach (var childPath in detail.removeChildren) { var childObj = detailGO.transform.Find(childPath); if (childObj != null) childObj.gameObject.SetActive(false); @@ -52,7 +52,7 @@ namespace NewHorizons.Builder.Props } } - if(detailGO != null && detail.removeComponents) + if (detailGO != null && detail.removeComponents) { // Just swap all the children to a new game object var newDetailGO = new GameObject(detailGO.name); @@ -60,11 +60,11 @@ namespace NewHorizons.Builder.Props newDetailGO.transform.parent = detailGO.transform.parent; // Can't modify parents while looping through children bc idk var children = new List(); - foreach(Transform child in detailGO.transform) + foreach (Transform child in detailGO.transform) { children.Add(child); } - foreach(var child in children) + foreach (var child in children) { child.parent = newDetailGO.transform; } @@ -87,7 +87,7 @@ namespace NewHorizons.Builder.Props GameObject prop = GameObject.Instantiate(prefab, sector.transform); prop.SetActive(false); - sector.OnOccupantEnterSector += (SectorDetector sd) => OWAssetHandler.OnOccupantEnterSector(prop, sd, sector); + if (sector != null) sector.OnOccupantEnterSector += (SectorDetector sd) => OWAssetHandler.OnOccupantEnterSector(prop, sd, sector); OWAssetHandler.LoadObject(prop); foreach (var component in prop.GetComponents().Concat(prop.GetComponentsInChildren())) @@ -96,52 +96,56 @@ namespace NewHorizons.Builder.Props var enabledField = component?.GetType()?.GetField("enabled"); if (enabledField != null && enabledField.FieldType == typeof(bool)) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => enabledField.SetValue(component, true)); - if(component is Sector) + // Fix a bunch of sector stuff + if (sector != null) { - (component as Sector)._parentSector = sector; - } - - // TODO: Make this work or smthng - if (component is GhostIK) (component as GhostIK).enabled = false; - if (component is GhostEffects) (component as GhostEffects).enabled = false; - - if(component is DarkMatterVolume) - { - var probeVisuals = component.gameObject.transform.Find("ProbeVisuals"); - if (probeVisuals != null) probeVisuals.gameObject.SetActive(true); - } - - if (component is SectoredMonoBehaviour) - { - (component as SectoredMonoBehaviour).SetSector(sector); - } - else - { - var sectorField = component?.GetType()?.GetField("_sector"); - if (sectorField != null && sectorField.FieldType == typeof(Sector)) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => sectorField.SetValue(component, sector)); - } - - if (component is AnglerfishController) - { - try + if (component is Sector) { - (component as AnglerfishController)._chaseSpeed += OWPhysics.CalculateOrbitVelocity(planetGO.GetAttachedOWRigidbody(), planetGO.GetComponent().GetPrimaryBody().GetAttachedOWRigidbody()).magnitude; + (component as Sector)._parentSector = sector; } - catch (Exception e) + + // TODO: Make this work or smthng + if (component is GhostIK) (component as GhostIK).enabled = false; + if (component is GhostEffects) (component as GhostEffects).enabled = false; + + if (component is DarkMatterVolume) { - Logger.LogError($"Couldn't update AnglerFish chase speed: {e.Message}"); + var probeVisuals = component.gameObject.transform.Find("ProbeVisuals"); + if (probeVisuals != null) probeVisuals.gameObject.SetActive(true); } - } - // Fix slide reel - if(component is SlideCollectionContainer) - { - sector.OnOccupantEnterSector.AddListener((_) => (component as SlideCollectionContainer).LoadStreamingTextures()); - } + if (component is SectoredMonoBehaviour) + { + (component as SectoredMonoBehaviour).SetSector(sector); + } + else + { + var sectorField = component?.GetType()?.GetField("_sector"); + if (sectorField != null && sectorField.FieldType == typeof(Sector)) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => sectorField.SetValue(component, sector)); + } - if(component is OWItemSocket) - { - (component as OWItemSocket)._sector = sector; + if (component is AnglerfishController) + { + try + { + (component as AnglerfishController)._chaseSpeed += OWPhysics.CalculateOrbitVelocity(planetGO.GetAttachedOWRigidbody(), planetGO.GetComponent().GetPrimaryBody().GetAttachedOWRigidbody()).magnitude; + } + catch (Exception e) + { + Logger.LogError($"Couldn't update AnglerFish chase speed: {e.Message}"); + } + } + + // Fix slide reel + if (component is SlideCollectionContainer) + { + sector.OnOccupantEnterSector.AddListener((_) => (component as SlideCollectionContainer).LoadStreamingTextures()); + } + + if (component is OWItemSocket) + { + (component as OWItemSocket)._sector = sector; + } } // Fix a bunch of stuff when done loading diff --git a/NewHorizons/External/PropModule.cs b/NewHorizons/External/PropModule.cs index 2bf7cbc3..8c4de295 100644 --- a/NewHorizons/External/PropModule.cs +++ b/NewHorizons/External/PropModule.cs @@ -20,6 +20,7 @@ namespace NewHorizons.External public EntryLocationInfo[] EntryLocation; public NomaiTextInfo[] NomaiText; public ProjectionInfo[] SlideShows; + public DetailInfo[] ProxyDetails; public class ScatterInfo { diff --git a/NewHorizons/schema.json b/NewHorizons/schema.json index 9ef93fd7..ad9ab075 100644 --- a/NewHorizons/schema.json +++ b/NewHorizons/schema.json @@ -112,6 +112,48 @@ "description": "Colour of the terrain." } } + }, + "detail": { + "type": "object", + "additionalProperties": false, + "properties": { + "path": { + "type": "string", + "description": "Either the path in the scene hierarchy of the item to copy or the path to the object in the supplied asset bundle" + }, + "assetBundle": { + "type": "string", + "description": "Relative filepath to an asset-bundle" + }, + "position": { + "$ref": "#/$defs/vector3" + }, + "rotation": { + "$ref": "#/$defs/vector3", + "description": "Euler angle degrees" + }, + "scale": { + "type": "number", + "default": 1 + }, + "alignToNormal": { + "type": "boolean", + "description": "Do we override rotation and try to automatically align this object to stand upright on the body's surface?", + "default": false + }, + "removeChildren": { + "type": "array", + "description": "A list of children to remove from this detail", + "items": { + "type": "string" + } + }, + "removeComponents": { + "type": "boolean", + "description": "Do we reset all the components on this object? Useful for certain props that have dialogue components attached to them.", + "default": false + } + } } }, "title": "Body", @@ -633,46 +675,7 @@ "details": { "type": "array", "items": { - "type": "object", - "additionalProperties": false, - "properties": { - "path": { - "type": "string", - "description": "Either the path in the scene hierarchy of the item to copy or the path to the object in the supplied asset bundle" - }, - "assetBundle": { - "type": "string", - "description": "Relative filepath to an asset-bundle" - }, - "position": { - "$ref": "#/$defs/vector3" - }, - "rotation": { - "$ref": "#/$defs/vector3", - "description": "Euler angle degrees" - }, - "scale": { - "type": "number", - "default": 1 - }, - "alignToNormal": { - "type": "boolean", - "description": "Do we override rotation and try to automatically align this object to stand upright on the body's surface?", - "default": false - }, - "removeChildren": { - "type": "array", - "description": "A list of children to remove from this detail", - "items": { - "type": "string" - } - }, - "removeComponents": { - "type": "boolean", - "description": "Do we reset all the components on this object? Useful for certain props that have dialogue components attached to them.", - "default": false - } - } + "$ref": "#/$defs/detail" } }, "dialogue": { @@ -1065,6 +1068,13 @@ } } } + }, + "proxyDetails": { + "type": "array", + "description": "Details which will be shown from 50km away. Meant to be lower resolution.", + "items": { + "$ref": "#/$defs/detail" + } } } },