Skip to content

Commit

Permalink
scroll position cache, expand first level always, add copy/pastable n…
Browse files Browse the repository at this point in the history
…ame+type
  • Loading branch information
factubsio committed Mar 12, 2022
1 parent 5bb65c6 commit f32ed67
Show file tree
Hide file tree
Showing 6 changed files with 270 additions and 67 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

# IDE0022: Use block body for methods
csharp_style_expression_bodied_methods = when_on_single_line

# RCS1123: Add parentheses when necessary.
dotnet_diagnostic.RCS1123.severity = silent
85 changes: 63 additions & 22 deletions BlueprintExplorer/BlueprintControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,27 @@ public class BlueprintControl : ScrollableControl
public event LinkClickedDelegate OnLinkClicked;
public event PathDelegate OnPathHovered;

private BlueprintHandle blueprint;
private Dictionary<string, int> ScrollPositionCache = new();

private IDisplayableElementCollection DisplayedObject;

private Timer ToastTimer;
private Stopwatch Timer = new();
private long LastTick = 0;

public BlueprintHandle Blueprint
public IDisplayableElementCollection Blueprint
{
get => blueprint;
get => DisplayedObject;
set
{
if (blueprint == value) return;
blueprint = value;
blueprint.EnsureParsed();
ValidateBlueprint();
if (DisplayedObject == value) return;
if (DisplayedObject != null)
{
ScrollPositionCache[DisplayedObject.GuidText] = VerticalScroll.Value;
}
DisplayedObject = value;
DisplayedObject.EnsureParsed();
ValidateBlueprint(true);
}
}

Expand Down Expand Up @@ -70,7 +76,7 @@ public StyleSpan(string value, StyleFlags flags = 0) {

public StyleSpan[] Spans;

public String Raw => string.Join("", Spans.Select(s => s.Value));
public String Raw => string.Concat(Spans.Select(s => s.Value));
}

public class RowElement
Expand Down Expand Up @@ -266,33 +272,57 @@ private void ValidateFilter()

int StringWidthAllowed => Width - NameColumnWidth - 32;

private void ValidateBlueprint()
private void ValidateBlueprint(bool scroll)
{
Elements.Clear();
var oneRow = Font.Height;
using var g = CreateGraphics();
int strWidthAllowed = StringWidthAllowed;
currentHover = -1;
int totalRows = 0;
if (blueprint != null)
if (DisplayedObject != null)
{
Elements.Add(new ()
{
key = "Blueprint ID",
value = blueprint.GuidText,
value = DisplayedObject.GuidText,
level = 0,
link = null,
Parent = null,
String = null,
RowCount = 1,
Collapsed = true,
});
Elements.Add(new ()
{
key = "Blueprint Name",
value = DisplayedObject.Name,
level = 1,
link = null,
Parent = Elements[0],
String = null,
RowCount = 1,
Collapsed = false,
});
Elements.Add(new ()
{
key = "Blueprint Type",
value = DisplayedObject.TypeName,
level = 1,
link = null,
Parent = Elements[0],
String = null,
RowCount = 1,
Collapsed = false,
});
totalRows = 1;
Elements[0].Children.Add(Elements[1]);
Elements[0].Children.Add(Elements[2]);
totalRows = 3;

int level = 0;
Stack<RowElement> stack = new();
stack.Push(null);
foreach (var e in blueprint.Elements)
foreach (var e in DisplayedObject.DisplayableElements)
{
int currentLevel = level;

Expand Down Expand Up @@ -322,26 +352,25 @@ private void ValidateBlueprint()
String = JsonExtensions.ParseAsString(e.Node),
RowCount = 1,
IsObj = e.isObj,
Collapsed = totalRows != 0 && !BubblePrints.Settings.EagerExpand,
Collapsed = totalRows != 0 && !BubblePrints.Settings.EagerExpand && currentLevel > 0,
};

if (e.isObj && e.Node.TryGetProperty("$type", out var rawType))
if (e.isObj && e.HasType)
{
var (typeGuid, typeName, typeNameFull) = rawType.NewTypeStr();
List<StyledString.StyleSpan> spans = new();
spans.Add(new(typeName + " ", StyleFlags.Bold));
spans.Add(new("typeId: " + typeGuid));
spans.Add(new(e.MaybeType.Name + " ", StyleFlags.Bold));
spans.Add(new("typeId: " + e.MaybeType.Guid));
row.ValueStyled = new(spans);
row.Type = typeName;
row.TypeFull = typeNameFull;
row.Type = e.MaybeType.Name;
row.TypeFull = e.MaybeType.FullName;
}

if (row.key == "$type" && row.Parent != null)
continue;

if (e.levelDelta == 0 && row.Parent != null)
{
row.Default = BlueprintDB.DefaultForField(row.Parent?.TypeFull, e.key);
row.Default = BlueprintDB.Instance.DefaultForField(row.Parent?.TypeFull, e.key);
}

if (row.String != null)
Expand Down Expand Up @@ -393,6 +422,18 @@ private void ValidateBlueprint()
}
}
AutoScroll = true;
if (scroll)
{
if (ScrollPositionCache.TryGetValue(DisplayedObject.GuidText, out var scrollPosition))
{
VerticalScroll.Value = scrollPosition;
}
else
{
VerticalScroll.Value = 0;

}
}
ValidateFilter();
}

