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

71 lines
1.8 KiB
C#
Raw Normal View History

2026-02-02 19:04:54 -06:00
using BlitzKit.Game.Models;
using CUE4Parse_Conversion.Textures;
using CUE4Parse.UE4.Assets.Exports.Texture;
using CUE4Parse.UE4.Objects.Engine;
using CUE4Parse.UE4.Objects.UObject;
2026-01-27 08:59:34 -06:00
using Microsoft.JavaScript.NodeApi;
2026-04-18 00:30:21 -05:00
using SkiaSharp;
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-02-02 17:08:37 -06:00
public 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-02-01 19:34:36 -06:00
public string[] files;
public string[] tanksDirectoryNations;
2026-01-27 08:59:34 -06:00
2026-02-02 17:08:37 -06:00
public GameInterface(string directory)
2026-02-01 19:34:36 -06:00
{
2026-02-02 17:08:37 -06:00
provider = new(directory);
2026-02-01 21:05:38 -06:00
2026-02-01 19:34:36 -06:00
files = [.. provider.Files.Keys];
var tanksBase = "Blitz/Content/Tanks/";
tanksDirectoryNations =
[
.. files
.Where(path => path.StartsWith(tanksBase))
.Select(path => path[tanksBase.Length..])
.Select(path => path.Split('/')[0])
.Where(nation => !nation.EndsWith(".uasset") && nation != "TankStub")
.Distinct(),
];
}
public string[] Files => files;
public string[] TanksDirectoryNations => tanksDirectoryNations;
public byte[] TankBigIcon(string tankId, string pdaName)
{
2026-02-01 21:05:38 -06:00
foreach (var nation in tanksDirectoryNations)
{
var path = $"Blitz/Content/Tanks/{nation}/{tankId}/{pdaName}.{pdaName}";
2026-02-02 19:04:54 -06:00
if (provider.TryLoadPackageObject<UPrimaryDataAsset>(path, out var pda))
2026-02-01 21:05:38 -06:00
{
2026-04-18 00:30:21 -05:00
FSoftObjectPath objectPath = pda.Get<FSoftObjectPath>("BigIcon");
UTexture2D uTexture = objectPath.Load<UTexture2D>();
CTexture? cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile);
if (cTexture is null)
2026-02-02 19:57:15 -06:00
{
2026-04-18 00:30:21 -05:00
continue;
2026-02-02 19:57:15 -06:00
}
2026-04-18 00:30:21 -05:00
SKBitmap bitmap = cTexture.ToSkBitmap();
SKData data = bitmap.Encode(SKEncodedImageFormat.Webp, 80);
byte[] bytes = data.ToArray();
return bytes;
2026-02-01 21:05:38 -06:00
}
else
{
continue;
}
}
2026-04-18 00:30:21 -05:00
return [];
2026-02-01 19:34:36 -06:00
}
2026-01-27 08:59:34 -06:00
}