Esempio n. 1
0
 def __init__(self, element=None, comp=None, nescient=None, hexparams=get_hex_params(35)):
     if nescient != None:
         Nescient.__init__(self, nescient.element, nescient.comp, nescient.name,
                         nescient.weapon, nescient.location, nescient.facing, nescient.body)
     else:
         if element == None:
             element = rand_element()
         if comp == None:
             comp = rand_comp(suit=element, kind='Nescient')
         Nescient.__init__(self, comp=comp, element=element)
     
     pygame.sprite.Sprite.__init__(self)
     self.hexparams  = hexparams
     self.image = pygame.Surface((577, 560))
     self.hex = make_hex(self.hexparams, COLORS[self.element])
     self.body = None
     
     self.images = {'head':None, 'left':None, 'right':None, 'tail':None}
     self.rects  = {'head':None, 'left':None, 'right':None, 'tail':None}
     
     for part in self.images:
         #self.images[part] = make_hex(self.hexparams, COLORS[self.element], self.image)
         #self.rects[part]  = self.images[part].get_rect()
         self.rects[part]  = pygame.rect.Rect((0,0), self.hexparams[-1])
     self.rect = self.image.get_rect()
     self.image.set_colorkey(black)
     self.text = []
Esempio n. 2
0
def convert_dict(dict):
    """takes a dict and returns composite objects."""
    key, value = dict.items()[0]
    if key == 'tile':
        #this obviously dramatically slows down the instanciation of a
        #previously instanciated grid, but when would this be done in real-time?
        if value['contents'] == None:
            return Tile(**eval("".join(str(value).replace("u'", "'"))))
        else:
            contents = convert_dict(value['contents'])
            del value['contents']
            tile = Tile(**eval("".join(str(value).replace("u'", "'"))))
            tile.contents = contents
            return tile
    elif key == 'grid':
        #It's dat eval hammer, boy!!! WOOO!!!
        comp = eval("".join(str(value['comp']).replace("u'", "'")))
        tiles = {}
        x = value['x']
        y = value['y']
        for i in xrange(x):
            new_x = {}
            for j in xrange(y):
                new_x.update({j: convert_dict(value['tiles'][str(i)][str(j)])})
            tiles.update({i: new_x})
        return Grid(comp, x, y, tiles)

    elif key == 'squad':
        squad = Squad(name=value['name'])
        data = value['data']
        for unit in data:
            squad.append(convert_dict(unit))
        return squad

    elif key == 'scient':
        scient = {}
        scient['element'] = value['element']
        scient['comp'] = value['comp']
        scient['name'] = value['name']
        scient = Scient(**scient)
        if not value['weapon'] == None:
            scient.weapon = convert_dict(value['weapon'])
        if not value['location'] == None:
            scient.location = Loc(value['location'][0], value['location'][1])
        return scient

    elif key == 'nescient':
        nescient = {}
        nescient['element'] = value['element']
        nescient['comp'] = value['comp']
        nescient['name'] = value['name']
        nescient['facing'] = value['facing']
        nescient['body'] = {}
        for part in value['body'].keys():
            nescient['body'][part] = Part(
                None, value['body'][part]['part']['location'])
        nescient = Nescient(**nescient)
        if not value['location'] == None:
            nescient.location = Loc(value['location'][0], value['location'][1])
        return nescient

    elif key == 'player':
        squads = []
        for squad in value['squads']:
            squads.append(convert_dict(squad))
        return Player(value['name'], squads)

    else:
        #for weapons
        return eval(
            key.capitalize())(**eval(''.join(str(value).replace("u'", "'"))))
