first commit

This commit is contained in:
2026-09-19 17:24:02 +08:00
commit afb343aa49
109 changed files with 13011 additions and 0 deletions
+269
View File
@@ -0,0 +1,269 @@
param(
[string]$WorkspaceRoot = (Split-Path -Parent $PSScriptRoot),
[ValidateSet('p0', 'p1')]
[string]$Set = 'p0',
[ValidateSet('v1', 'v2')]
[string]$Variant = 'v1'
)
Add-Type -AssemblyName System.Drawing
$helperSource = @'
using System;
using System.Drawing;
using System.Drawing.Imaging;
public static class SpriteCropper
{
private static bool IsBackgroundLike(Color c)
{
int max = Math.Max(c.R, Math.Max(c.G, c.B));
int min = Math.Min(c.R, Math.Min(c.G, c.B));
return c.A > 0 && max > 165 && (max - min) < 42;
}
public static Bitmap Extract(string path, Rectangle crop)
{
using (var source = new Bitmap(path))
{
var clipped = Rectangle.Intersect(crop, new Rectangle(0, 0, source.Width, source.Height));
var image = new Bitmap(clipped.Width, clipped.Height, PixelFormat.Format32bppArgb);
using (var g = Graphics.FromImage(image))
{
g.DrawImage(source, new Rectangle(0, 0, image.Width, image.Height), clipped, GraphicsUnit.Pixel);
}
int width = image.Width;
int height = image.Height;
var visited = new bool[width * height];
var queue = new int[width * height];
int queueHead = 0;
int queueTail = 0;
Action<int, int> seed = (x, y) =>
{
int index = y * width + x;
if (!visited[index] && IsBackgroundLike(image.GetPixel(x, y)))
{
visited[index] = true;
queue[queueTail++] = index;
}
};
for (int x = 0; x < width; x++) { seed(x, 0); seed(x, height - 1); }
for (int y = 0; y < height; y++) { seed(0, y); seed(width - 1, y); }
int[] dx = { 1, -1, 0, 0 };
int[] dy = { 0, 0, 1, -1 };
while (queueHead < queueTail)
{
int index = queue[queueHead++];
int x = index % width;
int y = index / width;
image.SetPixel(x, y, Color.Transparent);
for (int i = 0; i < 4; i++)
{
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || nx >= width || ny < 0 || ny >= height) continue;
int next = ny * width + nx;
if (!visited[next] && IsBackgroundLike(image.GetPixel(nx, ny)))
{
visited[next] = true;
queue[queueTail++] = next;
}
}
}
int minX = width, minY = height, maxX = -1, maxY = -1;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
if (image.GetPixel(x, y).A < 16) continue;
minX = Math.Min(minX, x);
minY = Math.Min(minY, y);
maxX = Math.Max(maxX, x);
maxY = Math.Max(maxY, y);
}
}
if (maxX < minX || maxY < minY) return image;
var bounds = Rectangle.FromLTRB(Math.Max(0, minX - 2), Math.Max(0, minY - 2), Math.Min(width, maxX + 3), Math.Min(height, maxY + 3));
var trimmed = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
using (var g = Graphics.FromImage(trimmed))
{
g.DrawImage(image, new Rectangle(0, 0, trimmed.Width, trimmed.Height), bounds, GraphicsUnit.Pixel);
}
image.Dispose();
return trimmed;
}
}
}
'@
$compilerReferences = @(
[System.Drawing.Bitmap].Assembly.Location,
[System.Drawing.Color].Assembly.Location,
[System.Reflection.Assembly]::Load('System.Private.Windows.GdiPlus').Location,
[System.Reflection.Assembly]::Load('System.Private.Windows.Core').Location,
[System.Reflection.Assembly]::Load('System.Collections').Location,
[System.Reflection.Assembly]::Load('System.Runtime').Location,
[System.Object].Assembly.Location
) | Select-Object -Unique
Add-Type -TypeDefinition $helperSource -ReferencedAssemblies $compilerReferences
$board1 = Join-Path $WorkspaceRoot 'assets\images\2d-game-characters\02-xinyin\source\action-keyposes\xinyin-p0-idle-move-attacks-v1.png'
$board2 = Join-Path $WorkspaceRoot 'assets\images\2d-game-characters\02-xinyin\source\action-keyposes\xinyin-p0-burst-hit-defeat-v1.png'
$corrections = Join-Path $WorkspaceRoot 'assets\images\2d-game-characters\02-xinyin\source\action-keyposes\xinyin-p0-corrections-v2.png'
$p1Board1 = Join-Path $WorkspaceRoot 'assets\images\2d-game-characters\02-xinyin\source\action-keyposes\xinyin-p1-ready-dodge-weakpoint-v1.png'
$p1Board2 = Join-Path $WorkspaceRoot 'assets\images\2d-game-characters\02-xinyin\source\action-keyposes\xinyin-p1-cover-v1.png'
$p1Board1V2 = Join-Path $WorkspaceRoot 'assets\images\2d-game-characters\02-xinyin\source\action-keyposes\xinyin-p1-ready-dodge-weakpoint-v2.png'
$p1BoardLeft = Join-Path $WorkspaceRoot 'assets\images\2d-game-characters\02-xinyin\source\action-keyposes\xinyin-p1-cover-left-v1.png'
if ($Set -eq 'p1') {
$output = Join-Path $WorkspaceRoot "assets\images\2d-game-characters\02-xinyin\previews\xinyin-p1-readability-test-$Variant.png"
}
else {
$output = Join-Path $WorkspaceRoot "assets\images\2d-game-characters\02-xinyin\previews\xinyin-action-readability-test-$Variant.png"
}
if ($Set -eq 'p1' -and $Variant -eq 'v2') {
$poses = @(
@{ Name = 'READY'; Path = $p1Board1V2; Crop = [Drawing.Rectangle]::new(780, 35, 390, 300); ReferenceHeight = 300 },
@{ Name = 'DODGE V2'; Path = $p1Board1V2; Crop = [Drawing.Rectangle]::new(500, 365, 510, 290); ReferenceHeight = 290 },
@{ Name = 'WEAKPOINT'; Path = $p1Board1V2; Crop = [Drawing.Rectangle]::new(770, 685, 480, 315); ReferenceHeight = 305 },
@{ Name = 'COVER IDLE R'; Path = $p1Board2; Crop = [Drawing.Rectangle]::new(1120, 45, 416, 445); ReferenceHeight = 320 },
@{ Name = 'COVER ATTACK R'; Path = $p1Board2; Crop = [Drawing.Rectangle]::new(600, 545, 470, 435); ReferenceHeight = 320 },
@{ Name = 'COVER ATTACK L'; Path = $p1BoardLeft; Crop = [Drawing.Rectangle]::new(500, 535, 530, 450); ReferenceHeight = 320 }
)
}
elseif ($Set -eq 'p1') {
$poses = @(
@{ Name = 'READY'; Path = $p1Board1; Crop = [Drawing.Rectangle]::new(780, 35, 390, 300); ReferenceHeight = 300 },
@{ Name = 'DODGE'; Path = $p1Board1; Crop = [Drawing.Rectangle]::new(500, 365, 510, 290); ReferenceHeight = 290 },
@{ Name = 'WEAKPOINT'; Path = $p1Board1; Crop = [Drawing.Rectangle]::new(770, 685, 480, 315); ReferenceHeight = 305 },
@{ Name = 'COVER IDLE'; Path = $p1Board2; Crop = [Drawing.Rectangle]::new(1120, 45, 416, 445); ReferenceHeight = 320 },
@{ Name = 'COVER ATTACK'; Path = $p1Board2; Crop = [Drawing.Rectangle]::new(600, 545, 470, 435); ReferenceHeight = 320 }
)
}
elseif ($Variant -eq 'v2') {
$poses = @(
@{ Name = 'IDLE'; Path = $board1; Crop = [Drawing.Rectangle]::new(500, 10, 290, 245); ReferenceHeight = 250 },
@{ Name = 'MOVE'; Path = $board1; Crop = [Drawing.Rectangle]::new(120, 270, 310, 225); ReferenceHeight = 250 },
@{ Name = 'ATTACK 1'; Path = $corrections; Crop = [Drawing.Rectangle]::new(560, 10, 450, 235); ReferenceHeight = 245 },
@{ Name = 'ATTACK 2'; Path = $corrections; Crop = [Drawing.Rectangle]::new(560, 270, 450, 225); ReferenceHeight = 245 },
@{ Name = 'BURST'; Path = $board2; Crop = [Drawing.Rectangle]::new(710, 10, 440, 345); ReferenceHeight = 305 },
@{ Name = 'HIT'; Path = $corrections; Crop = [Drawing.Rectangle]::new(330, 520, 440, 210); ReferenceHeight = 235 },
@{ Name = 'DEFEAT'; Path = $corrections; Crop = [Drawing.Rectangle]::new(1110, 770, 426, 240); ReferenceHeight = 250 }
)
}
else {
$poses = @(
@{ Name = 'IDLE'; Path = $board1; Crop = [Drawing.Rectangle]::new(500, 10, 290, 245); ReferenceHeight = 250 },
@{ Name = 'MOVE'; Path = $board1; Crop = [Drawing.Rectangle]::new(120, 270, 310, 225); ReferenceHeight = 250 },
@{ Name = 'ATTACK 1'; Path = $board1; Crop = [Drawing.Rectangle]::new(590, 510, 410, 225); ReferenceHeight = 250 },
@{ Name = 'ATTACK 2'; Path = $board1; Crop = [Drawing.Rectangle]::new(575, 755, 430, 250); ReferenceHeight = 250 },
@{ Name = 'BURST'; Path = $board2; Crop = [Drawing.Rectangle]::new(710, 10, 440, 345); ReferenceHeight = 305 },
@{ Name = 'HIT'; Path = $board2; Crop = [Drawing.Rectangle]::new(350, 380, 430, 270); ReferenceHeight = 285 },
@{ Name = 'DEFEAT'; Path = $board2; Crop = [Drawing.Rectangle]::new(1040, 680, 496, 330); ReferenceHeight = 285 }
)
}
$canvas = [Drawing.Bitmap]::new(2000, 1200, [Drawing.Imaging.PixelFormat]::Format32bppArgb)
$graphics = [Drawing.Graphics]::FromImage($canvas)
$graphics.SmoothingMode = [Drawing.Drawing2D.SmoothingMode]::AntiAlias
$graphics.InterpolationMode = [Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
$graphics.PixelOffsetMode = [Drawing.Drawing2D.PixelOffsetMode]::HighQuality
$graphics.Clear([Drawing.Color]::FromArgb(255, 17, 22, 31))
$headerBrush = [Drawing.SolidBrush]::new([Drawing.Color]::FromArgb(242, 244, 250))
$mutedBrush = [Drawing.SolidBrush]::new([Drawing.Color]::FromArgb(156, 171, 195))
$linePen = [Drawing.Pen]::new([Drawing.Color]::FromArgb(110, 118, 145, 183), 2)
$gridPen = [Drawing.Pen]::new([Drawing.Color]::FromArgb(220, 106, 166, 230), 2)
$gridFill = [Drawing.SolidBrush]::new([Drawing.Color]::FromArgb(34, 75, 128, 185))
$shadowBrush = [Drawing.SolidBrush]::new([Drawing.Color]::FromArgb(80, 0, 0, 0))
$fontTitle = [Drawing.Font]::new('Segoe UI Semibold', 26)
$fontSubtitle = [Drawing.Font]::new('Segoe UI', 14)
$fontLabel = [Drawing.Font]::new('Segoe UI Semibold', 14)
$fontRow = [Drawing.Font]::new('Segoe UI Semibold', 18)
$setLabel = if ($Set -eq 'p1') { 'P1 READABILITY TEST' } else { 'ACTION READABILITY TEST' }
$graphics.DrawString("XIN YIN — $setLabel $($Variant.ToUpper())", $fontTitle, $headerBrush, 52, 28)
$directionLabel = if ($Set -eq 'p1' -and $Variant -eq 'v2') { '4.75H front-right / front-left masters' } else { '4.75H front-right master' }
$graphics.DrawString("$directionLabel | base unit height 176 px | base cell 128 × 64 px", $fontSubtitle, $mutedBrush, 55, 70)
$graphics.DrawLine($linePen, 52, 104, 1948, 104)
$columnCenters = if ($poses.Count -eq 5) {
@(360, 680, 1000, 1320, 1640)
}
elseif ($poses.Count -eq 6) {
@(280, 568, 856, 1144, 1432, 1720)
}
else {
@(245, 495, 745, 995, 1245, 1495, 1745)
}
for ($i = 0; $i -lt $poses.Count; $i++) {
$size = $graphics.MeasureString($poses[$i].Name, $fontLabel)
$graphics.DrawString($poses[$i].Name, $fontLabel, $mutedBrush, $columnCenters[$i] - $size.Width / 2, 122)
}
$rows = @(
@{ Label = '100%'; UnitHeight = 176; CellWidth = 128; CellHeight = 64; CenterY = 400 },
@{ Label = '75%'; UnitHeight = 132; CellWidth = 96; CellHeight = 48; CenterY = 735 },
@{ Label = '50%'; UnitHeight = 88; CellWidth = 64; CellHeight = 32; CenterY = 1040 }
)
$sprites = @()
try {
foreach ($pose in $poses) {
$sprites += [SpriteCropper]::Extract($pose.Path, $pose.Crop)
}
foreach ($row in $rows) {
$graphics.FillRectangle([Drawing.SolidBrush]::new([Drawing.Color]::FromArgb(22, 255, 255, 255)), 34, $row.CenterY - 220, 1932, 285)
$graphics.DrawString($row.Label, $fontRow, $headerBrush, 55, $row.CenterY - 205)
$graphics.DrawString("unit $($row.UnitHeight) px", $fontSubtitle, $mutedBrush, 55, $row.CenterY - 172)
for ($i = 0; $i -lt $poses.Count; $i++) {
$cx = $columnCenters[$i]
$cy = $row.CenterY
$halfW = $row.CellWidth / 2
$halfH = $row.CellHeight / 2
$diamond = [Drawing.PointF[]]@(
[Drawing.PointF]::new($cx, $cy - $halfH),
[Drawing.PointF]::new($cx + $halfW, $cy),
[Drawing.PointF]::new($cx, $cy + $halfH),
[Drawing.PointF]::new($cx - $halfW, $cy)
)
$graphics.FillPolygon($gridFill, $diamond)
$graphics.DrawPolygon($gridPen, $diamond)
$graphics.FillEllipse($shadowBrush, $cx - $halfW * 0.34, $cy - $halfH * 0.05, $halfW * 0.68, [Math]::Max(4, $halfH * 0.22))
$source = $sprites[$i]
$scale = $row.UnitHeight / [double]$poses[$i].ReferenceHeight
$drawW = [int][Math]::Round($source.Width * $scale)
$drawH = [int][Math]::Round($source.Height * $scale)
$drawX = [int][Math]::Round($cx - $drawW / 2)
$drawY = [int][Math]::Round($cy + 6 - $drawH)
$graphics.DrawImage($source, [Drawing.Rectangle]::new($drawX, $drawY, $drawW, $drawH))
}
}
$evaluationText = if ($Set -eq 'p1') {
'Evaluation target: ready-state clarity, dodge afterimage balance, reticle separation, and cover exposure.'
}
else {
'Evaluation target: silhouette, weapon-hand readability, secondary-motion clutter, and single-cell footprint.'
}
$graphics.DrawString($evaluationText, $fontSubtitle, $mutedBrush, 52, 1160)
$canvas.Save($output, [Drawing.Imaging.ImageFormat]::Png)
}
finally {
foreach ($sprite in $sprites) { if ($null -ne $sprite) { $sprite.Dispose() } }
$fontTitle.Dispose(); $fontSubtitle.Dispose(); $fontLabel.Dispose(); $fontRow.Dispose()
$headerBrush.Dispose(); $mutedBrush.Dispose(); $linePen.Dispose(); $gridPen.Dispose(); $gridFill.Dispose(); $shadowBrush.Dispose()
$graphics.Dispose(); $canvas.Dispose()
}
Get-Item -LiteralPath $output