Example #1
0
 def _form_scient(self, element, stone_num, name=None):
     """Takes a stone from stronghold and turns it into a Scient."""
     #this should only be done by the production process.
     if name == None: name = rand_string()
     self.units.append(Scient(element, self.stones.pop(stone_num), name))
     self._p_changed = 1
     return transaction.commit()
Example #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'", "'"))))
Example #3
0
from binary_tactics.defs import Loc
from binary_tactics.units import Scient, Squad, Stone
from stores import yaml_store
from binary_tactics.weapons import *
from stores.store import get_persisted
from stores.yaml_store import *
from copy import deepcopy

sq1 = Squad()
s = Scient('Fire', Stone((2, 4, 0, 2)))
s.equip(Sword('Fire', Stone()))
for n in xrange(3):
    sq1.append(deepcopy(s))

s = Scient('Wind', Stone((0, 2, 2, 4)))
s.equip(Wand('Wind', Stone()))
for n in xrange(2):
    sq1.append(deepcopy(s))

i = Scient('Ice', Stone((2, 0, 4, 2)))
i.equip(Glove('Ice', Stone()))
for n in xrange(3):
    sq1.append(deepcopy(i))

sq0 = deepcopy(sq1)
sq0.name = "pt_0"
sq1.name = "pt_1"
for n in xrange(len(sq0)):
    sq0[n].location = Loc(n + 4, 4)
    sq1[n].location = Loc(n + 4, 11)
yaml.dump(get_persisted(sq0), file('pt_0.yaml', 'w'))