mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 03:29:51 +01:00
feat: nation flags
This commit is contained in:
1 parent
2e208507c3
commit
bc0004574a
4 files changed
+69
-6
No files matched your search
+1
-1
Submodule packages/closed updated: 660413e955...52a5847368.
@@ -1,4 +1,6 @@
|
|||||||
using BlitzKit.Game.Models;
|
using System.IO;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using BlitzKit.Game.Models;
|
||||||
using CUE4Parse_Conversion.Textures;
|
using CUE4Parse_Conversion.Textures;
|
||||||
using CUE4Parse.UE4.Assets.Exports.Texture;
|
using CUE4Parse.UE4.Assets.Exports.Texture;
|
||||||
using CUE4Parse.UE4.Objects.Engine;
|
using CUE4Parse.UE4.Objects.Engine;
|
||||||
@@ -9,7 +11,7 @@ using SkiaSharp;
|
|||||||
namespace BlitzKit.Game.JSExport;
|
namespace BlitzKit.Game.JSExport;
|
||||||
|
|
||||||
[JSExport]
|
[JSExport]
|
||||||
public class GameInterface
|
public partial class GameInterface
|
||||||
{
|
{
|
||||||
private readonly BlitzFileProvider provider;
|
private readonly BlitzFileProvider provider;
|
||||||
|
|
||||||
@@ -51,7 +53,7 @@ public class GameInterface
|
|||||||
|
|
||||||
if (cTexture is null)
|
if (cTexture is null)
|
||||||
{
|
{
|
||||||
continue;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
SKBitmap bitmap = cTexture.ToSkBitmap();
|
SKBitmap bitmap = cTexture.ToSkBitmap();
|
||||||
@@ -60,10 +62,51 @@ public class GameInterface
|
|||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex(@"T_UI_Flag_(\w+)_S")]
|
||||||
|
private static partial Regex FlagNameRegex();
|
||||||
|
|
||||||
|
public byte[] Flag(string nation)
|
||||||
|
{
|
||||||
|
var flagsBase = "Blitz/Content/UI/Textures/Flag/TankCard/";
|
||||||
|
|
||||||
|
foreach (var path in provider.Files.Keys)
|
||||||
|
{
|
||||||
|
if (!path.StartsWith(flagsBase))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
CTexture? cTexture = uTexture.Decode(ETexturePlatform.DesktopMobile);
|
||||||
|
|
||||||
|
if (cTexture is null)
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
SKBitmap bitmap = cTexture.ToSkBitmap();
|
||||||
|
SKData data = bitmap.Encode(SKEncodedImageFormat.Webp, 80);
|
||||||
|
byte[] bytes = data.ToArray();
|
||||||
|
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export function TankCard({ id }: PopularTank) {
|
|||||||
<div
|
<div
|
||||||
className={styles.flag}
|
className={styles.flag}
|
||||||
style={{
|
style={{
|
||||||
backgroundImage: "url(https://i.imgur.com/QGUfXNo.png)",
|
backgroundImage: `url(/api/nations/${tank.tank!.nation}.webp)`,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { Nation } from "@protos/game/proto/legacy/blitz_static_tank_component";
|
||||||
|
import type { APIContext, GetStaticPaths } from "astro";
|
||||||
|
import { game } from "../../../core/game/game";
|
||||||
|
|
||||||
|
export const getStaticPaths = (async () => {
|
||||||
|
return Object.values(Nation)
|
||||||
|
.filter(Number.isInteger)
|
||||||
|
.map((id) => ({ params: { id } }));
|
||||||
|
}) satisfies GetStaticPaths;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Even Noah can't save these animals.
|
||||||
|
*/
|
||||||
|
export async function GET({ params }: APIContext<never, { id: string }>) {
|
||||||
|
const enumName = Nation[Number(params.id)];
|
||||||
|
const nationName = enumName.replace("NATION_", "").toLowerCase();
|
||||||
|
const flag = game.flag(nationName);
|
||||||
|
|
||||||
|
return new Response(new Uint8Array(flag));
|
||||||
|
}
|
||||||
Reference in new issue
Block a user