Skip to content

Commit

Permalink
[0.5.0]
Browse files Browse the repository at this point in the history
- removed string restriction on $type
- fixed preceding comma, when purging last entry in a list
  • Loading branch information
Truinto committed Oct 18, 2022
1 parent 4167229 commit 72c945a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
38 changes: 29 additions & 9 deletions BlueprintPurge/BlueprintPurge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ private void ButtonSearch_Click(object sender, EventArgs e)
{
if (Guid.TryParse(bp, out var guid))
blueprints.Add(guid);
else if (rxAlphaNumerical.IsMatch(bp))
types.Add(", " + bp);
else //if (rxAlphaNumerical.IsMatch(bp))
types.Add(/*", " + */bp);
}

if (blueprints.Count == 0 && types.Count == 0)
Expand Down Expand Up @@ -194,7 +194,7 @@ private void Search(ZipEntry entry)
}

// if it's an type, check if it's blacklisted
else if (isType && this.types.Any(a => quote.EndsWith(a)))
else if (isType && this.types.Any(a => quote.Contains(a)))
{
// get id, if it has any
if (lastId.TryGetValue(stack.Count, out var id))
Expand Down Expand Up @@ -297,16 +297,18 @@ private void Cleanup()
break;
}

// include tailing comma
// include tailing comma; check if last entry in list
if (!purge.IsList)
{
for (int j = purge.End + 1; j < purge.Data.Length; j++)
{
char c = (char)purge.Data[j];
if (char.IsWhiteSpace(c))
continue;
if (c == ',')
else if (c == ',')
purge.End = j;
else if (c == ']' || c == '}')
purge.IsLastInList = true;
break;
}
}
Expand Down Expand Up @@ -382,6 +384,20 @@ private void ButtonPurge_Click(object sender, EventArgs e)
// simply clear all chars
for (int i = purge.Start; i <= purge.End; i++)
purge.Data[i] = (byte)' ';

// remove preceding comma
if (purge.IsLastInList)
{
for (int i = purge.Start; i > 0; i--)
{
char c = (char)purge.Data[i];
if (char.IsWhiteSpace(c))
continue;
else if (c == ',')
purge.Data[i] = (byte)' ';
break;
}
}
}
}

Expand All @@ -390,7 +406,7 @@ private void ButtonPurge_Click(object sender, EventArgs e)
{
foreach (var (file, data) in edited)
{
CheckSyntax(data);
CheckSyntax(file, data);
zip.UpdateEntry(file, data);
}

Expand All @@ -406,17 +422,21 @@ private void ButtonPurge_Click(object sender, EventArgs e)
Clear();
}

private bool CheckSyntax(byte[] data)
private bool CheckSyntax(string file, byte[] data)
{
string sdata = null;
try
{
JsonValue.Parse(Encoding.Default.GetString(data));
sdata = Encoding.Default.GetString(data);
JsonValue.Parse(sdata);
return true;
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
throw new Exception("Syntax error in output file", e);
Debug.WriteLine("in file: " + file);
Debug.WriteLine(sdata);
throw new Exception("Syntax error in output file " + file, e);
}
}

Expand Down
2 changes: 2 additions & 0 deletions BlueprintPurge/PurgeRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class PurgeRange
public bool IsList { get; set; }
public string Ref { get; set; }
public string Peek { get; set; }

public byte[] Data;
public bool IsLastInList;
}
}
2 changes: 1 addition & 1 deletion BlueprintPurge/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# BlueprintPurge
# BlueprintPurge
Tool for Pathfinder: Wrath of the Righteous

Index
Expand Down
4 changes: 4 additions & 0 deletions BlueprintPurge/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [0.5.0]
- removed string restriction on $type
- fixed preceding comma, when purging last entry in a list

## [0.4.0]
- added ability to filter $type; simply put it in the blueprint textbox

Expand Down

0 comments on commit 72c945a

Please sign in to comment.