From f0ee3ad742470e913d2fe3f2493b425200b3bc78 Mon Sep 17 00:00:00 2001 From: Ulysses Wu Date: Sun, 19 Jun 2022 23:19:16 +0800 Subject: [PATCH] Support krkr timeline folder, Fix #81 --- .../Properties/AssemblyInfo.cs | 4 +- .../Converters/Common2KrkrConverter.cs | 82 +++++++++++++++++++ .../Converters/Krkr2CommonConverter.cs | 35 ++++++++ .../Properties/AssemblyInfo.cs | 4 +- .../Properties/AssemblyInfo.cs | 4 +- .../Properties/AssemblyInfo.cs | 4 +- FreeMote.sln.DotSettings | 1 + FreeMote/Properties/AssemblyInfo.cs | 4 +- 8 files changed, 128 insertions(+), 10 deletions(-) diff --git a/FreeMote.Plugins.x64/Properties/AssemblyInfo.cs b/FreeMote.Plugins.x64/Properties/AssemblyInfo.cs index c51bbb4..28936b3 100644 --- a/FreeMote.Plugins.x64/Properties/AssemblyInfo.cs +++ b/FreeMote.Plugins.x64/Properties/AssemblyInfo.cs @@ -15,5 +15,5 @@ [assembly: Guid("7b5bae81-6779-4404-9e6e-512be4471ab9")] // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.2.0.0")] -[assembly: AssemblyFileVersion("3.2.0.0")] +[assembly: AssemblyVersion("3.3.0.0")] +[assembly: AssemblyFileVersion("3.3.0.0")] diff --git a/FreeMote.PsBuild/Converters/Common2KrkrConverter.cs b/FreeMote.PsBuild/Converters/Common2KrkrConverter.cs index 0b3ac28..43f19ac 100644 --- a/FreeMote.PsBuild/Converters/Common2KrkrConverter.cs +++ b/FreeMote.PsBuild/Converters/Common2KrkrConverter.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using FreeMote.Psb; using FreeMote.Psb.Textures; // ReSharper disable CompareOfFloatsByEqualityOperator @@ -38,6 +39,7 @@ public void Convert(PSB psb) { Add(psb); } + TranslateTimeline(psb); psb.Platform = PsbSpec.krkr; } @@ -248,5 +250,85 @@ private void Add(PSB psb) metadata.Add("attrcomp", new PsbDictionary(1)); } } + + private void TranslateTimeline(PSB psb) + { + PsbList nList = new PsbList(); + + void Insert(PsbList list, string path, PsbDictionary item) + { + if (ConvertOption == SpecConvertOption.Minimum) + { + item.Remove("hint_path"); + } + var paths = path.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries); + var currentFolderChildren = list; + for (var i = 0; i < paths.Length - 1; i++) + { + var folder = paths[i]; + if (currentFolderChildren.FirstOrDefault(v => + v is PsbDictionary dic && dic["type"] is PsbString {Value: "folder"} && dic["label"] is PsbString label && + label == folder) is not PsbDictionary targetFolder) + { + var targetFolderChildren = new PsbList(); + targetFolder = new PsbDictionary + { + {"label", folder.ToPsbString()}, + {"type", "folder".ToPsbString()}, + {"children", targetFolderChildren} + }; + currentFolderChildren.Add(targetFolder); + currentFolderChildren = targetFolderChildren; + } + else + { + if (targetFolder["children"] is PsbList children) + { + currentFolderChildren = children; + } + else + { + var targetFolderChildren = new PsbList(); + targetFolder["children"] = targetFolderChildren; + currentFolderChildren = targetFolderChildren; + } + } + } + + if (currentFolderChildren != null) + { + currentFolderChildren.Add(item); + } + else + { + Console.WriteLine($"[WARN] Failed to insert to path {path}, it will be in root path."); + list.Add(item); + } + } + + void TranslateChildren(PsbList timelineList) + { + foreach (var timeline in timelineList) + { + if (timeline is PsbDictionary item) + { + if (item["path_hint"] is PsbString hint) + { + Insert(nList, hint.Value, item); + } + else + { + nList.Add(item); + } + } + } + } + + if (psb.Objects["metadata"] is PsbDictionary metadata && metadata["timelineControl"] is PsbList timelines) + { + TranslateChildren(timelines); + metadata["timelineControl"] = nList; + } + } } } \ No newline at end of file diff --git a/FreeMote.PsBuild/Converters/Krkr2CommonConverter.cs b/FreeMote.PsBuild/Converters/Krkr2CommonConverter.cs index 47e6dc2..246745a 100644 --- a/FreeMote.PsBuild/Converters/Krkr2CommonConverter.cs +++ b/FreeMote.PsBuild/Converters/Krkr2CommonConverter.cs @@ -64,6 +64,7 @@ public void Convert(PSB psb) var iconInfo = TranslateResources(psb); Travel((PsbDictionary) psb.Objects["object"], iconInfo); Add(psb); + TranslateTimeline(psb); psb.Platform = ToWin ? PsbSpec.win : PsbSpec.common; } @@ -422,5 +423,39 @@ private void Travel(IPsbCollection collection, DictionaryTrue True True + True True True diff --git a/FreeMote/Properties/AssemblyInfo.cs b/FreeMote/Properties/AssemblyInfo.cs index 627ba22..0f40530 100644 --- a/FreeMote/Properties/AssemblyInfo.cs +++ b/FreeMote/Properties/AssemblyInfo.cs @@ -21,5 +21,5 @@ [assembly: InternalsVisibleTo("FreeMote.Tests")] // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.2.1.0")] -[assembly: AssemblyFileVersion("3.2.1.0")] +[assembly: AssemblyVersion("3.3.0.0")] +[assembly: AssemblyFileVersion("3.3.0.0")]