M1d: Stilproben #12
+13
-2
@@ -62,6 +62,9 @@ var _joining := ""
|
||||
## The host's accepted guests when _process last looked. A new one ends a
|
||||
## pause.
|
||||
var _known_guests := 0
|
||||
## Tiles whose burst of chips the own figure showed when it hit them, until
|
||||
## the core reports that hit. Their burst is not shown a second time.
|
||||
var _own_hits: Dictionary[Vector2i, bool] = {}
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
@@ -217,6 +220,7 @@ func _show_world() -> void:
|
||||
hud.show_stone(session.item_count(GwSession.ITEM_STONE))
|
||||
_update_status()
|
||||
_next_dig_tick = 0
|
||||
_own_hits.clear()
|
||||
|
||||
|
||||
## Says in the status line how the game is shared, and with how many.
|
||||
@@ -242,6 +246,7 @@ func _leave(message: String) -> void:
|
||||
map_view.reload()
|
||||
avatar.is_walkable = Callable()
|
||||
figures.clear()
|
||||
_own_hits.clear()
|
||||
_show_menu(message)
|
||||
|
||||
|
||||
@@ -403,11 +408,16 @@ func _apply(events: Array[Dictionary]) -> void:
|
||||
var tile := Vector2i(event["x"], event["y"])
|
||||
map_view.refresh_tile(tile)
|
||||
# The own hits showed their burst when they were made.
|
||||
if event["player"] != local:
|
||||
if event["player"] == local:
|
||||
_own_hits.erase(tile)
|
||||
else:
|
||||
map_view.hit(tile)
|
||||
"tile_changed":
|
||||
var tile := Vector2i(event["x"], event["y"])
|
||||
map_view.refresh_tile(tile)
|
||||
# The core does not say whose hit broke the tile; an own hit
|
||||
# showed its burst already.
|
||||
if not _own_hits.erase(tile):
|
||||
map_view.hit(tile)
|
||||
"item_gained":
|
||||
if event["player"] == local:
|
||||
@@ -453,8 +463,9 @@ func dig_at(tile: Vector2i) -> void:
|
||||
return
|
||||
session.dig(tile.x, tile.y)
|
||||
_next_dig_tick = session.tick() + GwSession.DIG_COOLDOWN_TICKS
|
||||
if session.terrain_at(tile.x, tile.y) != GwSession.TERRAIN_GROUND:
|
||||
if MapView.SOLID.has(session.terrain_at(tile.x, tile.y)):
|
||||
map_view.hit(tile)
|
||||
_own_hits[tile] = true
|
||||
|
||||
|
||||
## Writes the running world as the save. Returns false if nothing was
|
||||
|
||||
@@ -392,3 +392,17 @@ func test_an_own_hit_shows_its_burst_at_once() -> void:
|
||||
main.dig_at(rock)
|
||||
check_eq(main.map_view.burst_count(), 1, "the burst shows before the hit lands in a tick")
|
||||
_clean_up([directory])
|
||||
|
||||
|
||||
func test_an_own_hit_that_breaks_the_rock_shows_its_burst_only_once() -> void:
|
||||
var directory := TestFiles.temporary_dir("break")
|
||||
var main := _start_main(directory)
|
||||
main.play(false)
|
||||
var rock: Vector2i = main.session.spawn_point() + Vector2i(7, -2)
|
||||
for blow in 3:
|
||||
main.dig_at(rock)
|
||||
for tick in GwSession.DIG_COOLDOWN_TICKS + 1:
|
||||
main._run_tick()
|
||||
check_eq(main.session.terrain_at(rock.x, rock.y), GwSession.TERRAIN_GROUND, "three own hits break the rock")
|
||||
check_eq(main.map_view.burst_count(), 3, "one burst per own hit, none more when the rock breaks")
|
||||
_clean_up([directory])
|
||||
|
||||
Reference in New Issue
Block a user