feat: names

This commit is contained in:
tresabhi committed 2025-03-01 23:08:22 -06:00
1 parent 6f11fb4a70
commit 0864825513
5 files changed
+429 -19

No files matched your search

+27 -6
View File
@@ -1,14 +1,17 @@
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Text.Unicode;
using Blitzkit;
using BlitzKit.CLI.Models;
using BlitzKit.CLI.Utils;
using CUE4Parse.UE4.Assets.Exports;
using CUE4Parse.UE4.Assets.Exports.Engine;
using CUE4Parse.UE4.Assets.Exports.StaticMesh;
using CUE4Parse.UE4.Assets.Objects;
using CUE4Parse.UE4.Objects.UObject;
using CUE4Parse.UE4.Pak.Objects;
using Google.Protobuf;
using Google.Protobuf.Collections;
using Newtonsoft.Json.Linq;
@@ -16,7 +19,6 @@ namespace BlitzKit.CLI.Functions
{
public class Mangler(string[] args)
{
readonly Tanks tanks = new();
readonly BlitzProvider provider = new(args.Contains("--depot"));
readonly List<FileChange> changes = [];
@@ -37,6 +39,8 @@ namespace BlitzKit.CLI.Functions
void MangleNation(VFS nation)
{
Tanks tanks = new();
foreach (var tankDir in nation.Directories)
{
// if (tankDir.Value.Name != "R90_IS_4")
@@ -44,14 +48,28 @@ namespace BlitzKit.CLI.Functions
var tank = MangleTank(tankDir.Value);
if (tank == null)
continue;
if (!tank.Name.Locales.TryGetValue("en", out var nameEn))
{
throw new Exception($"Failed to get name for {tankDir.Value.Name}");
}
tanks.Tanks_.Add(tank.Id);
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 };
tanks.Tanks_.Add(tankMeta);
}
FileChange change = new("definitions/tanks.pb", tanks.ToByteArray());
changes.Add(change);
}
Tank? MangleTank(VFS tankDir)
Tank MangleTank(VFS tankDir)
{
var pdaName = $"PDA_{tankDir.Name}";
var pda = provider.LoadObject($"{tankDir.Path}/{pdaName}.{pdaName}");
@@ -68,7 +86,10 @@ namespace BlitzKit.CLI.Functions
changes.Add(new($"tanks/{tankId}/collision/hull.glb", hullCollisionGltf.Write()));
return new() { Id = tankId };
I18n Name = new();
Name.Locales.Add("en", tankId);
return new() { Id = tankId, Name = Name };
}
Dictionary<string, CrewType> CrewTypes = new()
+271 -6
View File
@@ -25,11 +25,13 @@ namespace Blitzkit {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"CiRwYWNrYWdlcy9jb3JlL3NyYy9wcm90b3MvdGFua3MucHJvdG8SCGJsaXR6",
"a2l0IhYKBVRhbmtzEg0KBXRhbmtzGAEgAygJ"));
"a2l0IioKBVRhbmtzEiEKBXRhbmtzGAEgAygLMhIuYmxpdHpraXQuVGFua01l",
"dGEiJgoIVGFua01ldGESCgoCaWQYASACKAkSDgoGc2VvX2lkGAIgAigJ"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Blitzkit.Tanks), global::Blitzkit.Tanks.Parser, new[]{ "Tanks_" }, null, null, null, null)
new pbr::GeneratedClrTypeInfo(typeof(global::Blitzkit.Tanks), global::Blitzkit.Tanks.Parser, new[]{ "Tanks_" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Blitzkit.TankMeta), global::Blitzkit.TankMeta.Parser, new[]{ "Id", "SeoId" }, null, null, null, null)
}));
}
#endregion
@@ -83,12 +85,12 @@ namespace Blitzkit {
/// <summary>Field number for the "tanks" field.</summary>
public const int Tanks_FieldNumber = 1;
private static readonly pb::FieldCodec<string> _repeated_tanks_codec
= pb::FieldCodec.ForString(10);
private readonly pbc::RepeatedField<string> tanks_ = new pbc::RepeatedField<string>();
private static readonly pb::FieldCodec<global::Blitzkit.TankMeta> _repeated_tanks_codec
= pb::FieldCodec.ForMessage(10, global::Blitzkit.TankMeta.Parser);
private readonly pbc::RepeatedField<global::Blitzkit.TankMeta> tanks_ = new pbc::RepeatedField<global::Blitzkit.TankMeta>();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public pbc::RepeatedField<string> Tanks_ {
public pbc::RepeatedField<global::Blitzkit.TankMeta> Tanks_ {
get { return tanks_; }
}
@@ -223,6 +225,269 @@ namespace Blitzkit {
}
[global::System.Diagnostics.DebuggerDisplayAttribute("{ToString(),nq}")]
public sealed partial class TankMeta : pb::IMessage<TankMeta>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<TankMeta> _parser = new pb::MessageParser<TankMeta>(() => new TankMeta());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pb::MessageParser<TankMeta> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pbr::MessageDescriptor Descriptor {
get { return global::Blitzkit.TanksReflection.Descriptor.MessageTypes[1]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public TankMeta() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public TankMeta(TankMeta other) : this() {
id_ = other.id_;
seoId_ = other.seoId_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public TankMeta Clone() {
return new TankMeta(this);
}
/// <summary>Field number for the "id" field.</summary>
public const int IdFieldNumber = 1;
private readonly static string IdDefaultValue = "";
private string id_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Id {
get { return id_ ?? IdDefaultValue; }
set {
id_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Gets whether the "id" field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool HasId {
get { return id_ != null; }
}
/// <summary>Clears the value of the "id" field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void ClearId() {
id_ = null;
}
/// <summary>Field number for the "seo_id" field.</summary>
public const int SeoIdFieldNumber = 2;
private readonly static string SeoIdDefaultValue = "";
private string seoId_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string SeoId {
get { return seoId_ ?? SeoIdDefaultValue; }
set {
seoId_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Gets whether the "seo_id" field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool HasSeoId {
get { return seoId_ != null; }
}
/// <summary>Clears the value of the "seo_id" field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void ClearSeoId() {
seoId_ = null;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
return Equals(other as TankMeta);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool Equals(TankMeta other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (Id != other.Id) return false;
if (SeoId != other.SeoId) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override int GetHashCode() {
int hash = 1;
if (HasId) hash ^= Id.GetHashCode();
if (HasSeoId) hash ^= SeoId.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
return hash;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override string ToString() {
return pb::JsonFormatter.ToDiagnosticString(this);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void WriteTo(pb::CodedOutputStream output) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
output.WriteRawMessage(this);
#else
if (HasId) {
output.WriteRawTag(10);
output.WriteString(Id);
}
if (HasSeoId) {
output.WriteRawTag(18);
output.WriteString(SeoId);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (HasId) {
output.WriteRawTag(10);
output.WriteString(Id);
}
if (HasSeoId) {
output.WriteRawTag(18);
output.WriteString(SeoId);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public int CalculateSize() {
int size = 0;
if (HasId) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Id);
}
if (HasSeoId) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(SeoId);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(TankMeta other) {
if (other == null) {
return;
}
if (other.HasId) {
Id = other.Id;
}
if (other.HasSeoId) {
SeoId = other.SeoId;
}
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(pb::CodedInputStream input) {
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
input.ReadRawMessage(this);
#else
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
break;
case 10: {
Id = input.ReadString();
break;
}
case 18: {
SeoId = input.ReadString();
break;
}
}
}
#endif
}
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
uint tag;
while ((tag = input.ReadTag()) != 0) {
if ((tag & 7) == 4) {
// Abort on any end group tag.
return;
}
switch(tag) {
default:
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
break;
case 10: {
Id = input.ReadString();
break;
}
case 18: {
SeoId = input.ReadString();
break;
}
}
}
}
#endif
}
#endregion
}
+26
View File
@@ -0,0 +1,26 @@
using System.Globalization;
using System.Text;
namespace BlitzKit.CLI.Utils
{
public static class Diacritics
{
public static string Remove(string text)
{
var normalizedString = text.Normalize(NormalizationForm.FormD);
var stringBuilder = new StringBuilder(capacity: normalizedString.Length);
for (int i = 0; i < normalizedString.Length; i++)
{
char c = normalizedString[i];
var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
if (unicodeCategory != UnicodeCategory.NonSpacingMark)
{
stringBuilder.Append(c);
}
}
return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
}
}
}