1
0
mirror of https://github.com/Raymonf/whack.git synced 2024-11-24 00:20:10 +01:00
This commit is contained in:
Raymonf 2022-11-08 00:26:44 -05:00
parent 73bb8b41e8
commit 885854e8dc
No known key found for this signature in database
GPG Key ID: 438459BF619B037A
3 changed files with 56 additions and 36 deletions

View File

@ -3,12 +3,13 @@ using UAssetAPI;
using UAssetAPI.PropertyTypes.Structs;
using UAssetAPI.UnrealTypes;
using WhackTranslationTool.Exceptions;
using WTT;
namespace WhackTranslationTool;
public class TableExporter
{
private readonly char[] _multilineChars = { '\n', '"' };
private readonly ExportSettings _settings;
private Dictionary<string, TomlTable> strings = new();
@ -33,22 +34,10 @@ public class TableExporter
private TomlTable MessageDataToTomlTable(StructPropertyData entry)
{
var tomlTable = new TomlTable();
var japaneseValue = (entry.Value[0].RawValue as FString)?.Value;
if (japaneseValue != null)
tomlTable.Add("JapaneseMessage", new TomlString
{
IsMultiline = japaneseValue.IndexOfAny(_multilineChars) != -1,
Value = japaneseValue
});
var koreanValue = (entry.Value[6].RawValue as FString)?.Value;
if (koreanValue != null)
tomlTable.Add("KoreanMessage", new TomlString
{
IsMultiline = koreanValue.IndexOfAny(_multilineChars) != -1,
Value = koreanValue
});
tomlTable.AddMessage(entry, 0, "JapaneseMessage");
tomlTable.AddMessage(entry, 1, "EnglishMessageUSA");
tomlTable.AddMessage(entry, 6, "KoreanMessage");
return tomlTable;
}
@ -56,22 +45,11 @@ public class TableExporter
private TomlTable CharacterMessageDataToTomlTable(StructPropertyData entry)
{
var tomlTable = new TomlTable();
var japaneseValue = (entry.Value[3].RawValue as FString)?.Value;
if (japaneseValue != null)
tomlTable.Add("JapaneseMessage", new TomlString
{
IsMultiline = japaneseValue.IndexOfAny(_multilineChars) != -1,
Value = japaneseValue
});
var koreanValue = (entry.Value[9].RawValue as FString)?.Value;
if (koreanValue != null)
tomlTable.Add("KoreanMessage", new TomlString
{
IsMultiline = koreanValue.IndexOfAny(_multilineChars) != -1,
Value = koreanValue
});
tomlTable.AddMessage(entry, 3, "JapaneseMessage");
tomlTable.AddMessage(entry, 4, "EnglishMessageUSA");
if (_settings.ExportKoreanMessage)
tomlTable.AddMessage(entry, 9, "KoreanMessage");
return tomlTable;
}

View File

@ -74,7 +74,8 @@ public class TableImporter
throw new InvalidDataException($"key '{key}' is invalid");
if (strings.ContainsKey(key))
throw new DuplicateKeyException($"duplicate key '{key}' found for file {tomlPath} ({asset.FilePath})");
strings.Add(key, value.HasKey("JapaneseMessage") ? value["JapaneseMessage"].AsString.Value : null);
var exists = value.HasKey("EnglishMessageUSA") && value["EnglishMessageUSA"].IsString;
strings.Add(key, exists ? value["EnglishMessageUSA"].AsString.Value : null);
}
}
@ -94,13 +95,25 @@ public class TableImporter
}
// index of JapaneseMessage
var index = entry.StructType.Value.Value switch
var jpnIndex = entry.StructType.Value.Value switch
{
"MessageData" => 0,
"CharaMessageData" => 3,
_ => throw new Exception($"Unhandled type '{entry.StructType}'")
};
entry.Value[index].SetObject(FString.FromString(strings[name]));
// index of EnglishMessageUSA
var engIndex = entry.StructType.Value.Value switch
{
"MessageData" => 1,
"CharaMessageData" => 4,
_ => throw new Exception($"Unhandled type '{entry.StructType}'")
};
// set the string as the english string if it isn't the same as the japanese string
if (strings[name] != null && ((FString)entry.Value[jpnIndex].RawValue).Value != strings[name])
{
entry.Value[engIndex].SetObject(FString.FromString(strings[name]));
}
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tommy;
using UAssetAPI.PropertyTypes.Structs;
using UAssetAPI.UnrealTypes;
namespace WTT
{
public static class TomlTableExtensions
{
private readonly static char[] _multilineChars = { '\n', '"' };
public static void AddMessage(this TomlTable tomlTable, StructPropertyData entry, int index, string key)
{
var value = (entry.Value[index].RawValue as FString)?.Value;
if (value != null)
tomlTable.Add(key, new TomlString
{
IsMultiline = value.IndexOfAny(_multilineChars) != -1,
Value = value
});
else
tomlTable.Add(key, false);
}
}
}