Skip to content

Commit

Permalink
Use GameDatabase and absolute paths (fixes #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Feb 10, 2017
1 parent 76f970a commit 4abfe3d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Astrogator.version
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"VERSION": {
"MAJOR": 0,
"MINOR": 3,
"PATCH": 0,
"PATCH": 1,
"BUILD": 0
},
"KSP_VERSION_MIN": {
Expand Down
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
2 changes: 1 addition & 1 deletion src/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/// <summary>
/// We don't want multiple copies of this floating around clobbering one another.
Expand Down
45 changes: 27 additions & 18 deletions src/ViewTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ public static class ViewTools {
/// The full relative path from the main KSP folder to a given resource from this mod.
/// </returns>
/// <param name="filename">Name of file located in our plugin folder</param>
public static string FilePath(string filename)
/// <param name="GameDataRelative">True if the KSP/GameData portion of the path is assumed, false if we need to provide the full path</param>
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);
}
}

/// <summary>
Expand All @@ -56,17 +63,15 @@ public static T ParseEnum<T>(string val, T defaultVal) where T : IConvertible
/// <value>
/// The icon to show for this mod in the app launcher.
/// </value>
public static Texture2D AppIcon = GetImage(FilePath("Astrogator.png"));
public static Texture2D AppIcon = GetImage(FilePath("Astrogator"));

/// <returns>
/// A texture object for the image file at the given path.
/// </returns>
/// <param name="filepath">Path to image file to load</param>
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);
}

/// <summary>
Expand All @@ -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;
}
}

/// <returns>
Expand Down Expand Up @@ -244,7 +253,7 @@ public static Sprite SolidColorSprite(Color c)
/// <value>
/// Icon for normal state of settings button.
/// </value>
public static Sprite settingsIcon = GetSprite(FilePath("settings.png"));
public static Sprite settingsIcon = GetSprite(FilePath("settings"));

/// <value>
/// Icon for normal state of settings button.
Expand All @@ -257,7 +266,7 @@ public static Sprite SolidColorSprite(Color c)
/// <value>
/// Icon for hovered state of settings button.
/// </value>
public static Sprite settingsHoverIcon = GetSprite(FilePath("settingsHover.png"));
public static Sprite settingsHoverIcon = GetSprite(FilePath("settingsHover"));

/// <value>
/// Icon for hovered state of settings button.
Expand All @@ -281,7 +290,7 @@ public static Sprite SolidColorSprite(Color c)
/// <value>
/// Icon for normal state of maneuver node creation button.
/// </value>
public static Sprite maneuverIcon = GetSprite(FilePath("maneuver.png"));
public static Sprite maneuverIcon = GetSprite(FilePath("maneuver"));

/// <value>
/// Icon for normal state of maneuver creation button.
Expand All @@ -294,7 +303,7 @@ public static Sprite SolidColorSprite(Color c)
/// <value>
/// Icon for hovered state of maneuver node creation button.
/// </value>
public static Sprite maneuverHoverIcon = GetSprite(FilePath("maneuverHover.png"));
public static Sprite maneuverHoverIcon = GetSprite(FilePath("maneuverHover"));

/// <value>
/// Icon for hovered state of maneuver creation button.
Expand All @@ -317,7 +326,7 @@ public static Sprite SolidColorSprite(Color c)
/// <value>
/// Icon for normal state of warp button.
/// </value>
public static Sprite warpIcon = GetSprite(FilePath("warp.png"));
public static Sprite warpIcon = GetSprite(FilePath("warp"));

/// <value>
/// Icon for normal state of warp button.
Expand All @@ -330,7 +339,7 @@ public static Sprite SolidColorSprite(Color c)
/// <value>
/// Icon for hovered state of warp button.
/// </value>
public static Sprite warpHoverIcon = GetSprite(FilePath("warpHover.png"));
public static Sprite warpHoverIcon = GetSprite(FilePath("warpHover"));

/// <value>
/// Icon for hovered state of warp button.
Expand Down

0 comments on commit 4abfe3d

Please sign in to comment.