Skip to content

Commit

Permalink
Merge pull request #12 from BenjaminCronin/develop
Browse files Browse the repository at this point in the history
Fix display bug, add styling, update formatting, update version and changelog
  • Loading branch information
AmberCronin committed Mar 7, 2020
2 parents 1ce81cb + e0b38c7 commit 4b9b750
Show file tree
Hide file tree
Showing 9 changed files with 487 additions and 344 deletions.
42 changes: 21 additions & 21 deletions Change.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

namespace KerbalChangelog
{
public class Change
{
string change = "";
List<string> subchanges = new List<string>();
public class Change
{
string change = "";
List<string> subchanges = new List<string>();

public Change(string c)
{
change = c;
subchanges = new List<string>();
}
public Change(string c, List<string> sc)
{
change = c;
subchanges = sc;
}
public Change(ConfigNode chn, string cfgDirName)
{
{
change = c;
subchanges = sc;
}
public Change(ConfigNode chn, string cfgDirName)
{
if (!chn.TryGetValue("change", ref change))
{
Debug.Log("[KCL] Could not find a needed change field in directory " + cfgDirName);
Expand All @@ -30,15 +30,15 @@ public Change(ConfigNode chn, string cfgDirName)
subchanges.Add(sc);
}
}
public override string ToString()
{
string ret = "";
ret += " * " + change + "\n";
foreach(string sc in subchanges)
{
ret += " - " + sc + "\n"; //6 spaces ought to look good (or it does to me)
}
return ret;
}
}
public override string ToString()
{
string ret = "";
ret += " * " + change + "\n";
foreach(string sc in subchanges)
{
ret += " " + " " + "- " + sc + "\n"; //6 spaces ought to look good (or it does to me)
}
return ret;
}
}
}
90 changes: 45 additions & 45 deletions ChangeSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@

namespace KerbalChangelog
{
public class ChangeSet : IComparable
{
public ChangelogVersion version { get; private set; }
List<Change> changes = new List<Change>();
public class ChangeSet : IComparable
{
public ChangelogVersion version { get; private set; }
List<Change> changes = new List<Change>();

public ChangeSet(ChangelogVersion v, List<Change> ch)
{
version = v;
changes = ch;
}
public ChangeSet(ConfigNode vn, string cfgDirName)
{
string _version = "";
if (!vn.TryGetValue("version", ref _version))
{
Debug.Log("[KCL] Badly formatted version in directory " + cfgDirName);
_version = "null";
}
public ChangeSet(ChangelogVersion v, List<Change> ch)
{
version = v;
changes = ch;
}
public ChangeSet(ConfigNode vn, string cfgDirName)
{
string _version = "";
if (!vn.TryGetValue("version", ref _version))
{
Debug.Log("[KCL] Badly formatted version in directory " + cfgDirName);
_version = "null";
}
string _versionName = "";
if(!vn.TryGetValue("versionName", ref _versionName))
{
Expand All @@ -34,36 +34,36 @@ public ChangeSet(ConfigNode vn, string cfgDirName)

//loads change fields (needed for backwards compatibility
foreach (string change in vn.GetValues("change"))
{
changes.Add(new Change(change, new List<string>()));
}
{
changes.Add(new Change(change, new List<string>()));
}
//loads change nodes
foreach(ConfigNode chn in vn.GetNodes("CHANGE"))
{
changes.Add(new Change(chn, cfgDirName));
}
}
public override string ToString()
{
string ret = version + "\n";
foreach (Change c in changes)
{
ret += c.ToString();
}
return ret + "\n";
}
foreach(ConfigNode chn in vn.GetNodes("CHANGE"))
{
changes.Add(new Change(chn, cfgDirName));
}
}
public override string ToString()
{
string ret = version + "\n";
foreach (Change c in changes)
{
ret += c.ToString();
}
return ret + "\n";
}

public int CompareTo(object obj)
{
if (obj == null)
return 1;
public int CompareTo(object obj)
{
if (obj == null)
return 1;

if (obj is ChangeSet cs)
{
return version.CompareTo(cs.version);
}
throw new ArgumentException("Object is not a ChangeSet");
if (obj is ChangeSet cs)
{
return version.CompareTo(cs.version);
}
throw new ArgumentException("Object is not a ChangeSet");

}
}
}
}
}
12 changes: 6 additions & 6 deletions ChangeSetAddStatus.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
namespace KerbalChangelog
{
public enum ChangeSetAddStatus
{
Success = 0,
DuplicateVersioning = 1,
EmptyChangeList = 2
}
public enum ChangeSetAddStatus
{
Success = 0,
DuplicateVersioning = 1,
EmptyChangeList = 2
}
}
112 changes: 59 additions & 53 deletions Changelog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

namespace KerbalChangelog
{
public class Changelog
{
public class Changelog
{
public string modName { get; private set; }
public string license { get; private set; } = null;
public string author { get; private set; } = null;

bool showCL = true;
public bool showCL { get; private set; } = true;

List<ChangeSet> changeSets = new List<ChangeSet>();
public ChangelogVersion highestVersion
{
get
{
changeSets.Sort();
List<ChangeSet> changeSets = new List<ChangeSet>();
public ChangelogVersion highestVersion
{
get
{
changeSets.Sort();
try
{
return changeSets[0].version;
Expand All @@ -28,40 +28,45 @@ public ChangelogVersion highestVersion
return null;
}
}
}
}

public Changelog(string mn, bool show, List<ChangeSet> cs)
{
modName = mn;
showCL = show;
changeSets = cs;
}
public Changelog(string mn, bool show, List<ChangeSet> cs)
{
modName = mn;
showCL = show;
changeSets = cs;
}

public Changelog(ConfigNode cn, UrlDir.UrlConfig cfgDir)
{
string cfgDirName = cfgDir.ToString();
string _modname = "";
if (!cn.TryGetValue("modName", ref _modname))
{
Debug.Log("[KCL] Missing mod name for changelog file in directory: " + cfgDirName);
Debug.Log("[KCL] Continuing using directory name as mod name...");
modName = cfgDirName;
}
else
{
modName = _modname;
}
public Changelog(ConfigNode cn, UrlDir.UrlConfig cfgDir)
{
string cfgDirName = cfgDir.url;
string _modname = "";
if (!cn.TryGetValue("modName", ref _modname))
{
Debug.Log("[KCL] Missing mod name for changelog file in directory: " + cfgDirName);
Debug.Log("[KCL] Continuing using directory name as mod name...");
modName = cfgDirName;
}
else
{
modName = _modname;
}

if (!cn.TryGetValue("showChangelog", ref showCL))
{
Debug.Log("[KCL] \"showChangelog\" field does not exist in mod ");
Debug.Log("[KCL] Assuming [true] to show changelog, adding field to changelog...");
if (!cn.SetValue("showChangelog", false, true)) //creates a new field for the viewing status, setting it to false
{
Debug.Log("[KCL] Unable to create 'showChangelog' in directory " + cfgDirName + " (field was missing in file)");
}
bool _showCL = true;
if (!cn.TryGetValue("showChangelog", ref _showCL))
{
Debug.Log("[KCL] \"showChangelog\" field does not exist in mod ");
Debug.Log("[KCL] Assuming [true] to show changelog, adding field to changelog...");
if (!cn.SetValue("showChangelog", false, true)) //creates a new field for the viewing status, setting it to false
{
Debug.Log("[KCL] Unable to create 'showChangelog' in directory " + cfgDirName + " (field was missing in file)");
}
cfgDir.parent.SaveConfigs();
}
}
else
{
showCL = _showCL;
}

string _author = "";
if(cn.TryGetValue("author", ref _author))
Expand All @@ -76,21 +81,22 @@ public Changelog(ConfigNode cn, UrlDir.UrlConfig cfgDir)


foreach (ConfigNode vn in cn.GetNodes("VERSION"))
{
changeSets.Add(new ChangeSet(vn, cfgDirName));
}
}
{
changeSets.Add(new ChangeSet(vn, cfgDirName));
}
}

public override string ToString()
{
string ret = modName + "\n";
public override string ToString()
{
string ret = "";
ret += modName + "\n";
ret += ((author == null) ? "" : "Created by: " + author + "\n");
ret += ((license == null) ? "\n" : "Licensed under the " + license + " license\n\n"); //give a double line break here
foreach(ChangeSet cs in changeSets)
{
ret += cs.ToString();
}
return ret;
}
}
foreach (ChangeSet cs in changeSets)
{
ret += cs.ToString();
}
return ret;
}
}
}
Loading

0 comments on commit 4b9b750

Please sign in to comment.