Skip to content

Commit

Permalink
Support krkr timeline folder, Fix #81
Browse files Browse the repository at this point in the history
  • Loading branch information
UlyssesWu committed Jun 19, 2022
1 parent 11bac3d commit f0ee3ad
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 10 deletions.
4 changes: 2 additions & 2 deletions FreeMote.Plugins.x64/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
82 changes: 82 additions & 0 deletions FreeMote.PsBuild/Converters/Common2KrkrConverter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FreeMote.Psb;
using FreeMote.Psb.Textures;
// ReSharper disable CompareOfFloatsByEqualityOperator
Expand Down Expand Up @@ -38,6 +39,7 @@ public void Convert(PSB psb)
{
Add(psb);
}
TranslateTimeline(psb);

psb.Platform = PsbSpec.krkr;
}
Expand Down Expand Up @@ -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;
}
}
}
}
35 changes: 35 additions & 0 deletions FreeMote.PsBuild/Converters/Krkr2CommonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -422,5 +423,39 @@ private void Travel(IPsbCollection collection, Dictionary<string, (string Tex, s
}
}
}

private void TranslateTimeline(PSB psb)
{
PsbList nList = new PsbList();

void TranslateChildren(PsbList childrenList, string path)
{
foreach (var timeline in childrenList)
{
if (timeline is PsbDictionary item)
{
if (item["type"] is PsbString { Value: "folder" } && item["children"] is PsbList children)
{
TranslateChildren(children, $"{path}/{item["label"].ToString()}");
}
else if (item["variableList"] is PsbList variableList)
{
item["path_hint"] = $"{path}/{item["label"].ToString()}".ToPsbString();
nList.Add(item);
}
else
{
Console.WriteLine($"[WARN] Cannot convert timeline {item["label"].ToString()}");
}
}
}
}

if (psb.Objects["metadata"] is PsbDictionary metadata && metadata["timelineControl"] is PsbList timelines)
{
TranslateChildren(timelines, "");
metadata["timelineControl"] = nList;
}
}
}
}
4 changes: 2 additions & 2 deletions FreeMote.Tools.EmtConvert/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

[assembly: Guid("44270712-4acb-447d-835e-9982bd515dbb")]

[assembly: AssemblyVersion("3.2.1.0")]
[assembly: AssemblyFileVersion("3.2.1.0")]
[assembly: AssemblyVersion("3.3.0.0")]
[assembly: AssemblyFileVersion("3.3.0.0")]
4 changes: 2 additions & 2 deletions FreeMote.Tools.EmtMake/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
[assembly: Guid("bd8855cf-0b99-43b2-8b92-4013e9a0c41c")]

// [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")]
4 changes: 2 additions & 2 deletions FreeMote.Tools.Viewer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.2.1.*")]
[assembly: AssemblyFileVersion("3.2.1.0")]
[assembly: AssemblyVersion("3.3.0.*")]
[assembly: AssemblyFileVersion("3.3.0.0")]
1 change: 1 addition & 0 deletions FreeMote.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=krkr/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=loopstr/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tachie/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=timelines/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unswizzle/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=XWMA/@EntryIndexedValue">True</s:Boolean>

Expand Down
4 changes: 2 additions & 2 deletions FreeMote/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]

0 comments on commit f0ee3ad

Please sign in to comment.