1
0
mirror of https://github.com/Raymonf/whack.git synced 2024-11-27 17:40:48 +01:00

Add crappy settings support

I should fix this lol
This commit is contained in:
Raymonf 2023-03-04 14:47:15 -05:00
parent 74b9a908b4
commit 396996c4ab
No known key found for this signature in database
GPG Key ID: 438459BF619B037A
12 changed files with 110 additions and 25 deletions

View File

@ -1,4 +1,4 @@
namespace WhackTranslationTool.Exceptions; namespace WTT.Exceptions;
public class DuplicateKeyException : Exception public class DuplicateKeyException : Exception
{ {

View File

@ -1,4 +1,4 @@
namespace WhackTranslationTool.Exceptions; namespace WTT.Exceptions;
public class MissingKeyException : Exception public class MissingKeyException : Exception
{ {

View File

@ -1,4 +1,4 @@
namespace WhackTranslationTool.Exceptions; namespace WTT.Exceptions;
public class UnhandledTomlError : Exception public class UnhandledTomlError : Exception
{ {

View File

@ -1,4 +1,4 @@
namespace WhackTranslationTool.Exceptions; namespace WTT.Exceptions;
public class UnsupportedAssetException : Exception public class UnsupportedAssetException : Exception
{ {

View File

@ -1,4 +1,4 @@
namespace WhackTranslationTool; namespace WTT;
public class ExportSettings public class ExportSettings
{ {

13
WTT/WTT/ImportSettings.cs Normal file
View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WTT
{
internal class ImportSettings
{
public Language Language { get; set; } = Language.EnglishUSA;
}
}

View File

@ -2,10 +2,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace WTT namespace WTT
{ {
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum Language public enum Language
{ {
Japanese, Japanese,

View File

@ -1,4 +1,5 @@
using WhackTranslationTool; using System.Text.Json;
using WTT;
string? basePath = null; // @"WindowsNoEditor\Mercury\Content\Message"; string? basePath = null; // @"WindowsNoEditor\Mercury\Content\Message";
bool? overwrite = null; bool? overwrite = null;
@ -33,9 +34,74 @@ static string GetAssetFilename(string path)
return Path.GetFileNameWithoutExtension(path) + ".uasset"; return Path.GetFileNameWithoutExtension(path) + ".uasset";
} }
const string ExportSettingsFilename = "ExportSettings.json";
const string ImportSettingsFilename = "ImportSettings.json";
while (true) while (true)
{ {
Console.WriteLine("[whack Translation Tool]"); Console.WriteLine("[whack Translation Tool]");
// fuck it, hacked in settings!
var exportSettings = new ExportSettings();
if (File.Exists(ExportSettingsFilename))
{
using var settingsStream = File.OpenRead(ExportSettingsFilename);
try
{
var result = JsonSerializer.Deserialize<ExportSettings>(settingsStream);
if (result != null)
exportSettings = result;
}
catch (Exception ex)
{
Console.WriteLine("Unable to read export settings:");
Console.WriteLine(ex);
}
}
else
{
try
{
File.WriteAllText(ExportSettingsFilename, JsonSerializer.Serialize(exportSettings));
}
catch (Exception ex)
{
Console.WriteLine("Unable to write export settings:");
Console.WriteLine(ex);
exportSettings = new();
}
}
var importSettings = new ImportSettings();
if (File.Exists(ImportSettingsFilename))
{
using var settingsStream = File.OpenRead(ImportSettingsFilename);
try
{
var result = JsonSerializer.Deserialize<ImportSettings>(settingsStream);
if (result != null)
importSettings = result;
}
catch (Exception ex)
{
Console.WriteLine("Unable to read import settings:");
Console.WriteLine(ex);
importSettings = new();
}
}
else
{
try
{
File.WriteAllText(ImportSettingsFilename, JsonSerializer.Serialize(importSettings));
}
catch (Exception ex)
{
Console.WriteLine("Unable to write import settings:");
Console.WriteLine(ex);
}
}
while (basePath == null || !Directory.Exists(basePath)) while (basePath == null || !Directory.Exists(basePath))
{ {
if (basePath != null) if (basePath != null)
@ -71,7 +137,7 @@ while (true)
var files = Directory.GetFiles(basePath, "*.uasset"); var files = Directory.GetFiles(basePath, "*.uasset");
foreach (var tableName in files) foreach (var tableName in files)
{ {
var exporter = new TableExporter(Path.Combine(basePath, tableName)); var exporter = new TableExporter(Path.Combine(basePath, tableName), exportSettings);
var targetPath = Path.GetFileName(Path.ChangeExtension(tableName, "toml")); var targetPath = Path.GetFileName(Path.ChangeExtension(tableName, "toml"));
if (File.Exists(targetPath)) if (File.Exists(targetPath))
@ -116,7 +182,7 @@ while (true)
foreach (var tableName in files) foreach (var tableName in files)
{ {
var assetFilename = GetAssetFilename(tableName); var assetFilename = GetAssetFilename(tableName);
var importer = new TableImporter(tableName, Path.Combine(assetFolder, assetFilename)); var importer = new TableImporter(tableName, Path.Combine(assetFolder, assetFilename), importSettings.Language);
var outputPath = Path.Combine(outputFolder, assetFilename); var outputPath = Path.Combine(outputFolder, assetFilename);
Console.WriteLine($"Exporting to {outputPath}"); Console.WriteLine($"Exporting to {outputPath}");
importer.Write(outputPath); importer.Write(outputPath);
@ -134,7 +200,7 @@ while (true)
break; break;
} }
var exporter = new TableExporter(Path.Combine(basePath, tableName)); var exporter = new TableExporter(Path.Combine(basePath, tableName), exportSettings);
var targetPath = Path.ChangeExtension(tableName, "toml"); var targetPath = Path.ChangeExtension(tableName, "toml");
if (File.Exists(targetPath)) if (File.Exists(targetPath))
{ {
@ -155,7 +221,7 @@ while (true)
var assetPath = Console.ReadLine()!.Trim(); var assetPath = Console.ReadLine()!.Trim();
if (assetPath.Length < 1) if (assetPath.Length < 1)
assetPath = Path.Combine(basePath, GetAssetFilename(importPath)); assetPath = Path.Combine(basePath, GetAssetFilename(importPath));
var importer = new TableImporter(importPath, assetPath); var importer = new TableImporter(importPath, assetPath, importSettings.Language);
Console.Write("Enter the output path or folder: "); Console.Write("Enter the output path or folder: ");
var output = Console.ReadLine()!.Trim(); var output = Console.ReadLine()!.Trim();
if (Directory.Exists(output)) if (Directory.Exists(output))

View File

@ -1,8 +1,7 @@
using UAssetAPI.PropertyTypes.Structs; using UAssetAPI.PropertyTypes.Structs;
using UAssetAPI.UnrealTypes; using UAssetAPI.UnrealTypes;
using WTT;
namespace WhackTranslationTool; namespace WTT;
public class Table public class Table
{ {

View File

@ -1,12 +1,9 @@
using Tommy; using Tommy;
using UAssetAPI; using UAssetAPI;
using UAssetAPI.PropertyTypes.Structs; using UAssetAPI.PropertyTypes.Structs;
using UAssetAPI.UnrealTypes; using WTT.Exceptions;
using WhackTranslationTool.Exceptions;
using WTT;
namespace WhackTranslationTool;
namespace WTT;
public class TableExporter public class TableExporter
{ {
@ -38,6 +35,12 @@ public class TableExporter
tomlTable.AddMessage(entry, 0, "JapaneseMessage"); tomlTable.AddMessage(entry, 0, "JapaneseMessage");
if (_settings.ExportEnglishUSAMessage) if (_settings.ExportEnglishUSAMessage)
tomlTable.AddMessage(entry, 1, "EnglishMessageUSA"); tomlTable.AddMessage(entry, 1, "EnglishMessageUSA");
if (_settings.ExportEnglishSGMessage)
tomlTable.AddMessage(entry, 2, "EnglishMessageSG");
if (_settings.ExportTChineseTWMessage)
tomlTable.AddMessage(entry, 3, "TraditionalChineseMessageTW");
if (_settings.ExportTChineseHKMessage)
tomlTable.AddMessage(entry, 4, "TraditionalChineseMessageHK");
if (_settings.ExportSChineseMessage) if (_settings.ExportSChineseMessage)
tomlTable.AddMessage(entry, 5, "SimplifiedChineseMessage"); tomlTable.AddMessage(entry, 5, "SimplifiedChineseMessage");
if (_settings.ExportKoreanMessage) if (_settings.ExportKoreanMessage)
@ -53,6 +56,12 @@ public class TableExporter
tomlTable.AddMessage(entry, 3, "JapaneseMessage"); tomlTable.AddMessage(entry, 3, "JapaneseMessage");
if (_settings.ExportEnglishUSAMessage) if (_settings.ExportEnglishUSAMessage)
tomlTable.AddMessage(entry, 4, "EnglishMessageUSA"); tomlTable.AddMessage(entry, 4, "EnglishMessageUSA");
if (_settings.ExportEnglishSGMessage)
tomlTable.AddMessage(entry, 5, "EnglishMessageSG");
if (_settings.ExportTChineseTWMessage)
tomlTable.AddMessage(entry, 6, "TraditionalChineseMessageTW");
if (_settings.ExportTChineseHKMessage)
tomlTable.AddMessage(entry, 7, "TraditionalChineseMessageHK");
if (_settings.ExportSChineseMessage) if (_settings.ExportSChineseMessage)
tomlTable.AddMessage(entry, 8, "SimplifiedChineseMessage"); tomlTable.AddMessage(entry, 8, "SimplifiedChineseMessage");
if (_settings.ExportKoreanMessage) if (_settings.ExportKoreanMessage)

View File

@ -1,13 +1,9 @@
using System.Text;
using Tommy; using Tommy;
using UAssetAPI; using UAssetAPI;
using UAssetAPI.Kismet.Bytecode.Expressions;
using UAssetAPI.PropertyTypes.Structs;
using UAssetAPI.UnrealTypes; using UAssetAPI.UnrealTypes;
using WhackTranslationTool.Exceptions; using WTT.Exceptions;
using WTT;
namespace WhackTranslationTool; namespace WTT;
public class TableImporter public class TableImporter
{ {
@ -21,7 +17,7 @@ public class TableImporter
/// <param name="tomlPath">Path to the toml source import file</param> /// <param name="tomlPath">Path to the toml source import file</param>
/// <param name="assetPath">Path to the target uasset file</param> /// <param name="assetPath">Path to the target uasset file</param>
/// <exception cref="UnsupportedAssetException">When UAssetAPI fails to reconstruct the asset file</exception> /// <exception cref="UnsupportedAssetException">When UAssetAPI fails to reconstruct the asset file</exception>
public TableImporter(string tomlPath, string assetPath, Language language = Language.EnglishUSA) public TableImporter(string tomlPath, string assetPath, Language language)
{ {
this.language = language; this.language = language;

View File

@ -1,6 +1,6 @@
using System; using System;
namespace WhackTranslationTool namespace WTT
{ {
internal class YesNoPrompt internal class YesNoPrompt
{ {