67 lines
2.4 KiB
Python
67 lines
2.4 KiB
Python
from engine.entity import Entity, EntityPosition
|
|
from engine.map import Map
|
|
from engine.tile import Tile, TileLayerInstance
|
|
from engine.world import World
|
|
|
|
|
|
class FakeRegistry:
|
|
def get_tile_layer_def(self, _layer, _def_id):
|
|
return None
|
|
|
|
|
|
def make_world_with_gap():
|
|
# a 10x10 field with a "water" gap (still walkable=True at the data level, but no dock
|
|
# path) between the player's dock and a ship anchored two tiles away
|
|
parent = Map("world", 10, 10, 1)
|
|
for x in range(10):
|
|
for y in range(10):
|
|
parent.set_tile(x, y, 0, Tile(flooring=TileLayerInstance("grass")))
|
|
|
|
ship = Map("ship", 3, 3, 1)
|
|
for x in range(3):
|
|
for y in range(3):
|
|
ship.set_tile(x, y, 0, Tile(flooring=TileLayerInstance("wood_deck")))
|
|
|
|
parent.embed(ship, (7, 5, 0)) # ship's footprint is x:7-9, y:5-7
|
|
return parent, ship
|
|
|
|
|
|
def test_leap_crosses_a_gap_that_a_single_step_could_not():
|
|
parent, ship = make_world_with_gap()
|
|
world = World()
|
|
world.maps = {"world": parent, "ship": ship}
|
|
world.registry = FakeRegistry()
|
|
|
|
player = Entity(position=EntityPosition("world", 5, 6, 0))
|
|
# a single step east only reaches (6,6,0), still short of the ship at x=7
|
|
assert world.try_move(player, 1, 0, 0) is True
|
|
assert (player.position.x, player.position.y) == (6, 6)
|
|
|
|
# leaping east 2 tiles clears the remaining gap and lands aboard the ship
|
|
assert world.try_leap(player, 1, 0, 0) is True
|
|
assert player.position.map_id == "ship"
|
|
assert (player.position.x, player.position.y, player.position.z) == (1, 1, 0)
|
|
|
|
|
|
def test_leap_distance_is_configurable():
|
|
parent, ship = make_world_with_gap()
|
|
world = World()
|
|
world.maps = {"world": parent, "ship": ship}
|
|
world.registry = FakeRegistry()
|
|
|
|
player = Entity(position=EntityPosition("world", 4, 6, 0))
|
|
assert world.try_leap(player, 1, 0, 0, distance=1) is True
|
|
assert player.position.map_id == "world" # a 1-tile leap from x=4 lands short of the ship at x=7
|
|
assert (player.position.x, player.position.y) == (5, 6)
|
|
|
|
|
|
def test_leap_lands_out_of_bounds_fails_like_a_normal_move():
|
|
parent, ship = make_world_with_gap()
|
|
world = World()
|
|
world.maps = {"world": parent, "ship": ship}
|
|
world.registry = FakeRegistry()
|
|
|
|
player = Entity(position=EntityPosition("world", 0, 0, 0))
|
|
assert world.try_leap(player, -1, 0, 0) is False
|
|
assert (player.position.x, player.position.y) == (0, 0)
|