Ejemplo n.º 1
0
def test_duplicated_move(battle_map: ManagedBattleMap):
    move = get_test_move()

    battle_map.process_token_action(move)
    move.action_type = TokenActionType.Moved
    with raises(IllegalMove):
        battle_map.process_token_action(move)
Ejemplo n.º 2
0
def test_illegal_remove(battle_map: ManagedBattleMap):
    battle_map.process_token_action(get_test_move())
    with raises(IllegalMove):
        battle_map.process_token_action(
            get_test_move({
                'action_type': TokenActionType.Removed,
                'mark': '7'
            }))
Ejemplo n.º 3
0
def test_remove(battle_map: ManagedBattleMap):
    add = get_test_move()

    battle_map.process_token_action(add)

    remove = get_test_move({'action_type': TokenActionType.Removed})
    battle_map.process_token_action(remove)

    assert len(battle_map.tokens) == 0

    history = battle_map.get_history(0)
    assert len(history) == 2
    assert history[1].payload.uuid == remove.uuid
    assert history[1].payload.action_type == TokenActionType.Removed
Ejemplo n.º 4
0
def test_simple(battle_map: ManagedBattleMap):
    move = get_test_move()

    battle_map.process_token_action(move)

    assert battle_map.action_count == 1
    assert len(battle_map.tokens) == 1
    assert battle_map.tokens[0].mark == '23'

    history = battle_map.get_history(0)
    assert len(history) == 1
    assert history[0].payload.uuid == move.uuid

    assert len(battle_map.get_history(1)) == 0
Ejemplo n.º 5
0
def test_overflow(battle_map: ManagedBattleMap):
    test_moves = []
    for i in range(320):
        move = get_test_move({'mark': str(i)})
        battle_map.process_token_action(move)
        test_moves.append(move)

    assert battle_map.action_count == 320
    assert len(battle_map.tokens) == 320

    history = battle_map.get_history(20)
    assert len(history) == 300
    assert history[50].payload.mark == '70'
    assert history[50].payload.uuid == test_moves[70].uuid

    with raises(LogsExpired):
        battle_map.get_history(19)
Ejemplo n.º 6
0
def test_move(battle_map: ManagedBattleMap):
    add = get_test_move()

    battle_map.process_token_action(add)

    move = get_test_move({
        'action_type': TokenActionType.Moved,
        'position': Coordinate(x=100, y=45)
    })
    battle_map.process_token_action(move)

    assert battle_map.tokens[0].position.x == 100
    assert battle_map.tokens[0].position.y == 45

    history = battle_map.get_history(0)
    assert len(history) == 2
    assert history[1].payload.uuid == move.uuid
    assert history[1].payload.action_type == TokenActionType.Moved
    def load_battle_map(self, map_set: MapSet, uuid: UUID) -> ManagedBattleMap:
        map_set_io = self._map_set_io
        battle_map = map_set_io.load_battle_map(map_set, uuid)
        background_image = map_set_io.load_image_data(map_set, uuid)

        if background_image is None and battle_map.background_media_type is not None:
            raise CorruptedImageData(
                f"Battle map {battle_map.uuid} has missing image data!"
            )
        if background_image is not None and battle_map.background_media_type is None:
            raise CorruptedImageData(
                f"Battle map {battle_map.uuid} has image data but no media type!"
            )

        return ManagedBattleMap(map_set=map_set, background_image=background_image, **battle_map.__dict__)
Ejemplo n.º 8
0
 def add_new_battle_map(self, name: str) -> ManagedBattleMap:
     battle_map = ManagedBattleMap(name=name, uuid=uuid4(), map_set=self)
     self.battle_maps_by_uuid[battle_map.uuid] = battle_map
     self.touch()
     return battle_map
 def save_battle_map(self, battle_map: ManagedBattleMap):
     map_set_io = self._map_set_io
     map_set_io.save_battle_map(battle_map.map_set, battle_map.get_clean_data())
 def sanitize_token_positions(self, battle_map: ManagedBattleMap):
     map_set_io = self._map_set_io
     width, height = map_set_io.get_image_dimensions(map_set=battle_map.map_set, battle_map_uuid=battle_map.uuid)
     battle_map.sanitize_token_positions(width, height)
Ejemplo n.º 11
0
def test_trivial(battle_map: ManagedBattleMap):
    assert len(battle_map.get_history(0)) == 0
    assert battle_map.action_count == 0
    assert len(battle_map.tokens) == 0
Ejemplo n.º 12
0
def test_illegal_add(battle_map: ManagedBattleMap):
    battle_map.process_token_action(get_test_move())
    with raises(IllegalMove):
        battle_map.process_token_action(get_test_move())
Ejemplo n.º 13
0
def battle_map() -> ManagedBattleMap:
    map_set = MapSet(name='Test', uuid=uuid4())
    yield ManagedBattleMap(uuid=UUID('cc24fb89-318d-4912-884d-6a7213a562a2'),
                           name='Test',
                           map_set=map_set)