417cf30a9c
Das Lebensmoos bekommt links und rechts Platz für seinen Umriss, der bei zwei von drei Formen abgeschnitten war; die Bilder der Vitrine sind neu aufgenommen. Die Pausenanzeige kehrt zurück, wenn eine Meldung während der Pause abläuft. Ein Test prüft die Splitter fremder Schläge, und der Test ohne Bilderordner hängt nicht mehr davon ab, was in res://art liegt. Der Fragebogen nennt die Felsproben und sagt, was sofort kommt und was erst mit der Antwort des Hosts. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
111 lines
4.0 KiB
GDScript
111 lines
4.0 KiB
GDScript
extends TestCase
|
|
|
|
## Draws every graphic of `art` twice, with `state` and with nothing, while
|
|
## it draws.
|
|
class Probe extends Node2D:
|
|
var art: Art
|
|
var state: Dictionary
|
|
var drawn := 0
|
|
|
|
func _draw() -> void:
|
|
for id in Art.IDS:
|
|
var rect := Rect2(0, 0, 48, 48) if id == Art.RUIN else Rect2(16, 16, 16, 16)
|
|
art.draw(self, id, rect, state)
|
|
art.draw(self, id, rect, {})
|
|
drawn += 1
|
|
|
|
|
|
## Everything a graphic can be asked to show, so that each drawing runs
|
|
## through all its parts.
|
|
static func _full_state() -> Dictionary:
|
|
return {
|
|
"solid": TileShape.N | TileShape.W | TileShape.NE, "living": TileShape.E | TileShape.S,
|
|
"variant": 123456, "hits": 2, "age": 0.5, "player": 1, "facing": -1.0, "step": 1.0,
|
|
"moving": true, "reachable": true, "time": 2.5, "growth": 0.9, "hop": 0.5, "awake": 0.7,
|
|
"points": PackedVector2Array([Vector2(0, 8), Vector2(10, 4), Vector2(24, 9)]),
|
|
}
|
|
|
|
|
|
## Lets `art` draw every graphic once and returns how many were drawn.
|
|
func _draw_everything(art: Art) -> int:
|
|
var probe := Probe.new()
|
|
probe.art = art
|
|
probe.state = _full_state()
|
|
tree.root.add_child(probe)
|
|
await tree.process_frame
|
|
await tree.process_frame
|
|
var drawn := probe.drawn
|
|
tree.root.remove_child(probe)
|
|
probe.free()
|
|
return drawn
|
|
|
|
|
|
func test_every_style_draws_every_graphic() -> void:
|
|
var art := Art.new()
|
|
for style in art.styles:
|
|
art.select(style.key())
|
|
check_eq(await _draw_everything(art), Art.IDS.size(), "%s draws them all" % style.key())
|
|
art.style = ArtStyle.new()
|
|
check_eq(await _draw_everything(art), Art.IDS.size(), "the placeholders too")
|
|
|
|
|
|
func test_the_styles_are_offered_in_a_fixed_order() -> void:
|
|
var art := Art.new()
|
|
var keys: Array[StringName] = []
|
|
for style in art.styles:
|
|
keys.append(style.key())
|
|
check_eq(keys, Art.style_keys(), "the keys in the order of the styles")
|
|
check_eq(keys, [WarmStyle.KEY, PastelStyle.KEY, GlowStyle.KEY], "warm, pastel, glow")
|
|
check_eq(art.style, art.styles[0], "the first one is chosen at first")
|
|
|
|
|
|
func test_a_style_is_chosen_by_its_key() -> void:
|
|
var art := Art.new()
|
|
var changes := [0]
|
|
art.changed.connect(func() -> void: changes[0] += 1)
|
|
check(art.select(PastelStyle.KEY), "the pastel style exists")
|
|
check_eq(art.style.key(), PastelStyle.KEY, "and is chosen")
|
|
check(art.select(PastelStyle.KEY), "choosing it again works")
|
|
check_eq(changes[0], 1, "only a real change is announced")
|
|
check(not art.select(&"watercolour"), "an unknown key is refused")
|
|
check_eq(art.style.key(), PastelStyle.KEY, "and changes nothing")
|
|
|
|
|
|
func test_the_next_style_follows_and_the_first_comes_after_the_last() -> void:
|
|
var art := Art.new()
|
|
var seen: Array[StringName] = []
|
|
for i in art.styles.size() + 1:
|
|
seen.append(art.style.key())
|
|
art.select_next()
|
|
check_eq(seen, [WarmStyle.KEY, PastelStyle.KEY, GlowStyle.KEY, WarmStyle.KEY], "round and round")
|
|
|
|
|
|
func test_every_style_has_a_name_in_every_language() -> void:
|
|
for translation in I18n.load_translations(I18n.TEXTS_FILE):
|
|
for style in Art.new().styles:
|
|
var title := String(translation.get_message(style.title_key()))
|
|
check(not title.is_empty(), "%s in %s" % [style.title_key(), translation.locale])
|
|
|
|
|
|
func test_a_picture_named_after_an_id_replaces_its_drawing() -> void:
|
|
var directory := TestFiles.temporary_dir("art")
|
|
DirAccess.make_dir_recursive_absolute(directory.path_join("terrain"))
|
|
var image := Image.create(16, 16, false, Image.FORMAT_RGBA8)
|
|
image.fill(Color.RED)
|
|
image.save_png(directory.path_join("terrain/ground.png"))
|
|
var art := Art.new()
|
|
art.load_overrides(directory)
|
|
check(art.has_override(Art.GROUND), "the ground has a picture")
|
|
check(not art.has_override(Art.SOFT_ROCK), "soft rock has none")
|
|
check_eq(await _draw_everything(art), Art.IDS.size(), "the picture is drawn like the rest")
|
|
art.load_overrides(directory.path_join("missing"))
|
|
check(not art.has_override(Art.GROUND), "loading again drops the picture")
|
|
TestFiles.remove_dir(directory)
|
|
|
|
|
|
func test_without_the_folder_of_pictures_everything_is_drawn() -> void:
|
|
var art := Art.new()
|
|
art.load_overrides("res://tests/no-pictures-here")
|
|
for id in Art.IDS:
|
|
check(not art.has_override(id), "no picture for %s" % id)
|