Skip to content

Commit 7ba38d2

Browse files
committed
Recursively iterating through nodes to display nested properties
1 parent b1adbcf commit 7ba38d2

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

WzVisualizer/GUI/Form1.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private void AddHairRow(WzImage image) {
9898

9999
private void AddGridRow(DataGridView grid, object wzObject) {
100100
int id;
101-
string properties = "";
101+
string properties = BuildProperties(wzObject);
102102
string name = null;
103103
WzCanvasProperty icon = null;
104104

@@ -144,7 +144,6 @@ private void AddGridRow(DataGridView grid, object wzObject) {
144144
icon = (WzCanvasProperty)subProperty.GetFromPath("icon");
145145
} else { // for breadcrumb like: 'category.img/{ID}/info/icon' (etc.wz)
146146
string imgName = subProperty.Name;
147-
properties = BuildProperties(subProperty);
148147
id = int.Parse(imgName);
149148
if (ItemConstants.IsEtc(id)) name = StringUtility.GetEtc(id);
150149
else if (ItemConstants.IsCash(id)) name = StringUtility.GetCash(id);
@@ -170,23 +169,27 @@ private void AddGridRow(DataGridView grid, object wzObject) {
170169
/// <param name="wzObject">a WzSubProperty or WzImage</param>
171170
/// <returns></returns>
172171
private string BuildProperties(object wzObject) {
173-
string properties = "";
174172
WzImageProperty infoRoot = null;
175-
if (wzObject is WzSubProperty subProperty) infoRoot = subProperty.GetFromPath("info");
173+
if (wzObject is WzSubProperty subProperty) infoRoot = subProperty.GetFromPath("info") ?? subProperty.GetFromPath("level");
176174
else if (wzObject is WzImage wzImage) infoRoot = wzImage.GetFromPath("info");
177-
if (infoRoot?.WzProperties != null) {
178-
foreach (WzImageProperty imgProperties in infoRoot.WzProperties) {
179-
switch (imgProperties.PropertyType) {
180-
default:
181-
properties += $"\r\n{imgProperties.Name}={imgProperties.WzValue}";
182-
break;
183-
case WzPropertyType.Canvas:
184-
case WzPropertyType.PNG:
185-
case WzPropertyType.Sound:
186-
break;
187-
}
188-
}
189175

176+
return ExtractProperties(infoRoot, "");
177+
}
178+
179+
private string ExtractProperties(WzImageProperty p, string prefix) {
180+
if (p?.WzProperties == null) return "";
181+
string properties = "";
182+
foreach (WzImageProperty imgProperties in p.WzProperties) {
183+
switch (imgProperties.PropertyType) {
184+
default:
185+
properties += $"\r\n{prefix}{imgProperties.Name}={imgProperties.WzValue}";
186+
if (imgProperties.PropertyType == WzPropertyType.SubProperty) properties += ExtractProperties(imgProperties, "\t" + prefix);
187+
break;
188+
case WzPropertyType.Canvas:
189+
case WzPropertyType.PNG:
190+
case WzPropertyType.Sound:
191+
break;
192+
}
190193
}
191194
return properties;
192195
}
@@ -643,7 +646,7 @@ private void Tab_Selected(object sender, TabPage tab) {
643646
break;
644647
}
645648
case TabControl childTab: {
646-
DataViewer view = (DataViewer) childTab.SelectedTab.Controls[0];
649+
DataViewer view = (DataViewer)childTab.SelectedTab.Controls[0];
647650
GridIOUtility.ImportGrid($"{TabControlMain.SelectedTab.Text}/{tab.Text}.bin", view.GridView,
648651
AddGridRow);
649652
break;

0 commit comments

Comments
 (0)