Make item icons transparent
This commit is contained in:
@@ -877,7 +877,9 @@ function Check-Item-Effects() {
|
||||
$item = $itemProp.Value
|
||||
$kind = [string](Get-Prop $item "kind" "")
|
||||
if (Has-Prop $item "icon") {
|
||||
Check-Portrait-Path (Get-Prop $item "icon" "") "Item $itemId icon"
|
||||
$iconPath = [string](Get-Prop $item "icon" "")
|
||||
Check-Portrait-Path $iconPath "Item $itemId icon"
|
||||
Check-Item-Icon-Cutout $iconPath "Item $itemId icon"
|
||||
}
|
||||
if (-not $validItemKinds.Contains($kind)) {
|
||||
Fail "Item $itemId has unknown kind: $kind"
|
||||
@@ -1874,6 +1876,51 @@ function Check-Portrait-Image([string]$AbsolutePath, [string]$Portrait, [string]
|
||||
}
|
||||
}
|
||||
|
||||
function Check-Item-Icon-Cutout([string]$Icon, [string]$Context) {
|
||||
$relativePath = $Icon.Substring("res://".Length)
|
||||
$absolutePath = [System.IO.Path]::GetFullPath((Join-Path ([System.IO.Path]::GetFullPath($Root)) $relativePath))
|
||||
$bitmap = $null
|
||||
try {
|
||||
$bitmap = [System.Drawing.Bitmap]::FromFile($absolutePath)
|
||||
if (-not [System.Drawing.Image]::IsAlphaPixelFormat($bitmap.PixelFormat)) {
|
||||
Fail "$Context must be an alpha PNG cutout: $Icon"
|
||||
}
|
||||
$cornerPixels = @(
|
||||
$bitmap.GetPixel(0, 0),
|
||||
$bitmap.GetPixel($bitmap.Width - 1, 0),
|
||||
$bitmap.GetPixel(0, $bitmap.Height - 1),
|
||||
$bitmap.GetPixel($bitmap.Width - 1, $bitmap.Height - 1)
|
||||
)
|
||||
foreach ($pixel in $cornerPixels) {
|
||||
if ($pixel.A -gt 3) {
|
||||
Fail "$Context must have transparent corners: $Icon"
|
||||
}
|
||||
}
|
||||
$transparentSamples = 0
|
||||
$totalSamples = 0
|
||||
for ($y = 0; $y -lt $bitmap.Height; $y += 4) {
|
||||
for ($x = 0; $x -lt $bitmap.Width; $x += 4) {
|
||||
$totalSamples += 1
|
||||
if ($bitmap.GetPixel($x, $y).A -le 3) {
|
||||
$transparentSamples += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($transparentSamples -lt [int]($totalSamples * 0.20)) {
|
||||
Fail "$Context must have substantial transparent background: $Icon ($transparentSamples/$totalSamples sampled pixels)"
|
||||
}
|
||||
} catch {
|
||||
if ($_.Exception.Message -like "$Context*") {
|
||||
throw
|
||||
}
|
||||
Fail "$Context could not inspect alpha cutout data: $Icon"
|
||||
} finally {
|
||||
if ($null -ne $bitmap) {
|
||||
$bitmap.Dispose()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Check-Post-Battle-Dialogue($Dialogue, [string]$ScenarioId) {
|
||||
if ($null -eq $Dialogue) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user