From 4abfe3db0ebcbbda7c4f8f5b2b737cb34d52cdc6 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Fri, 10 Feb 2017 02:27:30 -0600 Subject: [PATCH] Use GameDatabase and absolute paths (fixes #4) --- Astrogator.version | 2 +- src/Properties/AssemblyInfo.cs | 4 +-- src/Settings.cs | 2 +- src/ViewTools.cs | 45 ++++++++++++++++++++-------------- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Astrogator.version b/Astrogator.version index 5928f86..565f98f 100644 --- a/Astrogator.version +++ b/Astrogator.version @@ -10,7 +10,7 @@ "VERSION": { "MAJOR": 0, "MINOR": 3, - "PATCH": 0, + "PATCH": 1, "BUILD": 0 }, "KSP_VERSION_MIN": { diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index be4be75..38ffbc2 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.3.0.0")] -[assembly: AssemblyFileVersion("0.3.0.0")] +[assembly: AssemblyVersion("0.3.1.0")] +[assembly: AssemblyFileVersion("0.3.1.0")] diff --git a/src/Settings.cs b/src/Settings.cs index 2c6bbe0..1c7d63e 100644 --- a/src/Settings.cs +++ b/src/Settings.cs @@ -31,7 +31,7 @@ private Settings() } private ConfigNode config { get; set; } - private static string filename = FilePath(Astrogator.Name + ".settings"); + private static string filename = FilePath(Astrogator.Name + ".settings", false); /// /// We don't want multiple copies of this floating around clobbering one another. diff --git a/src/ViewTools.cs b/src/ViewTools.cs index 0bcc612..4de07b0 100644 --- a/src/ViewTools.cs +++ b/src/ViewTools.cs @@ -29,9 +29,16 @@ public static class ViewTools { /// The full relative path from the main KSP folder to a given resource from this mod. /// /// Name of file located in our plugin folder - public static string FilePath(string filename) + /// True if the KSP/GameData portion of the path is assumed, false if we need to provide the full path + public static string FilePath(string filename, bool GameDataRelative = true) { - return string.Format("GameData/{0}/{1}", Astrogator.Name, filename); + if (GameDataRelative) { + return string.Format("{0}/{1}", Astrogator.Name, filename); + } else { + return string.Format("{0}/{1}", + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), + filename); + } } /// @@ -56,7 +63,7 @@ public static T ParseEnum(string val, T defaultVal) where T : IConvertible /// /// The icon to show for this mod in the app launcher. /// - public static Texture2D AppIcon = GetImage(FilePath("Astrogator.png")); + public static Texture2D AppIcon = GetImage(FilePath("Astrogator")); /// /// A texture object for the image file at the given path. @@ -64,9 +71,7 @@ public static T ParseEnum(string val, T defaultVal) where T : IConvertible /// Path to image file to load public static Texture2D GetImage(string filepath) { - Texture2D tex = new Texture2D(38, 38, TextureFormat.ARGB32, false); - tex.LoadImage(System.IO.File.ReadAllBytes(filepath)); - return tex; + return GameDatabase.Instance.GetTexture(filepath, false); } /// @@ -86,12 +91,16 @@ public static Texture2D SolidColorTexture(Color c) private static Sprite SpriteFromTexture(Texture2D tex) { - return Sprite.Create( - tex, - new Rect(0, 0, tex.width, tex.height), - new Vector2(0.5f, 0.5f), - tex.width - ); + if (tex != null) { + return Sprite.Create( + tex, + new Rect(0, 0, tex.width, tex.height), + new Vector2(0.5f, 0.5f), + tex.width + ); + } else { + return null; + } } /// @@ -244,7 +253,7 @@ public static Sprite SolidColorSprite(Color c) /// /// Icon for normal state of settings button. /// - public static Sprite settingsIcon = GetSprite(FilePath("settings.png")); + public static Sprite settingsIcon = GetSprite(FilePath("settings")); /// /// Icon for normal state of settings button. @@ -257,7 +266,7 @@ public static Sprite SolidColorSprite(Color c) /// /// Icon for hovered state of settings button. /// - public static Sprite settingsHoverIcon = GetSprite(FilePath("settingsHover.png")); + public static Sprite settingsHoverIcon = GetSprite(FilePath("settingsHover")); /// /// Icon for hovered state of settings button. @@ -281,7 +290,7 @@ public static Sprite SolidColorSprite(Color c) /// /// Icon for normal state of maneuver node creation button. /// - public static Sprite maneuverIcon = GetSprite(FilePath("maneuver.png")); + public static Sprite maneuverIcon = GetSprite(FilePath("maneuver")); /// /// Icon for normal state of maneuver creation button. @@ -294,7 +303,7 @@ public static Sprite SolidColorSprite(Color c) /// /// Icon for hovered state of maneuver node creation button. /// - public static Sprite maneuverHoverIcon = GetSprite(FilePath("maneuverHover.png")); + public static Sprite maneuverHoverIcon = GetSprite(FilePath("maneuverHover")); /// /// Icon for hovered state of maneuver creation button. @@ -317,7 +326,7 @@ public static Sprite SolidColorSprite(Color c) /// /// Icon for normal state of warp button. /// - public static Sprite warpIcon = GetSprite(FilePath("warp.png")); + public static Sprite warpIcon = GetSprite(FilePath("warp")); /// /// Icon for normal state of warp button. @@ -330,7 +339,7 @@ public static Sprite SolidColorSprite(Color c) /// /// Icon for hovered state of warp button. /// - public static Sprite warpHoverIcon = GetSprite(FilePath("warpHover.png")); + public static Sprite warpHoverIcon = GetSprite(FilePath("warpHover")); /// /// Icon for hovered state of warp button.