d2a7973022
Karte, Figuren und Zielmarke zeichnet jetzt Art. Die Karte zeichnet in Blöcken von 16 mal 16 Kacheln und nach einem Treffer nur die Blöcke um die Kachel neu; jede Kachel kennt ihre Nachbarn. Figuren stehen aufrecht in ihrer Kachel, schreiten und schauen in die Richtung, in die sie gehen. Der eigene Schlag zeigt seine Splitter sofort, auch als Gast, und die Namen über fremden Figuren werden in Bildschirmgröße gezeichnet und bleiben scharf. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
95 lines
2.8 KiB
GDScript
95 lines
2.8 KiB
GDScript
extends TestCase
|
|
## The map view over a real world of the core.
|
|
|
|
var key := PackedByteArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
|
|
|
|
|
|
func _session() -> GwSession:
|
|
var session := GwSession.new()
|
|
session.start_new(7)
|
|
session.join(key, "Ada")
|
|
session.step()
|
|
return session
|
|
|
|
|
|
func _view(session: GwSession) -> MapView:
|
|
var view := MapView.new()
|
|
view.art = Art.new()
|
|
view.session = session
|
|
tree.root.add_child(view)
|
|
view.reload()
|
|
return view
|
|
|
|
|
|
func _free(view: MapView) -> void:
|
|
tree.root.remove_child(view)
|
|
view.free()
|
|
|
|
|
|
## The first tile of the soft rock beside the spawn clearing.
|
|
func _rock(session: GwSession) -> Vector2i:
|
|
return session.spawn_point() + Vector2i(7, -2)
|
|
|
|
|
|
func test_the_map_is_drawn_in_blocks_that_cover_it() -> void:
|
|
var session := _session()
|
|
var view := _view(session)
|
|
var across := ceili(session.map_width() / float(MapView.BLOCK))
|
|
var down := ceili(session.map_height() / float(MapView.BLOCK))
|
|
check_eq(view.block_count(), across * down, "blocks over the whole map")
|
|
for style in Art.style_keys():
|
|
view.art.select(style)
|
|
view.redraw()
|
|
await tree.process_frame
|
|
_free(view)
|
|
|
|
|
|
func test_each_tile_is_drawn_to_fit_the_rock_around_it() -> void:
|
|
var session := _session()
|
|
var view := _view(session)
|
|
var solid := TileShape.flags(session.terrain_codes(), MapView.SOLID)
|
|
for tile: Vector2i in [Vector2i(0, 0), session.spawn_point(), _rock(session)]:
|
|
var expected := TileShape.mask(solid, session.map_width(), session.map_height(), tile, true)
|
|
check_eq(view.mask_at(tile), expected, "the neighbours of %s" % tile)
|
|
_free(view)
|
|
|
|
|
|
func test_a_broken_rock_no_longer_shapes_its_neighbours() -> void:
|
|
var session := _session()
|
|
var view := _view(session)
|
|
var rock := _rock(session)
|
|
var west := rock + Vector2i(-1, 0)
|
|
check(view.mask_at(west) & TileShape.E != 0, "the rock lies east of its neighbour")
|
|
for hit in 3:
|
|
session.dig(rock.x, rock.y)
|
|
session.step()
|
|
for wait in GwSession.DIG_COOLDOWN_TICKS:
|
|
session.step()
|
|
check_eq(session.terrain_at(rock.x, rock.y), GwSession.TERRAIN_GROUND, "three hits break it")
|
|
view.refresh_tile(rock)
|
|
check(view.mask_at(west) & TileShape.E == 0, "now there is ground east of the neighbour")
|
|
await tree.process_frame
|
|
_free(view)
|
|
|
|
|
|
func test_a_burst_of_chips_shows_for_a_moment() -> void:
|
|
var view := _view(_session())
|
|
view.hit(Vector2i(3, 3))
|
|
check_eq(view.burst_count(), 1, "a burst")
|
|
view._process(MapView.HIT_SECONDS * 0.5)
|
|
check_eq(view.burst_count(), 1, "still in the air")
|
|
await tree.process_frame
|
|
view._process(MapView.HIT_SECONDS * 0.6)
|
|
check_eq(view.burst_count(), 0, "gone after its time")
|
|
_free(view)
|
|
|
|
|
|
func test_without_a_world_nothing_is_drawn() -> void:
|
|
var view := _view(_session())
|
|
view.session = null
|
|
view.reload()
|
|
check_eq(view.block_count(), 0, "no blocks")
|
|
view.refresh_tile(Vector2i(1, 1))
|
|
await tree.process_frame
|
|
_free(view)
|