Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Commit

Permalink
v1.13.3 for KSP 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Crzyrndm committed May 28, 2017
1 parent ef7d457 commit 6d5bf7d
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 57 deletions.
Binary file modified GameData/Pilot Assistant/PilotAssistant.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion GameData/Pilot Assistant/PilotAssistant.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"NAME":"Pilot Assistant","URL":"https://github.com/Crzyrndm/Pilot-Assistant/blob/master/GameData/Pilot%20Assistant/PilotAssistant.version","DOWNLOAD":"https://github.com/Crzyrndm/Pilot-Assistant/releases","VERSION":{"MAJOR":1,"MINOR":13,"PATCH":2,"BUILD":0},"KSP_VERSION":{"MAJOR":1,"MINOR":2,"PATCH":1},"KSP_VERSION_MIN":{"MAJOR":1,"MINOR":2,"PATCH":1},"KSP_VERSION_MAX":{"MAJOR":1,"MINOR":2,"PATCH":2}}
{"NAME":"Pilot Assistant","URL":"https://github.com/Crzyrndm/Pilot-Assistant/blob/master/GameData/Pilot%20Assistant/PilotAssistant.version","DOWNLOAD":"https://github.com/Crzyrndm/Pilot-Assistant/releases","VERSION":{"MAJOR":1,"MINOR":13,"PATCH":3},"KSP_VERSION":{"MAJOR":1,"MINOR":3,"PATCH":0}
8 changes: 4 additions & 4 deletions PilotAssistant/FlightModules/AsstVesselModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ protected override void OnStart()
}
catch (Exception ex)
{
Utils.LogError("Startup error");
Utils.LogError(ex.Message);
Utils.LogError(ex.InnerException);
Utils.LogError(ex.StackTrace);
Logger.Log("Startup error", Logger.LogLevel.Error);
Logger.Log(ex.Message, Logger.LogLevel.Error);
Logger.Log(ex.InnerException, Logger.LogLevel.Error);
Logger.Log(ex.StackTrace, Logger.LogLevel.Error);
}
}

Expand Down
70 changes: 70 additions & 0 deletions PilotAssistant/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using UnityEngine;

namespace PilotAssistant
{
internal static class Logger
{
public static readonly Version version = new Version(1, 13, 3);

internal enum LogLevel
{
Debug,
Warn,
Error
}

/// <summary>
/// format the string to be logged and prefix with mod id + version
/// </summary>
/// <param name="format">string format to be logged</param>
/// <param name="o">params for the format</param>
/// <returns></returns>
static string LogString(string format, params object[] o)
{
return $"[Pilot Assistant {version}]: {string.Format(format, o)}";
}

/// <summary>
/// Debug messages only compiled in debug build. Also much easier to search for once debugging/development complete...
/// </summary>
/// <param name="o"></param>
/// <param name="level"></param>
[System.Diagnostics.Conditional("DEBUG")]
internal static void Dev(object o, LogLevel level = LogLevel.Debug)
{
Log(o, level);
}

[System.Diagnostics.Conditional("DEBUG")]
internal static void Dev(string format, LogLevel level = LogLevel.Debug, params object[] o)
{
Log(format, level, o);
}

/// <summary>
/// Debug.Log with FE id/version inserted
/// </summary>
/// <param name="o"></param>
internal static void Log(object o, LogLevel level = LogLevel.Debug)
{
Log(o.ToString(), level);
}

internal static void Log(string format, LogLevel level = LogLevel.Debug, params object[] o)
{
if (level == LogLevel.Debug)
{
Debug.Log(LogString(format, o));
}
else if (level == LogLevel.Warn)
{
Debug.LogWarning(LogString(format, o));
}
else
{
Debug.LogError(LogString(format, o));
}
}
}
}
9 changes: 3 additions & 6 deletions PilotAssistant/PilotAssistant.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\Desktop\Kerbal Space Program Dev\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>..\..\..\Desktop\Kerbal Space Program Dev\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -45,17 +45,14 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\..\Desktop\Kerbal Space Program Dev\KSP_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\..\..\Desktop\Kerbal Space Program Dev\KSP_Data\Managed\UnityEngine.UI.dll</HintPath>
<HintPath>..\..\..\Desktop\Kerbal Space Program Dev\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="FlightModules\VesselData.cs" />
<Compile Include="FlightModules\AsstVesselModule.cs" />
<Compile Include="Logger.cs" />
<Compile Include="Toolbar\AppLauncherFlight.cs" />
<Compile Include="BindingManager.cs" />
<Compile Include="PilotAssistantFlightCore.cs" />
Expand Down
6 changes: 3 additions & 3 deletions PilotAssistant/PilotAssistantFlightCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ public void LoadConfig()
}
else
{
Utils.LogError("Failed to create settings node");
Logger.Log("Failed to create settings node", Logger.LogLevel.Error);
}
}
catch
{
Utils.LogError("Config load failed");
Logger.Log("Config load failed", Logger.LogLevel.Error);
}
}

