0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-10-13 23:10:23 +03:00
Files
ParkanPlayground/NResUI/Models/CpDatSchemeViewModel.cs

50 lines
1.1 KiB
C#
Raw Normal View History

2025-09-04 02:45:26 +03:00
using CpDatLib;
using ScrLib;
namespace NResUI.Models;
public class CpDatSchemeViewModel
{
public bool HasFile { get; set; }
public string? Error { get; set; }
public CpDatScheme? CpDatScheme { get; set; }
2025-10-05 18:17:18 +03:00
public List<(int Level, CpDatEntry Entry)> FlatList { get; set; } = [];
2025-09-04 02:45:26 +03:00
public string? Path { get; set; }
public void SetParseResult(CpDatParseResult parseResult, string path)
{
CpDatScheme = parseResult.Scheme;
Error = parseResult.Error;
HasFile = true;
Path = path;
if (CpDatScheme is not null)
{
2025-10-05 18:17:18 +03:00
RebuildFlatList();
}
}
public void RebuildFlatList()
{
FlatList = [];
if (CpDatScheme is null)
{
return;
}
2025-09-04 02:45:26 +03:00
2025-10-05 18:17:18 +03:00
CollectEntries(CpDatScheme.Root, 0);
2025-09-04 02:45:26 +03:00
2025-10-05 18:17:18 +03:00
void CollectEntries(CpDatEntry entry, int level)
{
FlatList.Add((level, entry));
foreach (var child in entry.Children)
2025-09-04 02:45:26 +03:00
{
2025-10-05 18:17:18 +03:00
CollectEntries(child, level + 1);
2025-09-04 02:45:26 +03:00
}
}
}
}