mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
what
This commit is contained in:
1 parent
8a6841adea
commit
a8ae806f8b
5 files changed
+52
-48
No files matched your search
@@ -10,6 +10,7 @@ using CUE4Parse.UE4.Objects.Engine;
|
||||
using CUE4Parse.UE4.Objects.UObject;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.JavaScript.NodeApi;
|
||||
using SharpGLTF.Schema2;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace BlitzKit.Game.JSExport;
|
||||
@@ -79,13 +80,13 @@ public partial class GameInterface
|
||||
[GeneratedRegex(@"T_UI_Flag_(\w+)_S")]
|
||||
private static partial Regex FlagNameRegex();
|
||||
|
||||
public byte[] Flag(string nation)
|
||||
{
|
||||
var flagsBase = "Blitz/Content/UI/Textures/Flag/TankCard/";
|
||||
private readonly string flagsPrefix = "Blitz/Content/UI/Textures/Flag/TankCard/";
|
||||
|
||||
foreach (var path in provider.Files.Keys)
|
||||
public byte[]? Flag(string nation)
|
||||
{
|
||||
foreach (var path in files)
|
||||
{
|
||||
if (!path.StartsWith(flagsBase))
|
||||
if (!path.StartsWith(flagsPrefix))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -100,34 +101,23 @@ public partial class GameInterface
|
||||
{
|
||||
if (provider.TryLoadPackageObject<UTexture2D>($"{path}.{fileName}", out var uTexture))
|
||||
{
|
||||
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();
|
||||
return Image(uTexture);
|
||||
}
|
||||
|
||||
Console.WriteLine($"No flag found for {nation}");
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"No flag found for {nation}");
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
|
||||
private static readonly string equipmentPDAPrefix =
|
||||
"Blitz/Content/TanksStuff/Equipment/PDA_Equipment";
|
||||
private static readonly string equipmentPDASuffix = ".uasset";
|
||||
|
||||
public byte[] EquipmentIcon(string[] names)
|
||||
public byte[]? EquipmentIcon(string[] names)
|
||||
{
|
||||
List<string> candidates = [];
|
||||
|
||||
@@ -154,38 +144,46 @@ public partial class GameInterface
|
||||
if (candidate is null)
|
||||
{
|
||||
Console.WriteLine($"No equipment pda found for {string.Join(", ", names)}");
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
|
||||
var path = $"{candidate}.{Path.GetFileNameWithoutExtension(candidate)}";
|
||||
var pda = PDA(candidate);
|
||||
var icon = pda.Get<FSoftObjectPath>("Icon");
|
||||
|
||||
if (provider.TryLoadPackageObject<UPrimaryDataAsset>(path, out var pda))
|
||||
return Image(icon);
|
||||
}
|
||||
|
||||
private UPrimaryDataAsset PDA(string path)
|
||||
{
|
||||
var name = Path.GetFileNameWithoutExtension(path);
|
||||
var fullPath = $"{path}.{name}";
|
||||
var pda = provider.LoadPackageObject<UPrimaryDataAsset>(fullPath);
|
||||
|
||||
return pda;
|
||||
}
|
||||
|
||||
private readonly SKEncodedImageFormat imageFormat = SKEncodedImageFormat.Webp;
|
||||
private readonly int imageQuality = 80;
|
||||
|
||||
private byte[]? Image(UTexture2D uTexture)
|
||||
{
|
||||
var cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile);
|
||||
|
||||
if (cTexture is null)
|
||||
{
|
||||
var icon = pda.Get<FSoftObjectPath>("Icon");
|
||||
var uTexture = icon.Load<UTexture2D>();
|
||||
var cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile);
|
||||
|
||||
if (cTexture is null)
|
||||
{
|
||||
Console.WriteLine($"Could not extract icon for {path}");
|
||||
return [];
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var bitmap = cTexture.ToSkBitmap();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
|
||||
// var data = bitmap.Encode(SKEncodedImageFormat.Webp, 80);
|
||||
|
||||
// return data.ToArray();
|
||||
Console.WriteLine($"Could not extract icon for {uTexture}");
|
||||
return null;
|
||||
}
|
||||
|
||||
Console.WriteLine($"Could not load {path} as pda");
|
||||
return [];
|
||||
var bitmap = cTexture.ToSkBitmap();
|
||||
var data = bitmap.Encode(imageFormat, imageQuality);
|
||||
|
||||
return data.ToArray();
|
||||
}
|
||||
|
||||
private byte[]? Image(FSoftObjectPath image)
|
||||
{
|
||||
var uTexture = image.Load<UTexture2D>();
|
||||
return Image(uTexture);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user