Beispiel #1
0
 def _test_updatePath(self):
     path = Path(
         '5e64cfce8aeb3647322e0880', {
             'id': '5e64de9265bf8bca60db5865',
             "planCoordinate": {
                 "x": -50,
                 "y": 0
             },
             "actualCoordinate": {
                 "x": -50,
                 "y": -70
             },
         }, {
             'id': '5e64deb3bd4b95cd35f1430f',
             "planCoordinate": {
                 "x": 70,
                 "y": 70
             },
             "actualCoordinate": {
                 "x": 70,
                 "y": 70
             }
         })
     path = self.EdgeDao.savePath(path)
     path.pointA['planCoordinate'] = {"x": -50, "y": 0}
     self.assertEqual(len(path.id), 24)
Beispiel #2
0
 def test_savePath(self):
     points = pointDao.findAll('5e64cfce8aeb3647322e0880')
     path = Path('5e64cfce8aeb3647322e0880', points[0].toJsonMap(),
                 points[1].toJsonMap())
     self.EdgeDao.savePath(path)
     path = Path('5e64cfce8aeb3647322e0880', points[1].toJsonMap(),
                 points[2].toJsonMap())
     self.EdgeDao.savePath(path)
     path = Path('5e64cfce8aeb3647322e0880', points[0].toJsonMap(),
                 points[2].toJsonMap())
     self.EdgeDao.savePath(path)
Beispiel #3
0
def create_test_world():
    world = add(World(name='Test World'))

    portal = add(Location(name='Portal', world=world))

    plaza = add(Location(name='Plaza', world=world))
    hotel = add(Location(name='Old Grand Hotel', world=world))
    basement = add(Location(name='Hotel Basement', world=world))

    add(
        Path(
            start=portal,
            destination=hotel,
            description=
            "YOU ARE IN THE HOTEL. THERE'S A DOOR TO THE BASEMENT IN FRONT OF YOU."
        ))

    add(
        Path(
            start=plaza,
            destination=hotel,
            description=
            "YOU ARE IN THE HOTEL. THERE'S A DOOR TO THE BASEMENT IN FRONT OF YOU."
        ))

    add(
        Path(start=hotel,
             destination=plaza,
             description="YOU ARE IN THE PLAZA, FACING THE HOTEL."))

    add(
        Path(
            start=hotel,
            destination=basement,
            description=
            "YOU ARE IN THE BASEMENT. THERE ARE STAIRS UP TO THE HOTEL LOBBY BEHIND YOU."
        ))

    add(
        Path(
            start=basement,
            destination=hotel,
            description=
            "YOU ARE IN THE HOTEL LOBBY. THERE'S AN EXIT TO THE PLAZA IN FRONT OF YOU."
        ))

    add(
        Session(code='TestSession1',
                active=True,
                current_location=hotel,
                previous_location=portal))

    db.session.commit()
Beispiel #4
0
 def _get_paths_starting_with(self, first, paths):
     ret = []
     for path in paths:
         c_path = Path(path=path)
         if c_path.cells[-1] == first:
             c_path.cells.reverse()
         if c_path.cells[0] == first:
             ret.append(c_path)
     return ret
Beispiel #5
0
 def _find_path_starting_and_ending_with(self, first, last, paths):
     for path in paths:
         c_path = Path(path=path)
         if c_path.cells[0] == first and c_path.cells[-1] == last:
             return c_path
         c_path.cells.reverse()
         if c_path.cells[0] == first and c_path.cells[-1] == last:
             return c_path
     return None
Beispiel #6
0
 def get_index_object(self, start, end):
     """
     A method to generate query,
          that gets bunch of object to show in the list
     """
     query = Path.all()
     query.filter('parent_c_key =', self.content.get_namekey())
     query.order(self.LIST_ORDER)
     return list(query.fetch(self.PAGE_SIZE, offset = start))
Beispiel #7
0
def upload_and_db(title, imgs):
    """
    把得到的img的url和title上传到七牛,返回的url存入到数据库
    """
    q = Auth(access_key, secret_key)
    new_pic = Picture(title=title)
    db_session.add(new_pic)
    db_session.flush()
    picture_id = new_pic.id

    for img in imgs:
        print img
        data = requests.get(img).content
        new_path = Path(picture=new_pic)
        db_session.add(new_path)
        db_session.flush()
        key_path = key_upload + str(new_path.id)
        mime_type = "image/jpeg"
        token = q.upload_token(bucket_name, key_path)
        ret, info = put_data(token, key_path, data,  mime_type=mime_type, check_crc=True)
        new_path.path_ = qiniu_url + ret['key']

    db_session.commit()
    return picture_id
