diff --git a/Marshmallow/AddToUITable.cs b/Marshmallow/AddToUITable.cs new file mode 100644 index 00000000..0398c94d --- /dev/null +++ b/Marshmallow/AddToUITable.cs @@ -0,0 +1,23 @@ +using OWML.ModHelper.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEngine; + +namespace Marshmallow.UI +{ + static class AddToUITable + { + public static int Add(string text) + { + TextTranslation.TranslationTable instance = GameObject.FindObjectOfType().GetValue("m_table"); + + instance.Insert_UI(instance.theUITable.Keys.Max() + 1, text); + + Main.Log("Added [" + text + "] to UI table with key [" + instance.theUITable.Keys.Max() + "]"); + + return instance.theUITable.Keys.Max(); + } + } +} diff --git a/Marshmallow/Main.cs b/Marshmallow/Main.cs index 8542aa7d..60a0cf83 100644 --- a/Marshmallow/Main.cs +++ b/Marshmallow/Main.cs @@ -1,7 +1,9 @@ -using OWML.Common; +using Newtonsoft.Json; +using OWML.Common; using OWML.ModHelper; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using UnityEngine; @@ -18,6 +20,8 @@ namespace Marshmallow public static IModHelper helper; + static List planetList = new List(); + void Start() { base.ModHelper.Events.Subscribe(Events.AfterStart); @@ -25,6 +29,13 @@ namespace Marshmallow events.OnEvent = (Action)Delegate.Combine(events.OnEvent, new Action(this.OnEvent)); helper = base.ModHelper; + + foreach (var file in Directory.GetFiles(ModHelper.Manifest.ModFolderPath + @"planets\")) + { + planetList.Add(ModHelper.Storage.Load(file)); + } + + Main.Log("Loaded [" + planetList.Count + "] planet config files."); } private void OnEvent(MonoBehaviour behaviour, Events ev) @@ -32,9 +43,14 @@ namespace Marshmallow bool flag = behaviour.GetType() == typeof(Flashlight) && ev == Events.AfterStart; if (flag) { + foreach (var config in planetList) + { + var planet = GenerateBody(config); + } + PlanetStructure inputStructure = new PlanetStructure { - name = "invisibleplanet", + name = "Mister_Nebula's Custom Planet!", primaryBody = Locator.GetAstroObject(AstroObject.Name.Sun), aoType = AstroObject.Type.Planet, @@ -82,8 +98,10 @@ namespace Marshmallow } } - private GameObject GenerateBody(PlanetStructure planet) + private GameObject GenerateBody(PlanetConfig config) { + Main.Log("Begin generation sequence of planet [" + planet.name + "] ..."); + float groundScale = 400f; GameObject body; @@ -99,7 +117,7 @@ namespace Marshmallow if (planet.hasMapMarker) { - General.MakeMapMarker.Make(body); + General.MakeMapMarker.Make(body, planet.name); } SECTOR = Body.MakeSector.Make(body, planet.topCloudSize.Value); @@ -127,6 +145,8 @@ namespace Marshmallow SPAWN = General.MakeSpawnPoint.Make(body, new Vector3(0, groundScale+10, 0)); } + Main.Log("Generation of planet [" + planet.name + "] completed."); + return body; } diff --git a/Marshmallow/MakeMapMarker.cs b/Marshmallow/MakeMapMarker.cs index cf7f4f52..947dc32f 100644 --- a/Marshmallow/MakeMapMarker.cs +++ b/Marshmallow/MakeMapMarker.cs @@ -6,11 +6,13 @@ namespace Marshmallow.General { static class MakeMapMarker { - public static void Make(GameObject body) + public static void Make(GameObject body, string name) { var MM = body.AddComponent(); - MM.SetValue("_labelID", UITextType.YouAreDeadMessage); + MM.SetValue("_labelID", (UITextType)UI.AddToUITable.Add(name)); MM.SetValue("_markerType", MM.GetType().GetNestedType("MarkerType", BindingFlags.NonPublic).GetField("Planet").GetValue(MM)); + + Main.Log("Map Marker - body : " + body.name + ", labelID : " + name); } } } diff --git a/Marshmallow/Marshmallow.csproj b/Marshmallow/Marshmallow.csproj index 4b6ac830..5ca8c9f4 100644 --- a/Marshmallow/Marshmallow.csproj +++ b/Marshmallow/Marshmallow.csproj @@ -93,20 +93,25 @@ - + + + + + + diff --git a/Marshmallow/PlanetConfig.cs b/Marshmallow/PlanetConfig.cs new file mode 100644 index 00000000..dbdf1a04 --- /dev/null +++ b/Marshmallow/PlanetConfig.cs @@ -0,0 +1,43 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Marshmallow +{ + class PlanetConfig + { + [JsonProperty("settings")] + public Dictionary Settings { get; set; } = new Dictionary(); + + public T GetSettingsValue(string key) + { + bool flag = !this.Settings.ContainsKey(key); + T result; + if (flag) + { + Main.Log("Error: setting not found: " + key); + result = default(T); + } + else + { + object obj = this.Settings[key]; + try + { + JObject jobject; + object value = ((jobject = (obj as JObject)) != null) ? jobject["value"] : obj; + result = (T)((object)Convert.ChangeType(value, typeof(T))); + } + catch (InvalidCastException) + { + Main.Log(string.Format("Error when converting setting {0} of type {1} to type {2}", key, obj.GetType(), typeof(T))); + result = default(T); + } + } + return result; + } + + } +}