diff --git a/NewHorizons/Builder/Body/FunnelBuilder.cs b/NewHorizons/Builder/Body/FunnelBuilder.cs new file mode 100644 index 00000000..b840c727 --- /dev/null +++ b/NewHorizons/Builder/Body/FunnelBuilder.cs @@ -0,0 +1,77 @@ +using NewHorizons.External.VariableSize; +using NewHorizons.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Builder.Body +{ + public static class FunnelBuilder + { + private enum FunnelType + { + SAND, + WATER, + LAVA, + STAR + } + + public static void Make(GameObject go, ConstantForceDetector detector, FunnelModule module) + { + var funnelType = FunnelType.SAND; + if (module.Type.ToUpper().Equals("WATER")) funnelType = FunnelType.WATER; + else if (module.Type.ToUpper().Equals("LAVA")) funnelType = FunnelType.LAVA; + else if (module.Type.ToUpper().Equals("STAR")) funnelType = FunnelType.STAR; + + var funnelGO = new GameObject($"{go.name.Replace("_Body", "")}Funnel_Body"); + funnelGO.SetActive(false); + + var owrb = funnelGO.AddComponent(); + var alignment = funnelGO.AddComponent(); + Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => alignment.SetTargetBody(AstroObjectLocator.GetAstroObject(module.Target)?.GetAttachedOWRigidbody())); + funnelGO.AddComponent(); + funnelGO.AddComponent(); + funnelGO.AddComponent(); + funnelGO.AddComponent(); + + var detectorGO = new GameObject("Detector_Funnel"); + detectorGO.transform.parent = funnelGO.transform; + var funnelDetector = detectorGO.AddComponent(); + funnelDetector._inheritDetector = detector; + + detectorGO.AddComponent(); + + var scaleRoot = new GameObject("ScaleRoot"); + scaleRoot.transform.parent = go.transform; + + var proxyGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Proxy_SandFunnel"), scaleRoot.transform); + proxyGO.name = "Proxy_Funnel"; + + var geoGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Geo_SandFunnel"), scaleRoot.transform); + geoGO.name = "Geo_Funnel"; + + var volumesGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Volumes_SandFunnel"), scaleRoot.transform); + volumesGO.name = "Volumes_Funnel"; + var sfv = volumesGO.GetComponent(); + switch(funnelType) + { + case FunnelType.SAND: + sfv._fluidType = FluidVolume.Type.SAND; + break; + case FunnelType.WATER: + sfv._fluidType = FluidVolume.Type.WATER; + break; + case FunnelType.LAVA: + sfv._fluidType = FluidVolume.Type.PLASMA; + break; + case FunnelType.STAR: + sfv._fluidType = FluidVolume.Type.PLASMA; + break; + } + + } + } +} diff --git a/NewHorizons/External/IPlanetConfig.cs b/NewHorizons/External/IPlanetConfig.cs index 822190af..5018b230 100644 --- a/NewHorizons/External/IPlanetConfig.cs +++ b/NewHorizons/External/IPlanetConfig.cs @@ -25,5 +25,6 @@ namespace NewHorizons.External LavaModule Lava { get; } SandModule Sand { get; } WaterModule Water { get; } + FunnelModule Funnel { get; } } } diff --git a/NewHorizons/External/PlanetConfig.cs b/NewHorizons/External/PlanetConfig.cs index f3418d86..8aeca491 100644 --- a/NewHorizons/External/PlanetConfig.cs +++ b/NewHorizons/External/PlanetConfig.cs @@ -28,6 +28,7 @@ namespace NewHorizons.External public LavaModule Lava { get; set; } public WaterModule Water { get; set; } public SandModule Sand { get; set; } + public FunnelModule Funnel { get; set; } public PlanetConfig(Dictionary dict) { diff --git a/NewHorizons/External/VariableSize/FunnelModule.cs b/NewHorizons/External/VariableSize/FunnelModule.cs new file mode 100644 index 00000000..cba7de4b --- /dev/null +++ b/NewHorizons/External/VariableSize/FunnelModule.cs @@ -0,0 +1,16 @@ +using NewHorizons.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External.VariableSize +{ + public class FunnelModule : VariableSizeModule + { + public string Target { get; set; } + public string Type { get; set; } = "Sand"; + public MColor32 Tint { get; set; } + } +} diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index f0fab029..0999e57a 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -489,6 +489,9 @@ namespace NewHorizons if (!body.Config.Orbit.IsStatic) DetectorBuilder.Make(go, owRigidBody, primaryBody, ao); + if (body.Config.Funnel != null) + FunnelBuilder.Make(go, go.GetComponentInChildren(), body.Config.Funnel); + if (ao.GetAstroObjectName() == AstroObject.Name.CustomString) AstroObjectLocator.RegisterCustomAstroObject(ao); HeavenlyBodyBuilder.Make(go, body.Config, sphereOfInfluence, gv, initialMotion); diff --git a/NewHorizons/schema.json b/NewHorizons/schema.json index d91d11d8..f07dea64 100644 --- a/NewHorizons/schema.json +++ b/NewHorizons/schema.json @@ -228,7 +228,7 @@ "description": "The average distance between the planet and its primary body." }, "inclination": { - "type": "integer", + "type": "number", "default": 0, "description": "The angle (in degrees) between the body's orbit and the plane of the star system" }, @@ -989,6 +989,70 @@ } } } + }, + "Funnel": { + "type": "object", + "properties": { + "target": { + "type": "string", + "description": "The body that the funnel is pouring onto" + }, + "type": { + "type": "string", + "enum": [ + "Sand", + "Water", + "Lava", + "Star" + ], + "default": "Sand" + } + "tint": { + "type": "object", + "properties": { + "R": { + "type": "integer", + "default": 0, + "minimum": 0, + "maximum": 255 + }, + "G": { + "type": "integer", + "default": 0, + "minimum": 0, + "maximum": 255 + }, + "B": { + "type": "integer", + "default": 0, + "minimum": 0, + "maximum": 255 + }, + "A": { + "type": "integer", + "default": 0, + "minimum": 0, + "maximum": 255 + } + } + }, + "curve": { + "type": "array", + "items": { + "type": "object", + "properties": { + "time": { + "type": "integer", + "default": 0 + }, + "value": { + "type": "integer", + "default": 0 + } + } + } + } + } } } } \ No newline at end of file