mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
feat: human ids
This commit is contained in:
1 parent
1b017aad48
commit
553c9d552b
16 files changed
+381
-177
No files matched your search
@@ -1,9 +1,12 @@
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Text.Unicode;
|
||||
using System.Threading.Tasks;
|
||||
using Blitzkit;
|
||||
using BlitzKit.CLI.Models;
|
||||
using BlitzKit.CLI.Quicktype.Locales;
|
||||
using BlitzKit.CLI.Utils;
|
||||
using CUE4Parse.UE4.Assets.Exports;
|
||||
using CUE4Parse.UE4.Assets.Exports.Engine;
|
||||
@@ -14,27 +17,86 @@ using CUE4Parse.UE4.Pak.Objects;
|
||||
using Google.Protobuf;
|
||||
using Google.Protobuf.Collections;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace BlitzKit.CLI.Functions
|
||||
{
|
||||
public class Mangler(string[] args)
|
||||
{
|
||||
readonly BlitzProvider provider = new(args.Contains("--depot"));
|
||||
Locales? locales;
|
||||
readonly List<FileChange> changes = [];
|
||||
readonly Dictionary<string, Dictionary<string, string>> strings = [];
|
||||
|
||||
public async Task Mangle()
|
||||
{
|
||||
var nationDirs = provider.RootDirectory.GetDirectory("Blitz/Content/Tanks").Directories;
|
||||
await FetchStrings();
|
||||
MangleNations();
|
||||
// await BlitzKitAssets.CommitAssets("ue assets", changes);
|
||||
}
|
||||
|
||||
foreach (var nationDir in nationDirs)
|
||||
I18n GetString(string name)
|
||||
{
|
||||
I18n i18n = new();
|
||||
|
||||
if (strings[locales!.Default].TryGetValue(name, out var defaultString))
|
||||
{
|
||||
if (nationDir.Key == "TankStub")
|
||||
continue;
|
||||
|
||||
MangleNation(nationDir.Value);
|
||||
foreach (var locale in locales!.Supported)
|
||||
{
|
||||
if (strings[locale.Locale].TryGetValue(name, out var localeString))
|
||||
{
|
||||
if (locale.Locale == locales.Default || localeString != defaultString)
|
||||
{
|
||||
i18n.Locales[locale.Locale] = localeString;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PrettyLog.Warn($"String missing from {locale.Locale} locale: {name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PrettyLog.Warn($"String missing from default locale: {name}");
|
||||
i18n.Locales[locales!.Default] = name;
|
||||
}
|
||||
|
||||
await BlitzKitAssets.CommitAssets("ue assets", changes);
|
||||
return i18n;
|
||||
}
|
||||
|
||||
async Task FetchStrings()
|
||||
{
|
||||
using var client = new HttpClient();
|
||||
var text = File.ReadAllText("../../packages/i18n/locales.json");
|
||||
this.locales =
|
||||
JsonSerializer.Deserialize<Locales>(text)
|
||||
?? throw new Exception("Failed to deserialize locales");
|
||||
|
||||
foreach (var locale in locales.Supported)
|
||||
{
|
||||
var blitzLocale = locale.Blitz ?? locale.Locale;
|
||||
var url =
|
||||
$"{Unpacker.WG_DLC_DOMAIN}/dlc/{Unpacker.CONTENT_GROUP}/ue_localizations/development/general/{blitzLocale}.yaml";
|
||||
var yaml = await client.GetStringAsync(url);
|
||||
var deserializer = new DeserializerBuilder().Build();
|
||||
var parsedYaml = deserializer.Deserialize<Dictionary<string, string>>(yaml);
|
||||
|
||||
strings[locale.Locale] = parsedYaml;
|
||||
}
|
||||
}
|
||||
|
||||
void MangleNations()
|
||||
{
|
||||
var dirs = provider.RootDirectory.GetDirectory("Blitz/Content/Tanks").Directories;
|
||||
|
||||
foreach (var dir in dirs)
|
||||
{
|
||||
if (dir.Key == "TankStub")
|
||||
continue;
|
||||
|
||||
MangleNation(dir.Value);
|
||||
}
|
||||
}
|
||||
|
||||
void MangleNation(VFS nation)
|
||||
@@ -48,25 +110,12 @@ namespace BlitzKit.CLI.Functions
|
||||
|
||||
var tank = MangleTank(tankDir.Value);
|
||||
|
||||
if (!tank.Name.Locales.TryGetValue("en", out var nameEn))
|
||||
{
|
||||
throw new Exception($"Failed to get name for {tankDir.Value.Name}");
|
||||
}
|
||||
|
||||
var seoId = Diacritics.Remove(nameEn).ToLower();
|
||||
seoId = Regex.Replace(seoId, "[^a-z0-9]", "-");
|
||||
seoId = Regex.Replace(seoId, "--+", "-");
|
||||
seoId = Regex.Replace(seoId, "-$", "");
|
||||
|
||||
Console.WriteLine($"{nameEn} -> {seoId}");
|
||||
|
||||
TankMeta tankMeta = new() { Id = tank.Id, SeoId = seoId };
|
||||
TankMeta tankMeta = new() { Id = tank.Id };
|
||||
|
||||
tanks.Tanks_.Add(tankMeta);
|
||||
}
|
||||
|
||||
FileChange change = new("definitions/tanks.pb", tanks.ToByteArray());
|
||||
changes.Add(change);
|
||||
changes.Add(new("definitions/tanks.pb", tanks.ToByteArray()));
|
||||
}
|
||||
|
||||
Tank MangleTank(VFS tankDir)
|
||||
@@ -74,9 +123,33 @@ namespace BlitzKit.CLI.Functions
|
||||
var pdaName = $"PDA_{tankDir.Name}";
|
||||
var pda = provider.LoadObject($"{tankDir.Path}/{pdaName}.{pdaName}");
|
||||
|
||||
var tankId = PropertyUtil.Get<FName>(pda, "TankId").Text;
|
||||
Console.WriteLine($"Mangling {tankId}...");
|
||||
var id = PropertyUtil.Get<FName>(pda, "TankId").Text;
|
||||
|
||||
var name = GetString($"{id}_SHORT_NAME");
|
||||
|
||||
var seoId = Diacritics.Remove(name.Locales["en"]).ToLower();
|
||||
seoId = Regex.Replace(seoId, "[^a-z0-9]", "-");
|
||||
seoId = Regex.Replace(seoId, "--+", "-");
|
||||
seoId = Regex.Replace(seoId, "-$", "");
|
||||
|
||||
// MangleHull(id, pda);
|
||||
|
||||
Console.WriteLine(seoId);
|
||||
|
||||
Tank tank = new()
|
||||
{
|
||||
Id = id,
|
||||
Name = name,
|
||||
SeoId = seoId,
|
||||
};
|
||||
|
||||
changes.Add(new($"definitions/tanks/{id}.pb", tank.ToByteArray()));
|
||||
|
||||
return tank;
|
||||
}
|
||||
|
||||
void MangleHull(string tankId, UObject pda)
|
||||
{
|
||||
var hulls = PropertyUtil.Get<UDataTable>(pda, "DT_Hulls");
|
||||
UDataTableUtility.TryGetDataTableRow(hulls, "hull", StringComparison.Ordinal, out var hull);
|
||||
var hullVisualData = PropertyUtil.Get<UObject>(hull, "VisualData");
|
||||
@@ -85,65 +158,6 @@ namespace BlitzKit.CLI.Functions
|
||||
MonoGltf hullCollisionGltf = new(hullCollision);
|
||||
|
||||
changes.Add(new($"tanks/{tankId}/collision/hull.glb", hullCollisionGltf.Write()));
|
||||
|
||||
I18n Name = new();
|
||||
Name.Locales.Add("en", tankId);
|
||||
|
||||
return new() { Id = tankId, Name = Name };
|
||||
}
|
||||
|
||||
Dictionary<string, CrewType> CrewTypes = new()
|
||||
{
|
||||
{ "EModuleOrTankmen::Commander", CrewType.Commander },
|
||||
{ "EModuleOrTankmen::Driver", CrewType.Driver },
|
||||
{ "EModuleOrTankmen::Gunner1", CrewType.Gunner1 },
|
||||
{ "EModuleOrTankmen::Gunner2", CrewType.Gunner2 },
|
||||
{ "EModuleOrTankmen::Loader1", CrewType.Loader1 },
|
||||
{ "EModuleOrTankmen::Loader2", CrewType.Loader2 },
|
||||
};
|
||||
|
||||
void MangleCrewHealth(RepeatedField<CrewHealth> map, JArray array)
|
||||
{
|
||||
foreach (var member in array.Cast<JObject>())
|
||||
{
|
||||
var key = member["Key"]!.Value<string>()!;
|
||||
|
||||
if (CrewTypes.TryGetValue(key, out var crewType))
|
||||
{
|
||||
CrewHealth crewHealth = new()
|
||||
{
|
||||
Type = crewType,
|
||||
MaxHealth = member["Value"]!["MaxHealth"]!.Value<float>(),
|
||||
};
|
||||
map.Add(crewHealth);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Unrecognized CrewType: {key}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ModuleHealth MangleModuleHealth(JObject obj)
|
||||
{
|
||||
ModuleHealth moduleHealth = new()
|
||||
{
|
||||
MaxHealth = obj["MaxHealth"]!.Value<float>(),
|
||||
MaxRegenHealth = obj["MaxRegenHealth"]!.Value<float>(),
|
||||
HealthRegenPerSec = obj["HealthRegenPerSec"]!.Value<float>(),
|
||||
};
|
||||
|
||||
if (obj.TryGetValue("HysteresisHealth", out var hysteresis))
|
||||
{
|
||||
moduleHealth.HysteresisHealth = hysteresis.Value<float>();
|
||||
}
|
||||
|
||||
if (obj.TryGetValue("HealthBurnPerSec", out var burn))
|
||||
{
|
||||
moduleHealth.HealthBurnPerSec = burn.Value<float>();
|
||||
}
|
||||
|
||||
return moduleHealth;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user