Ejemplo n.º 1
0
    def load_grid(self, game_data):
        self.game_data = game_data
        loaded_grid = self.game_data.get_data('board')
        if not loaded_grid:
            print('Board.load_grid: unfound data, so create new one.')
            self.load_new_grid()
            self.save_grid()
            print('Board.load_grid: created.')
        else:
            # build Pieces from data
            for line_key in loaded_grid:
                line = loaded_grid[line_key]
                for cell_key in line:
                    cell = line[cell_key]
                    if cell == '-':
                        utils.access(self.grid, '%s/%s' % (line_key, cell_key),
                                     '-')
                    else:
                        if cell['s'] == 'w':
                            side = self.sides['white']
                        else:
                            side = self.sides['black']

                        piece = ChessPiece.PiecePawn(self, cell['n'], side)
                        utils.access(self.grid, '%s/%s' % (line_key, cell_key),
                                     piece)
Ejemplo n.º 2
0
 def set_data(self, path, new_data):
     """ writes data, at given path if specified """
     """ - data : dict """
     """ - path : url-style, leaf content is set.
             if no path specified, data is written at root """
     if path:
         # write data in path
         data = json.loads(self.data)
         utils.access(data, path, new_data)
         self.data = json.dumps(data, separators=(',', ':'), cls=MyEncoder)
     else:
         # write data at root
         self.data = json.dumps(new_data,
                                separators=(',', ':'),
                                cls=MyEncoder)
     self.save()
     return True
Ejemplo n.º 3
0
 def get_data(self, path=None):
     """ loads data, from given key if specified """
     """ - path : url-style, leaf content is returned.
             if no path specified, all data is returned """
     data = json.loads(self.data)
     if path:
         return utils.access(data, path)
     else:
         return data
Ejemplo n.º 4
0
 def set(self, path, value):
     _data = getattr(self._modelObject, self._modelField)
     utils.access(_data, path, value)
     getattr(self._modelObject, 'save')()
Ejemplo n.º 5
0
 def get(self, path=None):
     _data = getattr(self._modelObject, self._modelField)
     return utils.access(_data, path)
Ejemplo n.º 6
0
 def set_piece_at(self, x, y, piece):
     return utils.access(self.grid, '%s/%s' % (x, y), piece)
Ejemplo n.º 7
0
 def get_piece_at(self, x, y):
     return utils.access(self.grid, '%s/%s' % (x, y))
Ejemplo n.º 8
0
 def get(self, path, default=None):
     _res = utils.access(self.data, path)
     if _res is None:
         return default
     return _res
Ejemplo n.º 9
0
def access(value, path):
    jdata = json.loads(value)
    data = utils.access(jdata, path)
    return data
Ejemplo n.º 10
0
def render_realjson2html(value, path):
    data = utils.access(value, path)
    return json2html.convert(json=data)
Ejemplo n.º 11
0
def render_json2html(value, path):
    jdata = json.loads(value)
    data = utils.access(jdata, path)
    return json2html.convert(json=data)