Esempio n. 3
0
def convert_dict(dict):
    """takes a dict and returns composite objects."""
    key, value = dict.items()[0]
    if key == "tile":
        # this obviously dramatically slows down the instanciation of a
        # previously instanciated grid, but when would this be done in real-time?
        if value["contents"] == None:
            return Tile(**eval("".join(str(value).replace("u'", "'"))))
        else:
            contents = convert_dict(value["contents"])
            del value["contents"]
            tile = Tile(**eval("".join(str(value).replace("u'", "'"))))
            tile.contents = contents
            return tile
    elif key == "grid":
        # It's dat eval hammer, boy!!! WOOO!!!
        comp = eval("".join(str(value["comp"]).replace("u'", "'")))
        tiles = {}
        x = value["x"]
        y = value["y"]
        for i in xrange(x):
            new_x = {}
            for j in xrange(y):
                new_x.update({j: convert_dict(value["tiles"][str(i)][str(j)])})
            tiles.update({i: new_x})
        return Grid(comp, x, y, tiles)

    elif key == "squad":
        squad = Squad(name=value["name"])
        data = value["data"]
        for unit in data:
            squad.append(convert_dict(unit))
        return squad

    elif key == "scient":
        scient = {}
        scient["element"] = value["element"]
        scient["comp"] = value["comp"]
        scient["name"] = value["name"]
        scient = Scient(**scient)
        if not value["weapon"] == None:
            scient.weapon = convert_dict(value["weapon"])
        if not value["location"] == None:
            scient.location = Loc(value["location"][0], value["location"][1])
        return scient

    elif key == "nescient":
        nescient = {}
        nescient["element"] = value["element"]
        nescient["comp"] = value["comp"]
        nescient["name"] = value["name"]
        nescient["facing"] = value["facing"]
        nescient["body"] = {}
        for part in value["body"].keys():
            nescient["body"][part] = Part(None, value["body"][part]["part"]["location"])
        nescient = Nescient(**nescient)
        if not value["location"] == None:
            nescient.location = Loc(value["location"][0], value["location"][1])
        return nescient

    elif key == "player":
        squads = []
        for squad in value["squads"]:
            squads.append(convert_dict(squad))
        return Player(value["name"], squads)

    else:
        # for weapons
        return eval(key.capitalize())(**eval("".join(str(value).replace("u'", "'"))))
Esempio n. 4
0
 def __repr__(self):
     return Nescient.__repr__(self)
Esempio n. 5
0
File: store.py Progetto: kamoh/btpy
def convert_dict(dict):
    """takes a dict and returns composite objects."""
    key, value = dict.items()[0]
    if key == 'tile':
        #this obviously dramatically slows down the instanciation of a
        #previously instanciated grid, but when would this be done in real-time?
        if value['contents'] == None:
            return Tile(**eval("".join(str(value).replace("u'", "'"))))
        else:
            contents = convert_dict(value['contents'])
            del value['contents']
            tile = Tile(**eval("".join(str(value).replace("u'", "'"))))
            tile.contents = contents
            return tile
    elif key == 'grid':
        #It's dat eval hammer, boy!!! WOOO!!!
        comp = eval("".join(str(value['comp']).replace("u'", "'")))
        tiles = {}
        x = value['x']
        y = value['y']
        for i in xrange(x):
            new_x = {}
            for j in xrange(y):
                new_x.update({j: convert_dict(value['tiles'][str(i)][str(j)])})
            tiles.update({i: new_x})
        return Grid(comp, x, y, tiles)
        
    elif key == 'squad':
        squad = Squad(name=value['name'])
        data = value['data']
        for unit in data:
            squad.append(convert_dict(unit))
        return squad
    
    elif key == 'scient':
        scient = {}
        scient['element'] = value['element']
        scient['comp'] = value['comp']
        scient['name'] = value['name']
        scient = Scient(**scient)
        if not value['weapon'] == None:
            scient.weapon = convert_dict(value['weapon'])
        if not value['location'] == None:
            scient.location = Loc(value['location'][0], value['location'][1])
        return scient
    
    elif key == 'nescient':
        nescient = {}
        nescient['element'] = value['element']
        nescient['comp'] = value['comp']
        nescient['name'] = value['name']
        nescient['facing'] = value['facing']
        nescient['body'] = {}
        for part in value['body'].keys():
            nescient['body'][part] = Part(None, value['body'][part]['part']['location'])
        nescient = Nescient(**nescient)
        if not value['location'] == None:
            nescient.location = Loc(value['location'][0], value['location'][1])
        return nescient
    
    elif key == 'player':
        squads = []
        for squad in value['squads']:
            squads.append(convert_dict(squad))
        return Player(value['name'], squads)
    
    else:
        #for weapons
        return eval(key.capitalize())(**eval(''.join(str(value).replace("u'", "'"))))