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:
parent
74b9a908b4
commit
396996c4ab
@ -1,4 +1,4 @@
|
||||
namespace WhackTranslationTool.Exceptions;
|
||||
namespace WTT.Exceptions;
|
||||
|
||||
public class DuplicateKeyException : Exception
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace WhackTranslationTool.Exceptions;
|
||||
namespace WTT.Exceptions;
|
||||
|
||||
public class MissingKeyException : Exception
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace WhackTranslationTool.Exceptions;
|
||||
namespace WTT.Exceptions;
|
||||
|
||||
public class UnhandledTomlError : Exception
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace WhackTranslationTool.Exceptions;
|
||||
namespace WTT.Exceptions;
|
||||
|
||||
public class UnsupportedAssetException : Exception
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace WhackTranslationTool;
|
||||
namespace WTT;
|
||||
|
||||
public class ExportSettings
|
||||
{
|
||||
|
13
WTT/WTT/ImportSettings.cs
Normal file
13
WTT/WTT/ImportSettings.cs
Normal 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;
|
||||
}
|
||||
}
|
@ -2,10 +2,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WTT
|
||||
{
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public enum Language
|
||||
{
|
||||
Japanese,
|
||||
|
@ -1,4 +1,5 @@
|
||||
using WhackTranslationTool;
|
||||
using System.Text.Json;
|
||||
using WTT;
|
||||
|
||||
string? basePath = null; // @"WindowsNoEditor\Mercury\Content\Message";
|
||||
bool? overwrite = null;
|
||||
@ -33,9 +34,74 @@ static string GetAssetFilename(string path)
|
||||
return Path.GetFileNameWithoutExtension(path) + ".uasset";
|
||||
}
|
||||
|
||||
const string ExportSettingsFilename = "ExportSettings.json";
|
||||
const string ImportSettingsFilename = "ImportSettings.json";
|
||||
|
||||
while (true)
|
||||
{
|
||||
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))
|
||||
{
|
||||
if (basePath != null)
|
||||
@ -71,7 +137,7 @@ while (true)
|
||||
var files = Directory.GetFiles(basePath, "*.uasset");
|
||||
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"));
|
||||
if (File.Exists(targetPath))
|
||||
@ -116,7 +182,7 @@ while (true)
|
||||
foreach (var tableName in files)
|
||||
{
|
||||
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);
|
||||
Console.WriteLine($"Exporting to {outputPath}");
|
||||
importer.Write(outputPath);
|
||||
@ -134,7 +200,7 @@ while (true)
|
||||
break;
|
||||
}
|
||||
|
||||
var exporter = new TableExporter(Path.Combine(basePath, tableName));
|
||||
var exporter = new TableExporter(Path.Combine(basePath, tableName), exportSettings);
|
||||
var targetPath = Path.ChangeExtension(tableName, "toml");
|
||||
if (File.Exists(targetPath))
|
||||
{
|
||||
@ -155,7 +221,7 @@ while (true)
|
||||
var assetPath = Console.ReadLine()!.Trim();
|
||||
if (assetPath.Length < 1)
|
||||
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: ");
|
||||
var output = Console.ReadLine()!.Trim();
|
||||
if (Directory.Exists(output))
|
||||
|
@ -1,8 +1,7 @@
|
||||
using UAssetAPI.PropertyTypes.Structs;
|
||||
using UAssetAPI.UnrealTypes;
|
||||
using WTT;
|
||||
|
||||
namespace WhackTranslationTool;
|
||||
namespace WTT;
|
||||
|
||||
public class Table
|
||||
{
|
||||
|
@ -1,12 +1,9 @@
|
||||
using Tommy;
|
||||
using UAssetAPI;
|
||||
using UAssetAPI.PropertyTypes.Structs;
|
||||
using UAssetAPI.UnrealTypes;
|
||||
using WhackTranslationTool.Exceptions;
|
||||
using WTT;
|
||||
|
||||
namespace WhackTranslationTool;
|
||||
using WTT.Exceptions;
|
||||
|
||||
namespace WTT;
|
||||
|
||||
public class TableExporter
|
||||
{
|
||||
@ -38,6 +35,12 @@ public class TableExporter
|
||||
tomlTable.AddMessage(entry, 0, "JapaneseMessage");
|
||||
if (_settings.ExportEnglishUSAMessage)
|
||||
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)
|
||||
tomlTable.AddMessage(entry, 5, "SimplifiedChineseMessage");
|
||||
if (_settings.ExportKoreanMessage)
|
||||
@ -53,6 +56,12 @@ public class TableExporter
|
||||
tomlTable.AddMessage(entry, 3, "JapaneseMessage");
|
||||
if (_settings.ExportEnglishUSAMessage)
|
||||
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)
|
||||
tomlTable.AddMessage(entry, 8, "SimplifiedChineseMessage");
|
||||
if (_settings.ExportKoreanMessage)
|
||||
|
@ -1,13 +1,9 @@
|
||||
using System.Text;
|
||||
using Tommy;
|
||||
using UAssetAPI;
|
||||
using UAssetAPI.Kismet.Bytecode.Expressions;
|
||||
using UAssetAPI.PropertyTypes.Structs;
|
||||
using UAssetAPI.UnrealTypes;
|
||||
using WhackTranslationTool.Exceptions;
|
||||
using WTT;
|
||||
using WTT.Exceptions;
|
||||
|
||||
namespace WhackTranslationTool;
|
||||
namespace WTT;
|
||||
|
||||
public class TableImporter
|
||||
{
|
||||
@ -21,7 +17,7 @@ public class TableImporter
|
||||
/// <param name="tomlPath">Path to the toml source import file</param>
|
||||
/// <param name="assetPath">Path to the target uasset file</param>
|
||||
/// <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;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace WhackTranslationTool
|
||||
namespace WTT
|
||||
{
|
||||
internal class YesNoPrompt
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user