Expand All @@ -409,7 +450,7 @@ private RowElement GetElement(int row)
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
ValidateBlueprint();
ValidateBlueprint(false);
}

private string _Filter;
Expand Down
93 changes: 63 additions & 30 deletions BlueprintExplorer/BlueprintDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class BlueprintDB
#region DEV
bool generateOutput = false;
bool importNew = false;
bool forceLastKnown = true;
bool forceLastKnown = false;
#endregion

private static BlueprintDB _Instance;
Expand Down Expand Up @@ -100,7 +100,7 @@ public int CompareTo(GameVersion other)

public List<GameVersion> Available = new() { };

private readonly GameVersion LastKnown = new(1, 2, 0, 'f', 1);
private readonly GameVersion LastKnown = new(1, 2, 0, 'A', 1);

private readonly string filenameRoot = "blueprints_raw";
private readonly string extension = "binz";
Expand Down Expand Up @@ -196,8 +196,8 @@ public GoingToLoad GetLoadType()

}

private static Dictionary<string, Dictionary<string, string>> defaults = new();
public static string DefaultForField(string typename, string field)
private Dictionary<string, Dictionary<string, string>> defaults = new();
public string DefaultForField(string typename, string field)
{
if (typename == null || !defaults.TryGetValue(typename, out var map))
return null;
Expand All @@ -213,7 +213,7 @@ public class ConnectionProgress

public string Status => EstimatedTotal == 0 ? "??" : $"{Current}/{EstimatedTotal} - {(Current / (double)EstimatedTotal):P1}";
}
public async Task<bool> TryConnect(ConnectionProgress progress)
public async Task<bool> TryConnect(ConnectionProgress progress, string forceFileName = null)
{
if (importNew)
{
Expand Down Expand Up @@ -324,32 +324,37 @@ public async Task<bool> TryConnect(ConnectionProgress progress)

string fileToOpen = null;

switch (GetLoadType())
if (forceFileName != null)
fileToOpen = forceFileName;
else
{
case GoingToLoad.FromWeb:
Console.WriteLine("Settings file does not exist, downloading");
var host = "https://github.com/factubsio/BubblePrintsData/releases/download";
var latestVersionUrl = new Uri($"{host}/{Latest}/{filenameRoot}_{Latest}.{extension}");

var client = new WebClient();
if (!Directory.Exists(CacheDir))
Directory.CreateDirectory(CacheDir);

fileToOpen = Path.Combine(CacheDir, FileName);
progress.EstimatedTotal = 100;
client.DownloadProgressChanged += (sender, e) =>
{
progress.Current = e.ProgressPercentage;
};
await client.DownloadFileTaskAsync(latestVersionUrl, fileToOpen);
break;
case GoingToLoad.FromCache:
fileToOpen = Path.Combine(CacheDir, FileName);
break;
case GoingToLoad.FromLocalFile:
Console.WriteLine("reading from local dev...");
fileToOpen = FileName;
break;
switch (GetLoadType())
{
case GoingToLoad.FromWeb:
Console.WriteLine("Settings file does not exist, downloading");
var host = "https://github.com/factubsio/BubblePrintsData/releases/download";
var latestVersionUrl = new Uri($"{host}/{Latest}/{filenameRoot}_{Latest}.{extension}");

var client = new WebClient();
if (!Directory.Exists(CacheDir))
Directory.CreateDirectory(CacheDir);

fileToOpen = Path.Combine(CacheDir, FileName);
progress.EstimatedTotal = 100;
client.DownloadProgressChanged += (sender, e) =>
{
progress.Current = e.ProgressPercentage;
};
await client.DownloadFileTaskAsync(latestVersionUrl, fileToOpen);
break;
case GoingToLoad.FromCache:
fileToOpen = Path.Combine(CacheDir, FileName);
break;
case GoingToLoad.FromLocalFile:
Console.WriteLine("reading from local dev...");
fileToOpen = FileName;
break;
}
}

BPFile.Reader reader = new(fileToOpen);
Expand Down Expand Up @@ -490,6 +495,34 @@ public async Task<bool> TryConnect(ConnectionProgress progress)
BubblePrints.SaveSettings();
ctx.Dispose();

//File.WriteAllLines(@"D:\areas.txt", cache.Where(b => b.TypeName == "BlueprintAbilityAreaEffect").SelectMany(bp =>
//{
// return new String[]
// {
// $"//{bp.Name}",
// "{",
// $" \"ability\": \"{bp.GuidText}\"",
// " \"type\": \"bad\"",
// "},",

// };
//}));

//var featureType = BubblePrints.Wrath.GetType("Kingmaker.Blueprints.Classes.BlueprintFeature");
//int featuresFound = 0;
//List<(string, string)> features = new();
//foreach (var bp in cache)
//{
// var type = BubblePrints.Wrath.GetType(bp.Type);
// if (type == null) continue;
// if (type.IsAssignableTo(featureType))
// {
// featuresFound++;
// features.Add((bp.Name, bp.GuidText));
// }
//}
//Console.WriteLine("Features found: " + featuresFound);
//File.WriteAllLines(@"D:\features.txt", features.Select(f => $"{f.Item2} {f.Item1}"));
}


Expand Down
Loading

0 comments on commit f32ed67

Please sign in to comment.