Expand Down Expand Up @@ -200,7 +200,7 @@ public void SaveConfig()
}
catch
{
Utils.LogError("Pilot Assistant save failed");
Logger.Log("Pilot Assistant save failed", Logger.LogLevel.Error);
}
}

Expand Down
21 changes: 8 additions & 13 deletions PilotAssistant/PresetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@ namespace PilotAssistant
[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class PresetManager : MonoBehaviour
{
private static PresetManager instance;
public static PresetManager Instance
{
get
{
return instance;
}
get;
private set;
}

//
// A list of all the loaded PA presets and the one currently loaded
public List<AsstPreset> AsstPresetList = new List<AsstPreset>();
[Obsolete("Need to move this inside the PA class as can be done per instance", true)]
public AsstPreset activeAsstPreset = null;

//
// stores all craft presets by name
Expand Down Expand Up @@ -77,7 +72,7 @@ public static PresetManager Instance
public void Start()
{
// only ever a single instance of this class created upon reaching the main menu for the first time
instance = this;
Instance = this;
// make sure that instance is never recovered while loading
DontDestroyOnLoad(this);
// load preset data saved from a previous time
Expand All @@ -99,7 +94,7 @@ public void LoadPresetsFromFile()
foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes(asstPresetNodeName)) // want to move this outside GameDatabase at some point
{
string name = node.GetValue("name");
if (ReferenceEquals(node, null) || instance.AsstPresetList.Any(p => p.name == name))
if (ReferenceEquals(node, null) || Instance.AsstPresetList.Any(p => p.name == name))
{
continue;
}
Expand Down Expand Up @@ -159,13 +154,13 @@ public static void SaveToFile()
var node = new ConfigNode();
// dummy value is required incase nothing else will be added to the file. KSP doesn't like blank .cfg's
node.AddValue("dummy", "do not delete me");
foreach (AsstPreset p in instance.AsstPresetList)
foreach (AsstPreset p in Instance.AsstPresetList)
{
node.AddNode(AsstPresetToNode(p));
}

var vesselNode = new ConfigNode(craftPresetNodeName);
foreach (KeyValuePair<string, string> cP in instance.craftPresetDict)
foreach (KeyValuePair<string, string> cP in Instance.craftPresetDict)
{
vesselNode.AddValue("pair", string.Concat(cP.Key, ",", cP.Value)); // pair = craft,preset
}
Expand Down Expand Up @@ -433,8 +428,8 @@ public void DeleteAsstPreset(AsstPreset p)
/// <param name="instance">The instance to load for</param>
public void LoadCraftAsstPreset(PilotAssistant instance)
{
Utils.Log("loading preset for craft " + instance.Vessel.name);
Utils.Log(craftPresetDict.TryGetValue(instance.Vessel.vesselName, out string presetName) + " " + presetName);
Logger.Log("loading preset for craft " + instance.Vessel.name);
Logger.Log(craftPresetDict.TryGetValue(instance.Vessel.vesselName, out string presetName) + " " + presetName);
if (craftPresetDict.TryGetValue(instance.Vessel.vesselName, out presetName))
{
LoadAsstPreset(presetName, instance);
Expand Down
30 changes: 0 additions & 30 deletions PilotAssistant/Utility/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,35 +271,5 @@ public static Rect TryGetValue(this ConfigNode node, string key, Rect defaultVal
}
return defaultValue;
}

public static void Log(object obj)
{
Debug.Log($"[Pilot Assistant] {obj.ToString()}");
}

public static void Log(string format, params object[] args)
{
Log(string.Format(format, args));
}

public static void LogWarn(object obj)
{
Debug.LogWarning($"[Pilot Assistant] {obj.ToString()}");
}

public static void LogWarn(string format, params object[] args)
{
LogWarn(string.Format(format, args));
}

public static void LogError(object obj)
{
Debug.LogError($"[Pilot Assistant] {obj.ToString()}");
}

public static void LogError(string format, params object[] args)
{
LogError(string.Format(format, args));
}
}
}

0 comments on commit 6d5bf7d

Please sign in to comment.