Skip to content

Commit

Permalink
spell/buff descriptor enum flags to string
Browse files Browse the repository at this point in the history
  • Loading branch information
factubsio committed May 22, 2022
1 parent b860a1f commit 95a0420
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
45 changes: 45 additions & 0 deletions BlueprintExplorer/BlueprintControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,54 @@ private void ValidateBlueprint(bool scroll)
row.TypeFull = e.MaybeType.FullName;
}

if (e.isObj && !e.HasType)
{
var parent = stack.Peek();
if (!parent.IsObj)
{
row.TypeFull = parent.TypeFull;
row.Type = parent.Type;
}
else
{
var type = BlueprintDB.Instance.TypeForField(parent.TypeFull, e.key);
if (type != null)
{
row.TypeFull = type.FullName;
row.Type = type.Name;
}
}
}

if (e.levelDelta > 0 && !e.isObj)
{
var parent = stack.Peek();
var type = BlueprintDB.Instance.TypeForField(parent.TypeFull, e.key);

if (type != null)
{
if (type.GenericTypeArguments.Length == 1)
type = type.GenericTypeArguments[0];
else if (type.HasElementType)
type = type.GetElementType();

row.TypeFull = type.FullName;
row.Type = type.Name;
}
}

if (row.key == "m_IntValue" && row.Parent.TypeFull == "Kingmaker.Blueprints.Classes.Spells.SpellDescriptorWrapper")
{
List<StyledString.StyleSpan> spans = new();
spans.Add(new(row.value + " - ", StyleFlags.Bold));
spans.Add(new(Enum.Parse(BubblePrints.Wrath.GetType("Kingmaker.Blueprints.Classes.Spells.SpellDescriptor"), row.value).ToString(), 0));
row.ValueStyled = new(spans);
}

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


if (e.levelDelta == 0 && row.Parent != null)
{
row.Default = BlueprintDB.Instance.DefaultForField(row.Parent?.TypeFull, e.key);
Expand Down
51 changes: 50 additions & 1 deletion BlueprintExplorer/BlueprintDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public int CompareTo(GameVersion other)

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

private readonly GameVersion LastKnown = new(1, 3, 2, 'c', 0);
private readonly GameVersion LastKnown = new(1, 3, 4, 'e', 0);

private readonly string filenameRoot = "blueprints_raw";
private readonly string extension = "binz";
Expand Down Expand Up @@ -220,6 +220,55 @@ public GoingToLoad GetLoadType()
}

private Dictionary<string, Dictionary<string, string>> defaults = new();
private Dictionary<string, Dictionary<string, Type>> fieldTypes = new();
private Dictionary<string, Type> nullDict = new();

private IEnumerable<(string name, Type type)> FieldTypes(Type of)
{
if (of.BaseType != null)
foreach (var t in FieldTypes(of.BaseType))
yield return t;

foreach (var f in of.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
yield return (f.Name, f.FieldType);
}

public Type TypeForField(string typename, string field)
{
if (BubblePrints.Wrath == null || typename == null)
return null;

if (fieldTypes.TryGetValue(typename, out var fields))
{
if (fields.TryGetValue(field, out var fieldType))
return fieldType;
return null;
}
else
{
var t = BubblePrints.Wrath.GetType(typename);
if (t == null)
{
fieldTypes[typename] = nullDict;
return null;
}

var fieldTypeDict = new Dictionary<string, Type>();

foreach (var prop in t.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
fieldTypeDict[prop.Name] = prop.PropertyType;

foreach (var (fname, ftype) in FieldTypes(t))
fieldTypeDict[fname] = ftype;

fieldTypes[typename] = fieldTypeDict;

if (fieldTypeDict.TryGetValue(field, out var fieldType))
return fieldType;

return null;
}
}
public string DefaultForField(string typename, string field)
{
if (typename == null || !defaults.TryGetValue(typename, out var map))
Expand Down

0 comments on commit 95a0420

Please sign in to comment.