diff --git a/SEWorldGenPlugin/GUI/PluginSettingsGui.cs b/SEWorldGenPlugin/GUI/PluginSettingsGui.cs index b1bbff8..28c8cc4 100644 --- a/SEWorldGenPlugin/GUI/PluginSettingsGui.cs +++ b/SEWorldGenPlugin/GUI/PluginSettingsGui.cs @@ -2,11 +2,10 @@ using Sandbox.Game.Localization; using Sandbox.Graphics.GUI; using SEWorldGenPlugin.ObjectBuilders; -using SEWorldGenPlugin.Utilities; -using SEWorldGenPlugin.Utilities.SEWorldGenPlugin.Utilities; using System; using VRage.Utils; using VRageMath; +using SEWorldGenPlugin.Utilities; namespace SEWorldGenPlugin.GUI { @@ -19,6 +18,7 @@ public class PluginSettingsGui : MyGuiScreenBase private MyGuiControlLabel m_sizeCapLabel; private MyGuiControlLabel m_moonProbLabel; private MyGuiControlLabel m_ringWidthLabel; + private MyGuiControlLabel m_ringProbLabel; private MyGuiControlLabel m_beltHeightLabel; private MyGuiControlLabel m_beltProbLabel; @@ -28,6 +28,7 @@ public class PluginSettingsGui : MyGuiScreenBase private MyGuiControlLabel m_sizeCapValue; private MyGuiControlLabel m_moonProbValue; private MyGuiControlLabel m_ringWidthValue; + private MyGuiControlLabel m_ringProbValue; private MyGuiControlLabel m_beltHeightValue; private MyGuiControlLabel m_beltProbValue; @@ -38,6 +39,7 @@ public class PluginSettingsGui : MyGuiScreenBase private MyGuiControlSlider m_sizeCapSlider; private MyGuiControlSlider m_moonProbSlider; private MyGuiControlSlider m_ringWidthSlider; + private MyGuiControlSlider m_ringProbSlider; private MyGuiControlSlider m_beltHeightSlider; private MyGuiControlSlider m_beltProbSlider; @@ -82,18 +84,20 @@ public void BuildControls() m_sizeCapLabel = MakeLabel("Planet size cap"); m_moonProbLabel = MakeLabel("Moon spawn probability"); m_ringWidthLabel = MakeLabel("Average ring width"); + m_ringProbLabel = MakeLabel("Ring spawn probability"); m_beltHeightLabel = MakeLabel("Average belt height"); m_beltProbLabel = MakeLabel("Belt spawn probability"); m_useGlobalCheck = new MyGuiControlCheckbox(); - m_objAmountSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 100f, x2, 15f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.SYS_OBJ_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true); - m_orbDistanceSlider = new MyGuiControlSlider(Vector2.Zero, 1000f, 100000f, x2, 50500f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.ORB_DIST_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true); - m_sizeMultiplierSlider = new MyGuiControlSlider(Vector2.Zero, 1f, 10f, x2, 2f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.SIZE_MUL_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true); - m_sizeCapSlider = new MyGuiControlSlider(Vector2.Zero, 120f, 2400f, x2, 1200f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.SIZE_CAP_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true); - m_moonProbSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 1f, x2, 0.5f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.MOON_PROB_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: false); - m_ringWidthSlider = new MyGuiControlSlider(Vector2.Zero, 1000f, 10000f, x2, 5000f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.RING_WIDTH_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true); - m_beltHeightSlider = new MyGuiControlSlider(Vector2.Zero, 4000f, 40000f, x2, 22000f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.BELT_HEIGHT_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true); - m_beltProbSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 1f, x2, 0.4f, null, null, 0, 0.8f, 0.05f, "White", MyTexts.TOOLTIPS.BELT_PROB_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: false); + m_objAmountSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 100f, x2, 15f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.SYS_OBJ_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true); + m_orbDistanceSlider = new MyGuiControlSlider(Vector2.Zero, 1000f, 100000f, x2, 50500f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.ORB_DIST_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true); + m_sizeMultiplierSlider = new MyGuiControlSlider(Vector2.Zero, 1f, 10f, x2, 2f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.SIZE_MUL_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true); + m_sizeCapSlider = new MyGuiControlSlider(Vector2.Zero, 120f, 2400f, x2, 1200f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.SIZE_CAP_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true); + m_moonProbSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 1f, x2, 0.5f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.MOON_PROB_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: false); + m_ringWidthSlider = new MyGuiControlSlider(Vector2.Zero, 10000f, 100000f, x2, 15000f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.RING_WIDTH_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true); + m_ringProbSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 1f, x2, 0.5f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.RING_PROB_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: false); + m_beltHeightSlider = new MyGuiControlSlider(Vector2.Zero, 4000f, 40000f, x2, 22000f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.BELT_HEIGHT_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: true); + m_beltProbSlider = new MyGuiControlSlider(Vector2.Zero, 0f, 1f, x2, 0.4f, null, null, 0, 0.8f, 0.05f, "White", MyPluginTexts.TOOLTIPS.BELT_PROB_SLIDER, MyGuiControlSliderStyleEnum.Default, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, intValue: false); m_objAmountValue = MakeLabel(m_objAmountSlider.Value.ToString()); m_objAmountValue.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER; @@ -107,12 +111,14 @@ public void BuildControls() m_moonProbValue.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER; m_ringWidthValue = MakeLabel(m_ringWidthSlider.Value.ToString()); m_ringWidthValue.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER; + m_ringProbValue = MakeLabel(m_ringProbSlider.Value.ToString()); + m_ringProbValue.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER; m_beltHeightValue = MakeLabel(m_beltHeightSlider.Value.ToString()); m_beltHeightValue.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER; m_beltProbValue = MakeLabel(String.Format("{0:0.00}", m_beltProbSlider.Value)); m_beltProbValue.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER; - m_useGlobalCheck.SetToolTip(MyTexts.TOOLTIPS.USE_GLOBAL_CHECK); + m_useGlobalCheck.SetToolTip(MyPluginTexts.TOOLTIPS.USE_GLOBAL_CHECK); m_useGlobalCheck.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER; m_objAmountSlider.ValueChanged = (Action)Delegate.Combine(m_objAmountSlider.ValueChanged, (Action)delegate (MyGuiControlSlider s) @@ -139,13 +145,17 @@ public void BuildControls() { m_ringWidthValue.Text = s.Value.ToString(); }); + m_ringProbSlider.ValueChanged = (Action)Delegate.Combine(m_ringProbSlider.ValueChanged, (Action)delegate (MyGuiControlSlider s) + { + m_ringProbValue.Text = String.Format("{0:0.00}", s.Value); + }); m_beltHeightSlider.ValueChanged = (Action)Delegate.Combine(m_beltHeightSlider.ValueChanged, (Action)delegate (MyGuiControlSlider s) { m_beltHeightValue.Text = s.Value.ToString(); }); m_beltProbSlider.ValueChanged = (Action)Delegate.Combine(m_beltProbSlider.ValueChanged, (Action)delegate (MyGuiControlSlider s) { - m_beltProbValue.Text = String.Format("{0:0.00}", s.Value); ; + m_beltProbValue.Text = String.Format("{0:0.000}", s.Value); ; }); m_useGlobalCheck.IsCheckedChanged = (Action)Delegate.Combine(m_useGlobalCheck.IsCheckedChanged, (Action)delegate (MyGuiControlCheckbox s) { @@ -155,6 +165,7 @@ public void BuildControls() m_sizeCapSlider.Enabled = !s.IsChecked; m_moonProbSlider.Enabled = !s.IsChecked; m_ringWidthSlider.Enabled = !s.IsChecked; + m_ringProbSlider.Enabled = !s.IsChecked; m_beltHeightSlider.Enabled = !s.IsChecked; m_beltProbSlider.Enabled = !s.IsChecked; }); @@ -186,6 +197,10 @@ public void BuildControls() Controls.Add(m_ringWidthSlider); Controls.Add(m_ringWidthValue); + Controls.Add(m_ringProbLabel); + Controls.Add(m_ringProbSlider); + Controls.Add(m_ringProbValue); + Controls.Add(m_beltHeightLabel); Controls.Add(m_beltHeightSlider); Controls.Add(m_beltHeightValue); @@ -226,11 +241,15 @@ public void BuildControls() m_ringWidthSlider.Position = m_ringWidthLabel.Position + offset2; m_ringWidthValue.Position = m_ringWidthLabel.Position + offset3; - m_beltHeightLabel.Position = start + offset * 7; + m_ringProbLabel.Position = start + offset * 7; + m_ringProbSlider.Position = m_ringProbLabel.Position + offset2; + m_ringProbValue.Position = m_ringProbLabel.Position + offset3; + + m_beltHeightLabel.Position = start + offset * 8; m_beltHeightSlider.Position = m_beltHeightLabel.Position + offset2; m_beltHeightValue.Position = m_beltHeightLabel.Position + offset3; - m_beltProbLabel.Position = start + offset * 8; + m_beltProbLabel.Position = start + offset * 9; m_beltProbSlider.Position = m_beltProbLabel.Position + offset2; m_beltProbValue.Position = m_beltProbLabel.Position + offset3; @@ -262,6 +281,8 @@ public void SetSettings(MyObjectBuilder_PluginSettings settings, bool useGlobal) m_ringWidthSlider.Value = (settings.GeneratorSettings.PlanetSettings.RingSettings.MinPlanetRingWidth + settings.GeneratorSettings.PlanetSettings.RingSettings.MaxPlanetRingWidth) / 2; + m_ringProbSlider.Value = settings.GeneratorSettings.PlanetSettings.RingSettings.PlanetRingProbability; + m_beltHeightSlider.Value = (settings.GeneratorSettings.BeltSettings.MinBeltHeight + settings.GeneratorSettings.BeltSettings.MaxBeltHeight) / 2; } @@ -282,6 +303,7 @@ public bool GetSettings(ref MyObjectBuilder_PluginSettings settings) settings.GeneratorSettings.PlanetSettings.RingSettings.MinPlanetRingWidth = (int)m_ringWidthSlider.Value / 10; settings.GeneratorSettings.PlanetSettings.RingSettings.MaxPlanetRingWidth = (int)m_ringWidthSlider.Value * 2 - settings.GeneratorSettings.PlanetSettings.RingSettings.MinPlanetRingWidth; + settings.GeneratorSettings.PlanetSettings.RingSettings.PlanetRingProbability = m_ringProbSlider.Value; settings.GeneratorSettings.BeltSettings.MinBeltHeight = (int)m_beltHeightSlider.Value / 10; settings.GeneratorSettings.BeltSettings.MaxBeltHeight = (int)m_beltHeightSlider.Value * 2 - settings.GeneratorSettings.BeltSettings.MinBeltHeight; diff --git a/SEWorldGenPlugin/GUI/PluginWorldSettings.cs b/SEWorldGenPlugin/GUI/PluginWorldSettings.cs index b52a9de..0d1e0d8 100644 --- a/SEWorldGenPlugin/GUI/PluginWorldSettings.cs +++ b/SEWorldGenPlugin/GUI/PluginWorldSettings.cs @@ -5,7 +5,7 @@ using Sandbox.Graphics.GUI; using SEWorldGenPlugin.ObjectBuilders; using SEWorldGenPlugin.Session; -using SEWorldGenPlugin.Utilities.SEWorldGenPlugin.Utilities; +using SEWorldGenPlugin.Utilities; using System; using System.IO; using System.Text; diff --git a/SEWorldGenPlugin/Generator/Asteroids/AsteroidRingShape.cs b/SEWorldGenPlugin/Generator/Asteroids/AsteroidRingShape.cs index 0e8c632..d87e17a 100644 --- a/SEWorldGenPlugin/Generator/Asteroids/AsteroidRingShape.cs +++ b/SEWorldGenPlugin/Generator/Asteroids/AsteroidRingShape.cs @@ -51,7 +51,7 @@ public ContainmentType Contains(Vector3D point) private double GetHeightAtRad(double rad) { if (rad < radius || rad > radius + width) throw new ArgumentOutOfRangeException("The radius " + rad + " has to be less than " + (radius + width) + " and larger than " + radius); - return Math.Sin((rad - radius) * Math.PI / width) * Math.Sin((rad - radius) * Math.PI / width) * 0.5 * height + 1;//Plus one to make asteroids on edges possible + return Math.Sin((rad - radius) * Math.PI / width) * Math.Sin((rad - radius) * Math.PI / width) * 0.5 * height + 100;//Plus 100 to make asteroids on edges possible } } } diff --git a/SEWorldGenPlugin/Generator/SystemGenerator.cs b/SEWorldGenPlugin/Generator/SystemGenerator.cs index 4758002..41698c1 100644 --- a/SEWorldGenPlugin/Generator/SystemGenerator.cs +++ b/SEWorldGenPlugin/Generator/SystemGenerator.cs @@ -6,7 +6,7 @@ using Sandbox.ModAPI; using SEWorldGenPlugin.ObjectBuilders; using SEWorldGenPlugin.Session; -using SEWorldGenPlugin.Utilities.SEWorldGenPlugin.Utilities; +using SEWorldGenPlugin.Utilities; using System; using System.Collections.Generic; using System.Linq; @@ -106,7 +106,7 @@ private void GenerateSystem() int distToPrev = MyRandom.Instance.Next(m_settings.MinOrbitDistance, m_settings.MaxOrbitDistance); tmp_distance += distToPrev; - if(MyRandom.Instance.NextDouble() * ((i % 6) * (i % 6) / 12.5) < 1 - m_settings.BeltSettings.BeltProbability){ + if(MyRandom.Instance.NextDouble()/* * ((i % 6) * (i % 6) / 12.5)*/ < 1 - m_settings.BeltSettings.BeltProbability){ GeneratePlanet(i, tmp_distance, numberPlanets); } else @@ -181,7 +181,7 @@ private MyPlanetMoonItem[] GenerateMoons(float planetSize, float surfaceGravity, private MyPlanetRingItem GenerateRing(float surfaceGravity, float planetSize) { - if (MyRandom.Instance.NextFloat() / surfaceGravity > 0.3 && false) return null; + if (MyRandom.Instance.NextFloat() > m_settings.PlanetSettings.RingSettings.PlanetRingProbability * surfaceGravity) return null; MyPlanetRingItem ring = new MyPlanetRingItem(); @@ -189,7 +189,7 @@ private MyPlanetRingItem GenerateRing(float surfaceGravity, float planetSize) ring.RoidSize = MyRandom.Instance.Next(64, Math.Min((int)(Math.Max(surfaceGravity * 0.5 * 128, 64)), 512)); ring.Width = MyRandom.Instance.Next(m_settings.PlanetSettings.RingSettings.MinPlanetRingWidth, m_settings.PlanetSettings.RingSettings.MaxPlanetRingWidth); ring.Height = MyRandom.Instance.Next(m_settings.PlanetSettings.RingSettings.MinPlanetRingWidth / 10, ring.Width / 10); - ring.AngleDegrees = MyRandom.Instance.Next(-180, 180); + ring.AngleDegrees = MyRandom.Instance.Next(-20, 20); ring.Radius = MyRandom.Instance.Next((int)(planetSize * 0.5 * 0.75), (int)(planetSize)); ring.DisplayName = ""; @@ -215,7 +215,7 @@ private MyPlanetGeneratorDefinition GetPlanetDefinition(float maximumSize) private int SizeByGravity(float gravity) { - return (int)Math.Min(Math.Sqrt(gravity * 120000 * 120000 * m_settings.PlanetSettings.SizeMultiplier * m_settings.PlanetSettings.SizeMultiplier), m_settings.PlanetSettings.PlanetSizeCap); + return (int)Math.Min(Math.Sqrt(gravity * 120000 * 120000 * m_settings.PlanetSettings.SizeMultiplier * m_settings.PlanetSettings.SizeMultiplier), m_settings.PlanetSettings.PlanetSizeCap); } private int GetMaxMoonCount(float gravity) diff --git a/SEWorldGenPlugin/MySettings.cs b/SEWorldGenPlugin/MySettings.cs index aa88a62..2f7a1c7 100644 --- a/SEWorldGenPlugin/MySettings.cs +++ b/SEWorldGenPlugin/MySettings.cs @@ -1,5 +1,5 @@ using SEWorldGenPlugin.ObjectBuilders; -using SEWorldGenPlugin.Utilities.SEWorldGenPlugin.Utilities; +using SEWorldGenPlugin.Utilities; using System; using VRage.Utils; diff --git a/SEWorldGenPlugin/ObjectBuilders/MyObjectBuilder_PluginSettings.cs b/SEWorldGenPlugin/ObjectBuilders/MyObjectBuilder_PluginSettings.cs index 15597cc..c97f743 100644 --- a/SEWorldGenPlugin/ObjectBuilders/MyObjectBuilder_PluginSettings.cs +++ b/SEWorldGenPlugin/ObjectBuilders/MyObjectBuilder_PluginSettings.cs @@ -109,6 +109,7 @@ public PlanetRingSettings() { MinPlanetRingWidth = 10000; MaxPlanetRingWidth = 100000; + PlanetRingProbability = 0.5f; } [ProtoMember(1)] @@ -116,11 +117,15 @@ public PlanetRingSettings() [ProtoMember(2)] public int MaxPlanetRingWidth; + [ProtoMember(2)] + public float PlanetRingProbability; + public void Verify() { Verifier.VerifyInt(0, MaxPlanetRingWidth, 10000, "PlanetRingSettings.MinPlanetRingWidth", ref MinPlanetRingWidth); Verifier.VerifyInt(MinPlanetRingWidth, int.MaxValue, 100000, "PlanetRingSettings.MaxPlanetRingWidth", ref MaxPlanetRingWidth); + Verifier.VerifyFloat(0, 1, 0.5f, "PlanetRingSettings.PlanetRingProbability", ref PlanetRingProbability); } } @@ -131,7 +136,7 @@ public BeltSettings() { MinBeltHeight = 4000; MaxBeltHeight = 40000; - BeltProbability = 0.4f; + BeltProbability = 0.2f; } [ProtoMember(1)] diff --git a/SEWorldGenPlugin/SEWorldGenPlugin.csproj b/SEWorldGenPlugin/SEWorldGenPlugin.csproj index 70fce68..4795e85 100644 --- a/SEWorldGenPlugin/SEWorldGenPlugin.csproj +++ b/SEWorldGenPlugin/SEWorldGenPlugin.csproj @@ -187,7 +187,7 @@ - + diff --git a/SEWorldGenPlugin/Session/SettingsSession.cs b/SEWorldGenPlugin/Session/SettingsSession.cs index 3e20fc5..475a5a9 100644 --- a/SEWorldGenPlugin/Session/SettingsSession.cs +++ b/SEWorldGenPlugin/Session/SettingsSession.cs @@ -1,5 +1,5 @@ using SEWorldGenPlugin.ObjectBuilders; -using SEWorldGenPlugin.Utilities.SEWorldGenPlugin.Utilities; +using SEWorldGenPlugin.Utilities; using VRage.Game; using VRage.Game.Components; using VRage.Utils; diff --git a/SEWorldGenPlugin/Utilities/FileUtils.cs b/SEWorldGenPlugin/Utilities/FileUtils.cs index cd08d11..7858a07 100644 --- a/SEWorldGenPlugin/Utilities/FileUtils.cs +++ b/SEWorldGenPlugin/Utilities/FileUtils.cs @@ -1,281 +1,273 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Sandbox.Game.World; +using System; +using System.IO; +using System.Xml; +using System.Xml.Serialization; +using VRage.FileSystem; +using VRage.Utils; namespace SEWorldGenPlugin.Utilities { - using Sandbox.Game.World; - using System.IO; - using System.Xml; - using System.Xml.Serialization; - using VRage.FileSystem; - using VRage.Utils; - - namespace SEWorldGenPlugin.Utilities + /* + * Taken form Keen Github, since ModAPI is not available at Plugin init, but methods are needed + */ + public class FileUtils { - /* - * Taken form Keen Github, since ModAPI is not available at Plugin init, but methods are needed - */ - public class FileUtils - { - private const string STORAGE_FOLDER = "Storage"; + private const string STORAGE_FOLDER = "Storage"; - private static string StripDllExtIfNecessary(string name) + private static string StripDllExtIfNecessary(string name) + { + string ext = ".dll"; + if (name.EndsWith(ext, StringComparison.InvariantCultureIgnoreCase)) { - string ext = ".dll"; - if (name.EndsWith(ext, StringComparison.InvariantCultureIgnoreCase)) - { - return name.Substring(0, name.Length - ext.Length); - } - return name; + return name.Substring(0, name.Length - ext.Length); } + return name; + } - public static bool FileExistsInWorldStorage(string file, Type callingType) + public static bool FileExistsInWorldStorage(string file, Type callingType) + { + if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) { - if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) - { - return false; - } + return false; + } - var path = Path.Combine(MySession.Static.CurrentPath, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); + var path = Path.Combine(MySession.Static.CurrentPath, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); - return File.Exists(path); - } + return File.Exists(path); + } - public static bool FileExistsInPath(string path, string file, Type callingType) + public static bool FileExistsInPath(string path, string file, Type callingType) + { + if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) { - if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) - { - return false; - } - - var paths = Path.Combine(path, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); - MyLog.Default.WriteLine(paths); - return File.Exists(paths); + return false; } - public static bool FileExistsInGlobalStorage(string file) - { - if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) - return false; + var paths = Path.Combine(path, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); + MyLog.Default.WriteLine(paths); + return File.Exists(paths); + } - var path = Path.Combine(MyFileSystem.UserDataPath, STORAGE_FOLDER, file); - return File.Exists(path); - } + public static bool FileExistsInGlobalStorage(string file) + { + if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) + return false; + + var path = Path.Combine(MyFileSystem.UserDataPath, STORAGE_FOLDER, file); + return File.Exists(path); + } - public static void DeleteFileInWorldStorage(string file, Type callingType) + public static void DeleteFileInWorldStorage(string file, Type callingType) + { + if (FileExistsInWorldStorage(file, callingType)) { - if (FileExistsInWorldStorage(file, callingType)) - { - var path = Path.Combine(MySession.Static.CurrentPath, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); - File.Delete(path); - } + var path = Path.Combine(MySession.Static.CurrentPath, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); + File.Delete(path); } + } - public static void DeleteFileInPath(string path, string file, Type callingType) + public static void DeleteFileInPath(string path, string file, Type callingType) + { + if (FileExistsInPath(path, file, callingType)) { - if (FileExistsInPath(path, file, callingType)) - { - var paths = Path.Combine(path, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); - File.Delete(paths); - } + var paths = Path.Combine(path, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); + File.Delete(paths); } + } - public static void DeleteFileInGlobalStorage(string file) + public static void DeleteFileInGlobalStorage(string file) + { + if (FileExistsInGlobalStorage(file)) { - if (FileExistsInGlobalStorage(file)) - { - var path = Path.Combine(MyFileSystem.UserDataPath, STORAGE_FOLDER, file); - File.Delete(path); - } + var path = Path.Combine(MyFileSystem.UserDataPath, STORAGE_FOLDER, file); + File.Delete(path); } + } - public static TextReader ReadFileInWorldStorage(string file, Type callingType) + public static TextReader ReadFileInWorldStorage(string file, Type callingType) + { + if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) { - if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) - { - throw new FileNotFoundException(); - } - var path = Path.Combine(MySession.Static.CurrentPath, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); - var stream = MyFileSystem.OpenRead(path); - if (stream != null) - { - return new StreamReader(stream); - } throw new FileNotFoundException(); } + var path = Path.Combine(MySession.Static.CurrentPath, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); + var stream = MyFileSystem.OpenRead(path); + if (stream != null) + { + return new StreamReader(stream); + } + throw new FileNotFoundException(); + } - public static TextReader ReadFileInPath(string path, string file, Type callingType) + public static TextReader ReadFileInPath(string path, string file, Type callingType) + { + if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) { - if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) - { - throw new FileNotFoundException(); - } - var paths = Path.Combine(path, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); - var stream = MyFileSystem.OpenRead(paths); - if (stream != null) - { - return new StreamReader(stream); - } throw new FileNotFoundException(); } - - public static TextReader ReadFileInGlobalStorage(string file) + var paths = Path.Combine(path, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); + var stream = MyFileSystem.OpenRead(paths); + if (stream != null) { - if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) - throw new FileNotFoundException(); + return new StreamReader(stream); + } + throw new FileNotFoundException(); + } - var path = Path.Combine(MyFileSystem.UserDataPath, STORAGE_FOLDER, file); - var stream = MyFileSystem.OpenRead(path); - if (stream != null) - { - return new StreamReader(stream); - } + public static TextReader ReadFileInGlobalStorage(string file) + { + if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) throw new FileNotFoundException(); - } - public static TextWriter WriteFileInWorldStorage(string file, Type callingType) + var path = Path.Combine(MyFileSystem.UserDataPath, STORAGE_FOLDER, file); + var stream = MyFileSystem.OpenRead(path); + if (stream != null) { - if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) - { - throw new FileNotFoundException(); - } + return new StreamReader(stream); + } + throw new FileNotFoundException(); + } - var path = Path.Combine(MySession.Static.CurrentPath, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); - var stream = MyFileSystem.OpenWrite(path); - if (stream != null) - { - return new StreamWriter(stream); - } + public static TextWriter WriteFileInWorldStorage(string file, Type callingType) + { + if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) + { throw new FileNotFoundException(); } - public static TextWriter WriteFileInPath(string path, string file, Type callingType) + var path = Path.Combine(MySession.Static.CurrentPath, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); + var stream = MyFileSystem.OpenWrite(path); + if (stream != null) { - if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) - { - throw new FileNotFoundException(); - } + return new StreamWriter(stream); + } + throw new FileNotFoundException(); + } - var paths = Path.Combine(path, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); - var stream = MyFileSystem.OpenWrite(paths); - if (stream != null) - { - return new StreamWriter(stream); - } + public static TextWriter WriteFileInPath(string path, string file, Type callingType) + { + if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) + { throw new FileNotFoundException(); } - public static TextWriter WriteFileInGlobalStorage(string file) + var paths = Path.Combine(path, STORAGE_FOLDER, StripDllExtIfNecessary(callingType.Assembly.ManifestModule.ScopeName), file); + var stream = MyFileSystem.OpenWrite(paths); + if (stream != null) { - if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) - throw new FileNotFoundException(); + return new StreamWriter(stream); + } + throw new FileNotFoundException(); + } - var path = Path.Combine(MyFileSystem.UserDataPath, STORAGE_FOLDER, file); - var stream = MyFileSystem.OpenWrite(path); - if (stream != null) - { - return new StreamWriter(stream); - } + public static TextWriter WriteFileInGlobalStorage(string file) + { + if (file.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) throw new FileNotFoundException(); - } - public static string SerializeToXml(T objToSerialize) + var path = Path.Combine(MyFileSystem.UserDataPath, STORAGE_FOLDER, file); + var stream = MyFileSystem.OpenWrite(path); + if (stream != null) { - System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(objToSerialize.GetType()); - StringWriter textWriter = new StringWriter(); - x.Serialize(textWriter, objToSerialize); - return textWriter.ToString(); + return new StreamWriter(stream); } + throw new FileNotFoundException(); + } - public static T SerializeFromXml(string xml) + public static string SerializeToXml(T objToSerialize) + { + System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(objToSerialize.GetType()); + StringWriter textWriter = new StringWriter(); + x.Serialize(textWriter, objToSerialize); + return textWriter.ToString(); + } + + public static T SerializeFromXml(string xml) + { + if (string.IsNullOrEmpty(xml)) { - if (string.IsNullOrEmpty(xml)) - { - return default(T); - } + return default(T); + } - XmlSerializer serializer = new XmlSerializer(typeof(T)); + XmlSerializer serializer = new XmlSerializer(typeof(T)); - using (StringReader textReader = new StringReader(xml)) + using (StringReader textReader = new StringReader(xml)) + { + using (XmlReader xmlReader = XmlReader.Create(textReader)) { - using (XmlReader xmlReader = XmlReader.Create(textReader)) - { - return (T)serializer.Deserialize(xmlReader); - } + return (T)serializer.Deserialize(xmlReader); } } + } - public static T ReadXmlFileFromWorld(string file, Type callingType) + public static T ReadXmlFileFromWorld(string file, Type callingType) + { + if (FileExistsInWorldStorage(file, callingType)) { - if(FileExistsInWorldStorage(file, callingType)) + try { - try - { - using(var reader = ReadFileInWorldStorage(file, callingType)) - { - T saveFile = SerializeFromXml(reader.ReadToEnd()); - return saveFile; - } - } - catch(Exception e) + using (var reader = ReadFileInWorldStorage(file, callingType)) { - MyLog.Default.Error("Couldnt load save file."); - MyLog.Default.Error(e.Message + "\n" + e.StackTrace); - DeleteFileInWorldStorage(file, callingType); - return default(T); + T saveFile = SerializeFromXml(reader.ReadToEnd()); + return saveFile; } } - return default(T); + catch (Exception e) + { + MyLog.Default.Error("Couldnt load save file."); + MyLog.Default.Error(e.Message + "\n" + e.StackTrace); + DeleteFileInWorldStorage(file, callingType); + return default(T); + } } + return default(T); + } - public static void WriteXmlFileToWorld(T saveFile, string file, Type callingType) + public static void WriteXmlFileToWorld(T saveFile, string file, Type callingType) + { + DeleteFileInWorldStorage(file, callingType); + string xml = SerializeToXml(saveFile); + using (var writer = WriteFileInWorldStorage(file, callingType)) { - DeleteFileInWorldStorage(file, callingType); - string xml = SerializeToXml(saveFile); - using(var writer = WriteFileInWorldStorage(file, callingType)) - { - writer.Write(xml); - writer.Close(); - } + writer.Write(xml); + writer.Close(); } + } - public static T ReadXmlFileFromPath(string path, string file, Type callingType) + public static T ReadXmlFileFromPath(string path, string file, Type callingType) + { + MyLog.Default.WriteLine(path + " PAth"); + if (FileExistsInPath(path, file, callingType)) { - MyLog.Default.WriteLine(path + " PAth"); - if(FileExistsInPath(path, file, callingType)) + try { - try - { - using(var reader = ReadFileInPath(path, file, callingType)) - { - T saveFile = SerializeFromXml(reader.ReadToEnd()); - return saveFile; - } - } - catch(Exception e) + using (var reader = ReadFileInPath(path, file, callingType)) { - MyLog.Default.Error("Couldnt load save file."); - MyLog.Default.Error(e.Message + "\n" + e.StackTrace); - DeleteFileInPath(path, file, callingType); - return default(T); + T saveFile = SerializeFromXml(reader.ReadToEnd()); + return saveFile; } } - return default(T); + catch (Exception e) + { + MyLog.Default.Error("Couldnt load save file."); + MyLog.Default.Error(e.Message + "\n" + e.StackTrace); + DeleteFileInPath(path, file, callingType); + return default(T); + } } + return default(T); + } - public static void WriteXmlFileToPath(T saveFile, string path, string file, Type callingType) + public static void WriteXmlFileToPath(T saveFile, string path, string file, Type callingType) + { + DeleteFileInPath(path, file, callingType); + string xml = SerializeToXml(saveFile); + using (var writer = WriteFileInPath(path, file, callingType)) { - DeleteFileInPath(path, file, callingType); - string xml = SerializeToXml(saveFile); - using(var writer = WriteFileInPath(path, file, callingType)) - { - writer.Write(xml); - writer.Close(); - } + writer.Write(xml); + writer.Close(); } } } -} +} \ No newline at end of file diff --git a/SEWorldGenPlugin/Utilities/MyTexts.cs b/SEWorldGenPlugin/Utilities/MyPluginTexts.cs similarity index 83% rename from SEWorldGenPlugin/Utilities/MyTexts.cs rename to SEWorldGenPlugin/Utilities/MyPluginTexts.cs index d3da397..c405f13 100644 --- a/SEWorldGenPlugin/Utilities/MyTexts.cs +++ b/SEWorldGenPlugin/Utilities/MyPluginTexts.cs @@ -6,11 +6,10 @@ namespace SEWorldGenPlugin.Utilities { - public class MyTexts + public class MyPluginTexts { public static ToolTips TOOLTIPS = new ToolTips(); } - public class ToolTips { public readonly string SYS_OBJ_SLIDER = "Objects that should be generated in the system"; @@ -19,8 +18,10 @@ public class ToolTips public readonly string SIZE_CAP_SLIDER = "The largest diameter a planet can have, if some planet would be larger, it will get this diameter. Value in kilometers"; public readonly string MOON_PROB_SLIDER = "The probability a planet has moons"; public readonly string RING_WIDTH_SLIDER = "Average width of a ring around a planet in meters"; + public readonly string RING_PROB_SLIDER = "Probability an asteroid ring spawn around a planet. Gets multiplied with the surface gravity of the planet, so larger planets have a higher chance to spawn a ring."; public readonly string BELT_HEIGHT_SLIDER = "Average height of an asteroid belt in meters."; public readonly string BELT_PROB_SLIDER = "The probability a belt will spawn every 6th object."; public readonly string USE_GLOBAL_CHECK = "If the settings for this world are based on the global configuration file."; } + }