diff --git a/Marshmallow/AddToUITable.cs b/Marshmallow/AddToUITable.cs index 0398c94d..3cf696c4 100644 --- a/Marshmallow/AddToUITable.cs +++ b/Marshmallow/AddToUITable.cs @@ -1,8 +1,5 @@ using OWML.ModHelper.Events; -using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using UnityEngine; namespace Marshmallow.UI diff --git a/Marshmallow/Main.cs b/Marshmallow/Main.cs index d66342aa..281c2e73 100644 --- a/Marshmallow/Main.cs +++ b/Marshmallow/Main.cs @@ -1,13 +1,9 @@ -using Newtonsoft.Json; -using OWML.Common; +using OWML.Common; using OWML.ModHelper; using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; using UnityEngine; -using UnityEngine.SceneManagement; namespace Marshmallow { @@ -31,8 +27,12 @@ namespace Marshmallow foreach (var file in Directory.GetFiles(ModHelper.Manifest.ModFolderPath + @"planets\")) { - var config = ModHelper.Storage.Load(file); + PlanetConfig config = ModHelper.Storage.Load(file.Replace(ModHelper.Manifest.ModFolderPath, "")); + planetList.Add(config); + + Log(config.GetSettingsValue("position").ToString()); + Log(config.GetSettingsValue("fogTint").ToString()); } if (planetList.Count != 0) @@ -54,52 +54,11 @@ namespace Marshmallow { var planet = GenerateBody(config); - if (config.GetSettingsValue("primaryBody") == Locator.GetAstroObject(AstroObject.Name.Sun)) - { - planet.transform.parent = Locator.GetRootTransform(); - } - else - { - planet.transform.parent = config.GetSettingsValue("primaryBody").transform; - } + planet.transform.parent = Locator.GetRootTransform(); planet.transform.position = config.GetSettingsValue("position"); planet.SetActive(true); } - - PlanetStructure inputStructure = new PlanetStructure - { - name = "Mister_Nebula's Custom Planet!", - - primaryBody = Locator.GetAstroObject(AstroObject.Name.Sun), - aoType = AstroObject.Type.Planet, - aoName = AstroObject.Name.InvisiblePlanet, - - position = new Vector3(0, 0, 30000), - - makeSpawnPoint = true, - - hasClouds = true, - topCloudSize = 650f, - bottomCloudSize = 600f, - cloudTint = new Color32(0, 75, 15, 128), - - hasWater = true, - waterSize = 401f, - - hasRain = true, - - hasGravity = true, - surfaceAccel = 12f, - - hasMapMarker = true, - - hasFog = true, - fogTint = new Color32(0, 75, 15, 128), - fogDensity = 0.75f, - - hasOrbit = true - }; } } @@ -111,7 +70,7 @@ namespace Marshmallow var name = config.GetSettingsValue("name"); var topCloudSize = config.GetSettingsValue("topCloudSize"); - var bottomCloudSize = config.GetSettingsValue("topCloudSize"); + var bottomCloudSize = config.GetSettingsValue("bottomCloudSize"); GameObject body; @@ -120,7 +79,7 @@ namespace Marshmallow Body.MakeGeometry.Make(body, groundScale); - General.MakeOrbitingAstroObject.Make(body, config.GetSettingsValue("primaryBody"), 0.02f, config.GetSettingsValue("hasGravity"), config.GetSettingsValue("surfaceAcceleration"), groundScale); + General.MakeOrbitingAstroObject.Make(body, 0.02f, config.GetSettingsValue("orbitAngle"), config.GetSettingsValue("hasGravity"), config.GetSettingsValue("surfaceAcceleration"), groundScale); General.MakeRFVolume.Make(body); if (config.GetSettingsValue("hasMapMarker")) @@ -132,7 +91,7 @@ namespace Marshmallow if (config.GetSettingsValue("hasClouds")) { - Atmosphere.MakeClouds.Make(body, topCloudSize, bottomCloudSize, config.GetSettingsValue("cloudTint")); + Atmosphere.MakeClouds.Make(body, topCloudSize, bottomCloudSize, config.GetSettingsValue("cloudTint")); Atmosphere.MakeSunOverride.Make(body, topCloudSize, bottomCloudSize, config.GetSettingsValue("waterSize")); } @@ -146,11 +105,11 @@ namespace Marshmallow Atmosphere.MakeBaseEffects.Make(body); Atmosphere.MakeVolumes.Make(body, groundScale, topCloudSize); General.MakeAmbientLight.Make(body); - Atmosphere.MakeAtmosphere.Make(body, topCloudSize, config.GetSettingsValue("hasFog"), config.GetSettingsValue("fogDensity"), config.GetSettingsValue("fogTint")); + Atmosphere.MakeAtmosphere.Make(body, topCloudSize, config.GetSettingsValue("hasFog"), config.GetSettingsValue("fogDensity"), config.GetSettingsValue("fogTint")); if (config.GetSettingsValue("makeSpawnPoint")) { - SPAWN = General.MakeSpawnPoint.Make(body, new Vector3(0, groundScale+10, 0)); + SPAWN = General.MakeSpawnPoint.Make(body, new Vector3(0, groundScale + 10, 0)); } Main.Log("Generation of planet [" + name + "] completed."); diff --git a/Marshmallow/MakeAmbientLight.cs b/Marshmallow/MakeAmbientLight.cs index 0ae0aa40..c9f1f37d 100644 --- a/Marshmallow/MakeAmbientLight.cs +++ b/Marshmallow/MakeAmbientLight.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; +using UnityEngine; namespace Marshmallow.General { diff --git a/Marshmallow/MakeAtmosphere.cs b/Marshmallow/MakeAtmosphere.cs index 0d2404f5..2011d464 100644 --- a/Marshmallow/MakeAtmosphere.cs +++ b/Marshmallow/MakeAtmosphere.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; +using UnityEngine; namespace Marshmallow.Atmosphere { @@ -101,7 +97,7 @@ namespace Marshmallow.Atmosphere lodg.SetLODs(lodlist); lodg.fadeMode = LODFadeMode.None; */ - + //atmo.SetActive(true); atmoM.SetActive(true); } diff --git a/Marshmallow/MakeBaseEffects.cs b/Marshmallow/MakeBaseEffects.cs index f6bd948a..61c7245a 100644 --- a/Marshmallow/MakeBaseEffects.cs +++ b/Marshmallow/MakeBaseEffects.cs @@ -1,9 +1,5 @@ using OWML.ModHelper.Events; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; using UnityEngine; namespace Marshmallow.Atmosphere diff --git a/Marshmallow/MakeClouds.cs b/Marshmallow/MakeClouds.cs index c8625e1c..1d037341 100644 --- a/Marshmallow/MakeClouds.cs +++ b/Marshmallow/MakeClouds.cs @@ -14,7 +14,7 @@ namespace Marshmallow.Atmosphere GameObject cloudsTop = new GameObject(); cloudsTop.SetActive(false); cloudsTop.transform.parent = cloudsMain.transform; - cloudsTop.transform.localScale = new Vector3(topCloudScale/2, topCloudScale/2, topCloudScale/2); + cloudsTop.transform.localScale = new Vector3(topCloudScale / 2, topCloudScale / 2, topCloudScale / 2); MeshFilter MF = cloudsTop.AddComponent(); MF.mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; @@ -22,6 +22,11 @@ namespace Marshmallow.Atmosphere MeshRenderer MR = cloudsTop.AddComponent(); MR.materials = GameObject.Find("CloudsTopLayer_GD").GetComponent().materials; + foreach (var item in MR.materials) + { + item.SetColor("_Color", cloudTint.Value); + } + RotateTransform RT = cloudsTop.AddComponent(); RT.SetValue("_localAxis", Vector3.up); RT.SetValue("degreesPerSecond", 10); @@ -39,7 +44,7 @@ namespace Marshmallow.Atmosphere GameObject cloudsBottom = new GameObject(); cloudsBottom.SetActive(false); cloudsBottom.transform.parent = cloudsMain.transform; - cloudsBottom.transform.localScale = new Vector3(bottomCloudScale/2, bottomCloudScale/2, bottomCloudScale/2); + cloudsBottom.transform.localScale = new Vector3(bottomCloudScale / 2, bottomCloudScale / 2, bottomCloudScale / 2); TessellatedSphereRenderer TSR = cloudsBottom.AddComponent(); TSR.tessellationMeshGroup = GameObject.Find("CloudsBottomLayer_GD").GetComponent().tessellationMeshGroup; @@ -64,7 +69,7 @@ namespace Marshmallow.Atmosphere SphereCollider cloudSC = cloudsFluid.AddComponent(); cloudSC.isTrigger = true; - cloudSC.radius = topCloudScale/2; + cloudSC.radius = topCloudScale / 2; OWShellCollider cloudShell = cloudsFluid.AddComponent(); cloudShell.SetValue("_innerRadius", bottomCloudScale); @@ -82,7 +87,7 @@ namespace Marshmallow.Atmosphere cloudsFluid.SetActive(true); cloudsMain.SetActive(true); - Main.Log("Clouds - topCloudScale : " + topCloudScale + ", bottomCloudScale : " + bottomCloudScale + ", cloudTint : " + cloudTint); + //Main.Log("Clouds - topCloudScale : " + topCloudScale + ", bottomCloudScale : " + bottomCloudScale + ", cloudTint : " + cloudTint); } } } diff --git a/Marshmallow/MakeGeometry.cs b/Marshmallow/MakeGeometry.cs index ea21daaa..d155b941 100644 --- a/Marshmallow/MakeGeometry.cs +++ b/Marshmallow/MakeGeometry.cs @@ -1,9 +1,4 @@ -using OWML.Common; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; +using UnityEngine; namespace Marshmallow.Body { diff --git a/Marshmallow/MakeOrbitingAstroObject.cs b/Marshmallow/MakeOrbitingAstroObject.cs index d50f4c78..e109c066 100644 --- a/Marshmallow/MakeOrbitingAstroObject.cs +++ b/Marshmallow/MakeOrbitingAstroObject.cs @@ -5,7 +5,7 @@ namespace Marshmallow.General { static class MakeOrbitingAstroObject { - public static void Make(GameObject body, AstroObject primaryBody, float angularSpeed, bool hasGravity, float surfaceAccel, float groundSize) + public static void Make(GameObject body, float angularSpeed, float orbitAngle, bool hasGravity, float surfaceAccel, float groundSize) { Rigidbody RB = body.AddComponent(); RB.mass = 10000; @@ -23,8 +23,8 @@ namespace Marshmallow.General Main.OWRB.SetValue("_maintainOriginalCenterOfMass", true); InitialMotion IM = body.AddComponent(); - IM.SetPrimaryBody(primaryBody.GetAttachedOWRigidbody()); - IM.SetValue("_orbitAngle", 0f); + IM.SetPrimaryBody(Locator.GetAstroObject(AstroObject.Name.Sun).GetAttachedOWRigidbody()); + IM.SetValue("_orbitAngle", orbitAngle); IM.SetValue("_isGlobalAxis", false); IM.SetValue("_initAngularSpeed", angularSpeed); IM.SetValue("_initLinearSpeed", 0f); @@ -40,8 +40,8 @@ namespace Marshmallow.General AstroObject AO = body.AddComponent(); AO.SetValue("_type", AstroObject.Type.Planet); - AO.SetValue("_name", AstroObject.Name.InvisiblePlanet); - AO.SetPrimaryBody(primaryBody); + AO.SetValue("_name", AstroObject.Name.None); + AO.SetPrimaryBody(Locator.GetAstroObject(AstroObject.Name.Sun)); if (hasGravity) { GravityVolume GV = MakeGravityWell.Make(body, surfaceAccel, groundSize, groundSize); diff --git a/Marshmallow/MakeSpawnPoint.cs b/Marshmallow/MakeSpawnPoint.cs index 921b69af..3c0b9763 100644 --- a/Marshmallow/MakeSpawnPoint.cs +++ b/Marshmallow/MakeSpawnPoint.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; +using UnityEngine; namespace Marshmallow.General { @@ -16,7 +12,7 @@ namespace Marshmallow.General spawn.transform.localPosition = position; - Main.Log("Made spawnpoint on [" + body.name + "] at " + position); + //Main.Log("Made spawnpoint on [" + body.name + "] at " + position); return spawn.AddComponent(); } diff --git a/Marshmallow/MakeSunOverride.cs b/Marshmallow/MakeSunOverride.cs index 7082236e..d8eef200 100644 --- a/Marshmallow/MakeSunOverride.cs +++ b/Marshmallow/MakeSunOverride.cs @@ -13,9 +13,9 @@ namespace Marshmallow.Atmosphere GiantsDeepSunOverrideVolume vol = sunov.AddComponent(); vol.SetValue("_sector", Main.SECTOR); - vol.SetValue("_cloudsOuterRadius", topCloudScale/2); - vol.SetValue("_cloudsInnerRadius", bottomCloudScale/2); - vol.SetValue("_waterOuterRadius", waterSize/2); + vol.SetValue("_cloudsOuterRadius", topCloudScale / 2); + vol.SetValue("_cloudsInnerRadius", bottomCloudScale / 2); + vol.SetValue("_waterOuterRadius", waterSize / 2); vol.SetValue("_waterInnerRadius", 402.5f); sunov.SetActive(true); diff --git a/Marshmallow/MakeVolumes.cs b/Marshmallow/MakeVolumes.cs index 49654a8d..f0ae9cae 100644 --- a/Marshmallow/MakeVolumes.cs +++ b/Marshmallow/MakeVolumes.cs @@ -1,8 +1,4 @@ using OWML.ModHelper.Events; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using UnityEngine; namespace Marshmallow.Atmosphere diff --git a/Marshmallow/MakeWater.cs b/Marshmallow/MakeWater.cs index b277e5c0..67989e87 100644 --- a/Marshmallow/MakeWater.cs +++ b/Marshmallow/MakeWater.cs @@ -32,7 +32,7 @@ namespace Marshmallow.Body GameObject fog1 = new GameObject(); fog1.transform.parent = waterBase.transform; - fog1.transform.localScale = new Vector3(1,1,1); + fog1.transform.localScale = new Vector3(1, 1, 1); fog1.AddComponent().mesh = GameObject.Find("CloudsTopLayer_GD").GetComponent().mesh; fog1.AddComponent().material = new Material(Shader.Find("Sprites/Default")); fog1.GetComponent().material.color = new Color32(0, 75, 50, 5); @@ -53,7 +53,7 @@ namespace Marshmallow.Body waterBase.SetActive(true); - Main.Log("Water - waterScale : " + waterScale); + //Main.Log("Water - waterScale : " + waterScale); } } } diff --git a/Marshmallow/Marshmallow.csproj b/Marshmallow/Marshmallow.csproj index a5d1585e..52da6c89 100644 --- a/Marshmallow/Marshmallow.csproj +++ b/Marshmallow/Marshmallow.csproj @@ -112,7 +112,6 @@ - diff --git a/Marshmallow/PlanetConfig.cs b/Marshmallow/PlanetConfig.cs index 01e0d888..9f045f97 100644 --- a/Marshmallow/PlanetConfig.cs +++ b/Marshmallow/PlanetConfig.cs @@ -3,18 +3,17 @@ using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; -using System.Text; +using UnityEngine; namespace Marshmallow { - class PlanetConfig - { - [JsonProperty("settings")] - public Dictionary Settings { get; set; } = new Dictionary(); + class PlanetConfig + { + [JsonProperty("settings")] + public Dictionary Settings { get; set; } = new Dictionary(); public T GetSettingsValue(string key) { - Main.Log("start"); bool flag = !this.Settings.ContainsKey(key); T result; if (flag) @@ -29,7 +28,47 @@ namespace Marshmallow { JObject jobject; object value = ((jobject = (obj as JObject)) != null) ? jobject["value"] : obj; - result = (T)((object)Convert.ChangeType(value, typeof(T))); + + if (obj.GetType() == typeof(JArray)) + { + if (typeof(T) == typeof(Vector2)) + { + JArray array = (JArray)obj; + float[] items = array.Select(jv => (float)jv).ToArray(); + Vector2 output = new Vector2(items[0], items[1]); + + return (T)Convert.ChangeType(output, typeof(T)); + } + + if (typeof(T) == typeof(Vector3)) + { + JArray array = (JArray)obj; + float[] items = array.Select(jv => (float)jv).ToArray(); + Vector3 output = new Vector3(items[0], items[1], items[2]); + + return (T)Convert.ChangeType(output, typeof(T)); + } + + if (typeof(T) == typeof(Vector4) || typeof(T) == typeof(Color)) + { + JArray array = (JArray)obj; + float[] items = array.Select(jv => (float)jv).ToArray(); + Vector4 output = new Vector4(items[0], items[1], items[2], items[3]); + + return (T)Convert.ChangeType(output, typeof(T)); + } + + if (typeof(T) == typeof(Color32)) + { + JArray array = (JArray)obj; + byte[] items = array.Select(jv => (byte)jv).ToArray(); + Color32 output = new Color32(items[0], items[1], items[2], items[3]); + + return (T)Convert.ChangeType(output, typeof(T)); + } + } + + result = (T)Convert.ChangeType(value, typeof(T)); } catch (InvalidCastException) { diff --git a/Marshmallow/PlanetStructure.cs b/Marshmallow/PlanetStructure.cs deleted file mode 100644 index ee584501..00000000 --- a/Marshmallow/PlanetStructure.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using UnityEngine; - -namespace Marshmallow -{ - public class PlanetStructure - { - public string name; - - public AstroObject primaryBody; - public AstroObject.Type aoType; - public AstroObject.Name aoName; - - public Vector3 position; - - public bool makeSpawnPoint = false; - - public bool hasClouds = false; - public float? topCloudSize = null; - public float? bottomCloudSize = null; - public Color? cloudTint = null; - - public bool hasWater = false; - public float? waterSize = null; - - public bool hasRain = false; - - public bool hasGravity = false; - public float surfaceAccel = 1f; - - public bool hasMapMarker = false; - - public bool hasFog = false; - public Color fogTint = Color.white; - public float fogDensity = 0.3f; - - public bool hasOrbit = false; - } -} diff --git a/Marshmallow/Properties/AssemblyInfo.cs b/Marshmallow/Properties/AssemblyInfo.cs index 51474b26..18162c07 100644 --- a/Marshmallow/Properties/AssemblyInfo.cs +++ b/Marshmallow/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following