Add photorealistic officer portraits

This commit is contained in:
2026-06-18 12:43:19 +09:00
parent c3a09d6577
commit 644bab582e
14 changed files with 61 additions and 7 deletions

View File

@@ -106,6 +106,14 @@ $validSkillEffectTypes = @("stat_bonus", "damage_over_time", "action_lock")
$validSkillAreaShapes = @("single", "diamond")
$validDialogueSides = @("left", "right")
$validPortraitPathPattern = '^res://.+\.(png|jpg|jpeg|webp)$'
$minimumPortraitDimension = 512
$portraitImageInspectorReady = $false
try {
Add-Type -AssemblyName System.Drawing -ErrorAction Stop
$portraitImageInspectorReady = $true
} catch {
$portraitImageInspectorReady = $false
}
$validMoveTypes = New-Object System.Collections.Generic.HashSet[string]
$knownFlagIds = New-Object System.Collections.Generic.HashSet[string]
$knownFlagValueKinds = @{}
@@ -1535,6 +1543,42 @@ function Check-Portrait-Path($Portrait, [string]$Context) {
if ([string]$Portrait -notmatch $validPortraitPathPattern) {
Fail "$Context must be a res:// image path."
}
$relativePath = ([string]$Portrait).Substring("res://".Length)
$rootPath = [System.IO.Path]::GetFullPath($Root)
$absolutePath = [System.IO.Path]::GetFullPath((Join-Path $rootPath $relativePath))
$trimChars = @([System.IO.Path]::DirectorySeparatorChar, [System.IO.Path]::AltDirectorySeparatorChar)
$rootPathWithSeparator = $rootPath.TrimEnd($trimChars) + [System.IO.Path]::DirectorySeparatorChar
$insideRoot = $absolutePath.Equals($rootPath, [System.StringComparison]::OrdinalIgnoreCase) -or $absolutePath.StartsWith($rootPathWithSeparator, [System.StringComparison]::OrdinalIgnoreCase)
if (-not $insideRoot) {
Fail "$Context must stay inside the project: $Portrait"
}
if (-not (Test-Path -LiteralPath $absolutePath -PathType Leaf)) {
Fail "$Context references missing file: $Portrait"
}
Check-Portrait-Image $absolutePath ([string]$Portrait) $Context
}
function Check-Portrait-Image([string]$AbsolutePath, [string]$Portrait, [string]$Context) {
if (-not $portraitImageInspectorReady) {
Fail "$Context cannot inspect portrait image metadata: $Portrait"
}
$image = $null
$width = 0
$height = 0
try {
$image = [System.Drawing.Image]::FromFile($AbsolutePath)
$width = [int]$image.Width
$height = [int]$image.Height
} catch {
Fail "$Context references an unreadable image file: $Portrait"
} finally {
if ($null -ne $image) {
$image.Dispose()
}
}
if ($width -lt $minimumPortraitDimension -or $height -lt $minimumPortraitDimension) {
Fail "$Context image is too small: $Portrait ($width x $height, minimum ${minimumPortraitDimension}x${minimumPortraitDimension})"
}
}
function Check-Post-Battle-Dialogue($Dialogue, [string]$ScenarioId) {