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

70 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-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-02-02 19:57:15 -06:00
try
{
return pda.Get<FSoftObjectPath>("BigIcon")
.Load<UTexture2D>()
.Decode(ETexturePlatform.DesktopMobile)!
.ToSkBitmap()
.Encode(SkiaSharp.SKEncodedImageFormat.Webp, 80)
.ToArray();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
2026-02-01 21:05:38 -06:00
}
else
{
continue;
}
}
throw new FileNotFoundException($"Tank {tankId}/{pdaName} not found in any nation");
2026-02-01 19:34:36 -06:00
}
2026-01-27 08:59:34 -06:00
}