Make base unit art transparent
This commit is contained in:
@@ -55,6 +55,19 @@ func _check_battle_visual_data(failures: Array[String]) -> void:
|
||||
_check_unit_sprite_resolution(failures, state, "yellow_turban_1", "res://art/units/enemies/enemy_warrior.png", true)
|
||||
_check_unit_sprite_resolution(failures, state, "yellow_turban_2", "res://art/units/enemies/enemy_infantry.png", true)
|
||||
_check_unit_sprite_resolution(failures, state, "yellow_turban_3", "res://art/units/enemies/enemy_archer.png", true)
|
||||
for path in [
|
||||
"res://art/units/archer.png",
|
||||
"res://art/units/cavalry.png",
|
||||
"res://art/units/infantry.png",
|
||||
"res://art/units/strategist.png",
|
||||
"res://art/units/warrior.png",
|
||||
"res://art/units/enemies/enemy_archer.png",
|
||||
"res://art/units/enemies/enemy_cavalry.png",
|
||||
"res://art/units/enemies/enemy_infantry.png",
|
||||
"res://art/units/enemies/enemy_strategist.png",
|
||||
"res://art/units/enemies/enemy_warrior.png"
|
||||
]:
|
||||
_check_alpha_cutout_path(failures, path, "unit cutout %s" % path)
|
||||
|
||||
var gate_state = BattleStateScript.new()
|
||||
if not gate_state.load_battle("res://data/scenarios/002_sishui_gate.json"):
|
||||
@@ -348,6 +361,39 @@ func _check_unit_sprite_resolution(failures: Array[String], state, unit_id: Stri
|
||||
_check_image_path(failures, sprite, "unit %s resolved sprite" % unit_id)
|
||||
|
||||
|
||||
func _check_alpha_cutout_path(failures: Array[String], path: String, context: String) -> void:
|
||||
if path.is_empty():
|
||||
failures.append("%s has an empty image path" % context)
|
||||
return
|
||||
if not path.begins_with("res://"):
|
||||
failures.append("%s must use a res:// path: %s" % [context, path])
|
||||
return
|
||||
if not FileAccess.file_exists(path):
|
||||
failures.append("%s references missing image: %s" % [context, path])
|
||||
return
|
||||
var image := Image.new()
|
||||
var err := image.load(path)
|
||||
if err != OK:
|
||||
failures.append("%s references unreadable image: %s" % [context, path])
|
||||
return
|
||||
if image.get_width() < 512 or image.get_height() < 512:
|
||||
failures.append("%s image should be at least 512x512: %s (%dx%d)" % [context, path, image.get_width(), image.get_height()])
|
||||
return
|
||||
for corner in [Vector2i(0, 0), Vector2i(image.get_width() - 1, 0), Vector2i(0, image.get_height() - 1), Vector2i(image.get_width() - 1, image.get_height() - 1)]:
|
||||
if image.get_pixelv(corner).a > 0.01:
|
||||
failures.append("%s should have transparent corners: %s" % [context, path])
|
||||
return
|
||||
var transparent_samples := 0
|
||||
var total_samples := 0
|
||||
for y in range(0, image.get_height(), 4):
|
||||
for x in range(0, image.get_width(), 4):
|
||||
total_samples += 1
|
||||
if image.get_pixel(x, y).a <= 0.01:
|
||||
transparent_samples += 1
|
||||
if transparent_samples < int(total_samples * 0.20):
|
||||
failures.append("%s should have substantial transparent background: %s (%d/%d sampled pixels)" % [context, path, transparent_samples, total_samples])
|
||||
|
||||
|
||||
func _check_image_path(failures: Array[String], path: String, context: String) -> void:
|
||||
if path.is_empty():
|
||||
failures.append("%s has an empty image path" % context)
|
||||
|
||||
Reference in New Issue
Block a user