Beispiel #8
0
    def parse_data(self, data):
        paths = []
        for item in data:
            parts = item.split()
            ftype = parts[0]
            size = parts[4]
            if len(parts) > 9:
                filename = ' '.join(parts[8:])
            else:
                filename = parts[8]
            date = '{month} {day} {t}'.format(month=parts[5],
                                              day=parts[6],
                                              t=parts[7])
            if filename == '.':
                # Skip this one
                continue
            paths.append(Path(ftype, size, filename, date))

        wx.CallAfter(pub.sendMessage, 'update', paths=paths)
    def _map_init(self, map_msg):
        row_num = map_msg["rows"]
        col_num = map_msg["cols"]

        input_cells = [[Cell(row=row, col=col) for col in range(col_num)] for row in range(row_num)]

        paths = [Path(id=path["id"], cells=[input_cells[cell["row"]][cell["col"]] for cell in path["cells"]]
                      ) for path in map_msg["paths"]]
        kings = [King(player_id=king["playerId"], center=input_cells[king["center"]["row"]][king["center"]["col"]],
                      hp=king["hp"],
                      attack=king["attack"], range=king["range"], target=None, target_cell=None, is_alive=True)
                 for king in map_msg["kings"]]

        self.players = [Player(player_id=map_msg["kings"][i]["playerId"], king=kings[i], deck=[],
                               hand=[], ap=self.game_constants.max_ap,
                               paths_from_player=self._get_paths_starting_with(kings[i].center, paths),
                               path_to_friend=self._find_path_starting_and_ending_with(kings[i].center,
                                                                                       kings[i ^ 1].center, paths),
                               units=[], cast_area_spell=None, cast_unit_spell=None,
                               duplicate_units=[],
                               hasted_units=[],
                               played_units=[],
                               died_units=[],
                               range_upgraded_unit=None,
                               damage_upgraded_unit=None,
                               spells=[]) for i in range(4)]

        for player in self.players:
            player.paths_from_player.remove(player.path_to_friend)

        self.player = self.players[0]
        self.player_friend = self.players[1]
        self.player_first_enemy = self.players[2]
        self.player_second_enemy = self.players[3]

        self.map = Map(row_num=row_num, col_num=col_num, paths=paths, kings=kings, cells=input_cells, units=[])
Beispiel #10
0
    def _handle_turn_units(self, msg, is_dead_unit=False):
        if not is_dead_unit:
            self._map._clear_units()
            for player in self._players:
                player.units.clear()
                player.played_units.clear()
                player.hasted_units.clear()
                player.duplicate_units.clear()
                player.range_upgraded_unit = None
                player.damage_upgraded_unit = None
        else:
            for player in self._players:
                player.died_units.clear()

        unit_input_list = []

        for unit_msg in msg:
            unit_id = unit_msg["unitId"]
            player = self.get_player_by_id(player_id=unit_msg["playerId"])
            base_unit = self._base_units[unit_msg["typeId"]]

            if not unit_msg['target'] == -1:
                target_cell = Cell(row=unit_msg["targetCell"]["row"],
                                   col=unit_msg["targetCell"]["col"])
            else:
                target_cell = None
            unit = Unit(
                unit_id=unit_id,
                base_unit=base_unit,
                cell=self._map.get_cell(unit_msg["cell"]["row"],
                                        unit_msg["cell"]["col"]),
                path=self._map.get_path_by_id(unit_msg["pathId"]),
                hp=unit_msg["hp"],
                damage_level=unit_msg["damageLevel"],
                range_level=unit_msg["rangeLevel"],
                is_duplicate=unit_msg["isDuplicate"],
                is_hasted=unit_msg["isHasted"],
                range=unit_msg["range"],
                attack=unit_msg["attack"],
                target=None,  # will be set later when all units are in set
                target_cell=target_cell,
                affected_spells=[
                    self.get_cast_spell_by_id(cast_spell_id)
                    for cast_spell_id in unit_msg["affectedSpells"]
                ],
                target_if_king=None
                if self.get_player_by_id(unit_msg["target"]) is None else
                self.get_player_by_id(unit_msg["target"]).king,
                player_id=unit_msg["playerId"])
            unit_input_list.append(unit)

            if unit.path is not None:
                if self.get_player_by_id(
                        unit.player_id
                ).king.center in unit.path.cells and unit.path.cells[
                        0] != self.get_player_by_id(
                            unit.player_id).king.center:
                    unit.path = Path(path=unit.path)
                    unit.path.cells.reverse()
                if self._get_friend_by_id(
                        unit.player_id
                ).king.center in unit.path.cells and unit.path.cells[
                        0] != self._get_friend_by_id(
                            unit.player_id).king.center:
                    unit.path = Path(path=unit.path)
                    unit.path.cells.reverse()

            if not is_dead_unit:
                self._map._add_unit_in_cell(unit.cell.row, unit.cell.col, unit)
                player.units.append(unit)
                if unit_msg["wasDamageUpgraded"]:
                    player.damage_upgraded_unit = unit
                if unit_msg["wasRangeUpgraded"]:
                    player.range_upgraded_unit = unit
                if unit_msg["wasPlayedThisTurn"]:
                    player.played_units.append(unit)
                if unit.is_hasted:
                    player.hasted_units.append(unit)
                if unit.is_duplicate:
                    player.duplicate_units.append(unit)
            else:
                player.died_units.append(unit)

        for i in range(len(unit_input_list)):
            unit = unit_input_list[i]
            if unit.target_if_king is not None:
                unit.target = None
            else:
                unit.target = self.get_unit_by_id(msg[i]["target"])
Beispiel #11
0
 def _testDropPath(self):
     path = Path(mapId='5e64cfce8aeb3647322e0880',
                 id='5e64e06d5f5e97bf5ead919b')
     print(path.id, path.mapId)
     result = self.EdgeDao.dropPath(path)
     self.assertEqual(result, 1)