Skip to content

Commit

Permalink
Fixed DataViewer alignment and hid backing fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
se5a committed Mar 1, 2024
1 parent b16943e commit 61c3908
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"MaterialID": "plastic",
"HitPoints": "255",
"MeltingPoint": "170",
"Density": "1175f"
"Density": "1175"
}
},
{
Expand All @@ -26,7 +26,7 @@
"MaterialID": "aluminium",
"HitPoints": "0",
"MeltingPoint": "660",
"Density": "2700f"
"Density": "2700"
}
},
{
Expand All @@ -36,7 +36,7 @@
"MaterialID": "titanium",
"HitPoints": "255",
"MeltingPoint": "1668",
"Density": "4540f"
"Density": "4540"
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion Pulsar4X/GameEngine/Data/basemod/modInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"systemGenSettings.json",
"techCategories.json",
"techs.json",
"weapons.json"
"weapons.json",
"damageResistance.json"
]
}
5 changes: 4 additions & 1 deletion Pulsar4X/GameEngine/FeatureSets/DamageComplex/DamageTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public DamageResistBlueprint(byte iDCode, int hitPoints, float density)
//Heat = heat;
//Kinetic = kinetic;
Density = density; //kg/m^3
DamageTools.DamageResistsLookupTable.Add(IDCode, this);
if (DamageTools.DamageResistsLookupTable.ContainsKey(iDCode))
DamageTools.DamageResistsLookupTable[iDCode] = this;
else
DamageTools.DamageResistsLookupTable.Add(IDCode, this);
}
}

Expand Down
6 changes: 3 additions & 3 deletions Pulsar4X/GameEngine/Modding/ModInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public enum DataType
Tech,
TechCategory,
Theme,
DamageResist,
DamageResistance,
}
public enum OperationType { Default, Remove }
public enum CollectionOperationType { Add, Remove, Overwrite }
Expand Down Expand Up @@ -98,8 +98,8 @@ public override bool CanConvert(Type objectType)
case ModInstruction.DataType.Theme:
instruction.Data = jObject["Payload"].ToObject<ThemeBlueprint>();
break;
case ModInstruction.DataType.DamageResist:
instruction.Data = jObject["DamageResistance"].ToObject<DamageResistBlueprint>();
case ModInstruction.DataType.DamageResistance:
instruction.Data = jObject["Payload"].ToObject<DamageResistBlueprint>();
break;
}

Expand Down
2 changes: 1 addition & 1 deletion Pulsar4X/GameEngine/Modding/ModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private void ApplyMod(ModDataStore baseData, ModInstruction mod, string modNames
case ModInstruction.DataType.Theme:
ApplyModGeneric<ThemeBlueprint>(baseData.Themes, mod, modNamespace);
break;
case ModInstruction.DataType.DamageResist:
case ModInstruction.DataType.DamageResistance:
ApplyModGeneric<DamageResistBlueprint>(baseData.DamageResists, mod, modNamespace);
break;
}
Expand Down
35 changes: 22 additions & 13 deletions Pulsar4X/Pulsar4X.Client/DebugAndPData/DataViewerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using ImGuiNET;
using Pulsar4X.Engine;
using Pulsar4X.Engine.Industry;
Expand Down Expand Up @@ -119,8 +120,11 @@ public static void DisplayDataObj(object dataObj)

if (ImGui.TreeNode(de.Key.ToString()))
{
ImGui.NextColumn();
ImGui.NextColumn();
_numLines += itemsCount;
RecursiveReflection(de.Value);
ImGui.Unindent();
ImGui.Separator();
}
else
Expand Down Expand Up @@ -249,7 +253,7 @@ static void RecursiveReflection(object obj)
if (typeof(FieldInfo).IsAssignableFrom(memberInfo.GetType()) || typeof(PropertyInfo).IsAssignableFrom(memberInfo.GetType()))
{
value = GetValue(memberInfo, obj);
if(value == null)
if(value == null || memberInfo.GetCustomAttribute<CompilerGeneratedAttribute>()!= null)
continue;
if (typeof(ICollection).IsAssignableFrom(value.GetType()))
{
Expand Down Expand Up @@ -438,24 +442,29 @@ static void RecursiveReflection(object obj)

static object? GetValue(this MemberInfo memberInfo, object forObject)
{
switch (memberInfo.MemberType)
{
case MemberTypes.Field:
return ((FieldInfo)memberInfo).GetValue(forObject);
case MemberTypes.Property:

switch (memberInfo.MemberType)
{
try
case MemberTypes.Field:
{
return ((PropertyInfo)memberInfo).GetValue(forObject);

return ((FieldInfo)memberInfo).GetValue(forObject);
}
catch (Exception e)
case MemberTypes.Property:
{
return "";
try
{
return ((PropertyInfo)memberInfo).GetValue(forObject);
}
catch (Exception e)
{
return "";
}

}

}

}
}

return "";
}
}

0 comments on commit 61c3908

Please sign in to comment.