Files
blitzkit/packages/game/JSExport/GameInterface.cs
T

117 lines
3.1 KiB
C#
Raw Normal View History

2026-05-22 13:51:30 -05:00
using System.Text.RegularExpressions;
2026-04-26 18:02:45 -05:00
using BlitzKit.Game.Models;
2026-02-02 19:04:54 -06:00
using CUE4Parse_Conversion.Textures;
2026-05-23 13:18:09 -05:00
using CUE4Parse.Compression;
2026-05-22 19:42:32 -05:00
using CUE4Parse.UE4.Assets.Exports;
2026-02-02 19:04:54 -06:00
using CUE4Parse.UE4.Assets.Exports.Texture;
2026-05-22 19:42:32 -05:00
using CUE4Parse.UE4.Assets.Objects.Properties;
using CUE4Parse.UE4.IO.Objects;
2026-02-02 19:04:54 -06:00
using CUE4Parse.UE4.Objects.Engine;
using CUE4Parse.UE4.Objects.UObject;
2026-05-22 13:51:30 -05:00
using Microsoft.CodeAnalysis.CSharp.Syntax;
2026-01-27 08:59:34 -06:00
using Microsoft.JavaScript.NodeApi;
2026-04-18 00:30:21 -05:00
using SkiaSharp;
2026-05-27 20:54:48 -05:00
using CUE4Parse.UE4.AssetRegistry.Objects;
using CUE4Parse.UE4.Readers;
using CUE4Parse.UE4.AssetRegistry.Readers;
using CUE4Parse.UE4.AssetRegistry;
2026-01-27 08:59:34 -06:00
2026-02-02 17:28:24 -06:00
namespace BlitzKit.Game.JSExport;
2026-01-27 08:59:34 -06:00
[JSExport]
2026-04-26 18:02:45 -05:00
public partial class GameInterface
2026-01-27 08:59:34 -06:00
{
2026-02-02 17:08:37 -06:00
private readonly BlitzFileProvider provider;
2026-01-27 08:59:34 -06:00
2026-05-22 13:51:30 -05:00
public HashSet<string> files;
2026-01-27 08:59:34 -06:00
2026-05-24 12:42:08 -05:00
public GameInterface(string directory, string map, string temp)
2026-02-01 19:34:36 -06:00
{
2026-05-27 20:54:48 -05:00
provider = new(directory, map, temp);
2026-02-01 19:34:36 -06:00
files = [.. provider.Files.Keys];
}
2026-05-22 13:51:30 -05:00
public HashSet<string> Files => files;
2026-02-01 19:34:36 -06:00
2026-06-04 20:17:31 -05:00
public byte[] TankBigIcon(string tag)
2026-02-01 19:34:36 -06:00
{
2026-06-04 20:17:31 -05:00
var pda = provider.Discovered<UPrimaryDataAsset>(tag);
var icon = pda.Get<FSoftObjectPath>("BigIcon");
return provider.Image(icon);
2026-04-26 18:02:45 -05:00
}
[GeneratedRegex(@"T_UI_Flag_(\w+)_S")]
private static partial Regex FlagNameRegex();
2026-05-23 14:30:52 -05:00
public byte[] Flag(string nation)
2026-05-23 14:25:32 -05:00
{
2026-05-23 14:30:52 -05:00
var flagsBase = "Blitz/Content/UI/Textures/Flag/TankCard/";
foreach (var path in provider.Files.Keys)
2026-04-26 18:02:45 -05:00
{
2026-05-23 14:30:52 -05:00
if (!path.StartsWith(flagsBase))
2026-02-01 21:05:38 -06:00
{
continue;
}
2026-04-26 18:02:45 -05:00
var fileName = Path.GetFileNameWithoutExtension(path);
var match = FlagNameRegex().Match(fileName);
if (
match.Success
&& match.Groups[1].Value.Equals(nation, StringComparison.CurrentCultureIgnoreCase)
)
{
if (provider.TryLoadPackageObject<UTexture2D>($"{path}.{fileName}", out var uTexture))
{
2026-05-23 14:30:52 -05:00
CTexture? cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile);
if (cTexture is null)
{
Console.WriteLine($"No flag found for {nation}");
return [];
}
SKBitmap bitmap = cTexture.ToSkBitmap();
SKData data = bitmap.Encode(SKEncodedImageFormat.Webp, 80);
return data.ToArray();
2026-04-26 18:02:45 -05:00
}
2026-05-22 19:42:32 -05:00
Console.WriteLine($"No flag found for {nation}");
2026-05-23 14:30:52 -05:00
return [];
2026-04-26 18:02:45 -05:00
}
2026-02-01 21:05:38 -06:00
}
2026-05-22 19:42:32 -05:00
Console.WriteLine($"No flag found for {nation}");
2026-05-23 14:30:52 -05:00
return [];
2026-02-01 19:34:36 -06:00
}
2026-05-22 13:51:30 -05:00
2026-05-27 20:54:48 -05:00
public byte[] ConsumableIcon(string tag)
{
var pda = provider.Discovered<UPrimaryDataAsset>(tag);
var icon = pda.Get<FSoftObjectPath>("Icon");
return provider.Image(icon);
}
2026-05-28 12:34:14 -05:00
public byte[] EquipmentIcon(string tag)
2026-05-22 13:51:30 -05:00
{
2026-05-28 12:34:14 -05:00
var pda = provider.Discovered<UPrimaryDataAsset>(tag);
2026-05-24 12:42:08 -05:00
var icon = pda.Get<FSoftObjectPath>("Icon");
return provider.Image(icon);
2026-05-22 13:51:30 -05:00
}
2026-06-05 11:05:19 -05:00
private readonly string[] tankPartEntries = ["DT_Chassis", "DT_Hulls", "DT_Turrets", "DT_Guns"];
public byte[] TankPart(string tag, string part)
{
var pda = provider.Discovered<UPrimaryDataAsset>(tag);
foreach (var entry in tankPartEntries) {
pda.Get<FSoftObjectPath>(entry);
// var icon = pda.Get<FSoftObjectPath>("Icon");
}
return [];
}
2026-01-27 08:59:34 -06:00
}