d189a358cd
In zwei der vier Laufbilder hob sich der Körper um ein Pixel, und der dunkle Umriss oben am Kopf fiel aus dem Bild. Laufende Figuren flackerten dadurch am Kopf. Jetzt sinkt der Körper, solange die Beine gespreizt sind, und über dem Kopf bleibt immer eine Zeile frei. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
91 lines
3.9 KiB
GDScript
91 lines
3.9 KiB
GDScript
extends TestCase
|
|
## The pixel art of the ground, the rock and the figures, which every pixel
|
|
## style draws.
|
|
|
|
|
|
## How many pixels of `image` are not transparent.
|
|
static func _opaque(image: Image) -> int:
|
|
var count := 0
|
|
for y in image.get_height():
|
|
for x in image.get_width():
|
|
if image.get_pixel(x, y).a > 0.0:
|
|
count += 1
|
|
return count
|
|
|
|
|
|
func test_the_field_is_drawn_in_sharp_pixels() -> void:
|
|
check_eq(ProjectSettings.get_setting("rendering/textures/canvas_textures/default_texture_filter"), 0, "each pixel a square, not blurred")
|
|
check(ProjectSettings.get_setting("rendering/2d/snap/snap_2d_transforms_to_pixel"), "on whole pixels of the screen")
|
|
|
|
|
|
func test_ground_fills_its_tile_and_lies_in_the_shadow_of_rock() -> void:
|
|
var style := WarmStyle.new()
|
|
var open := style._earth(3, 0).image
|
|
check_eq(open.get_size(), Vector2i(PixelStyle.TILE, PixelStyle.TILE), "a tile")
|
|
check_eq(_opaque(open), PixelStyle.TILE * PixelStyle.TILE, "no gaps")
|
|
var shaded := style._earth(3, TileShape.N).image
|
|
check(shaded.get_pixel(5, 0).get_luminance() < open.get_pixel(5, 0).get_luminance(), "darker below rock")
|
|
check_eq(shaded.get_pixel(5, 8), open.get_pixel(5, 8), "but only along the rock")
|
|
|
|
|
|
func test_a_lone_rock_is_round_and_shows_its_face() -> void:
|
|
var style := WarmStyle.new()
|
|
var lone := style._rock_image("soft", 0, 0).image
|
|
check_eq(lone.get_pixel(0, 0).a, 0.0, "a round corner, the ground shows there")
|
|
check_eq(lone.get_pixel(PixelStyle.TILE - 1, PixelStyle.TILE - 1).a, 0.0, "round at the bottom too")
|
|
check_eq(lone.get_pixel(8, 0), style.palette["outline"], "outlined at the top")
|
|
check_eq(lone.get_pixel(8, PixelStyle.TILE - 1), style.palette["outline"], "and where it meets the ground")
|
|
check_eq(lone.get_pixel(5, PixelStyle.TILE - 3), style.palette["soft_face"], "its face toward the open ground")
|
|
|
|
|
|
func test_rock_inside_a_mass_has_neither_edge_nor_face() -> void:
|
|
var style := WarmStyle.new()
|
|
var inside := style._rock_image("soft", 255, 0).image
|
|
check_eq(_opaque(inside), PixelStyle.TILE * PixelStyle.TILE, "no gaps")
|
|
for y in PixelStyle.TILE:
|
|
for x in PixelStyle.TILE:
|
|
var colour := inside.get_pixel(x, y)
|
|
check(colour != style.palette["outline"] and colour != style.palette["soft_face"], "inside at %d, %d" % [x, y])
|
|
|
|
|
|
func test_only_the_corners_that_matter_tell_tiles_apart() -> void:
|
|
check_eq(PixelStyle._shape(TileShape.NE), 0, "a corner alone does not count")
|
|
check_eq(PixelStyle._shape(TileShape.N | TileShape.E | TileShape.NE), TileShape.N | TileShape.E | TileShape.NE, "between two sides it does")
|
|
check_eq(PixelStyle._shape(255), 255, "all of them inside a mass")
|
|
|
|
|
|
func test_each_picture_is_made_only_once() -> void:
|
|
var style := WarmStyle.new()
|
|
var made := [0]
|
|
var make := func() -> PixelStyle.Pixels:
|
|
made[0] += 1
|
|
return PixelStyle.Pixels.new(1, 1)
|
|
var first := style._image("test/once", make)
|
|
var again := style._image("test/once", make)
|
|
check_eq(again, first, "the same picture")
|
|
check_eq(made[0], 1, "made once")
|
|
|
|
|
|
func test_a_figure_walks_in_four_steps_and_faces_both_ways() -> void:
|
|
var style := WarmStyle.new()
|
|
var frames: Array[PackedByteArray] = []
|
|
for frame in 5:
|
|
var image := style._figure_image(0, frame, false).image
|
|
check_eq(image.get_size(), PixelStyle.FIGURE_SIZE, "a tile wide, one and a half tall")
|
|
check(not frames.has(image.get_data()), "frame %d differs from the others" % frame)
|
|
frames.append(image.get_data())
|
|
var left := style._figure_image(0, 1, true).image
|
|
left.flip_x()
|
|
check_eq(left.get_data(), frames[1], "facing left mirrors facing right")
|
|
var other := style._figure_image(1, 0, false).image
|
|
check(other.get_data() != frames[0], "another player has another colour")
|
|
|
|
|
|
func test_the_head_keeps_its_outline_in_every_step() -> void:
|
|
var style := WarmStyle.new()
|
|
for frame in 5:
|
|
var image := style._figure_image(0, frame, false).image
|
|
for x in image.get_width():
|
|
var top := image.get_pixel(x, 0)
|
|
check(top.a == 0.0 or top == style.palette["outline"], "frame %d, column %d: %s" % [frame, x, top])
|