Esempio n. 1
0
 def layout(self):
     self._rmtemp()
     buttons = []
     donebtn = Button('Close', 
         self.item,
         ['close'],
         self.frontend.eventstack,
         self.frontend.imagecache,
         pos=(self.rect.x + 15,self.rect.y + 35),
         layer=self._layer +1)
     buttons.append(donebtn)
     if self.can_add:
         addbtn = Button('Add Item', 
             self.item,
             ['add'],
             self.frontend.eventstack,
             self.frontend.imagecache,
             pos=(self.rect.x, self.rect.y + 35),
             layer=self._layer +1)
         buttons.append(addbtn)
     if self.can_remove and self.selected:
         rmbtn = Button('Remove Item', 
             self.item,
             ['remove'],
             self.frontend.eventstack,
             self.frontend.imagecache,
             pos=(self.rect.x, self.rect.y + 35),
             layer=self._layer +1)
         buttons.append(rmbtn)
     for button in buttons:
         buttonspacing = ((self.rect.w-30)/len(buttons))*buttons.index(button)
         button.rect = pygame.Rect(self.rect.x+15+ buttonspacing, button.rect.y, button.rect.w,button.rect.h)
         debug(button.rect, button._layer)
         self._addtemp(make_hash(), button)
     col, row = 0,0
     size = self.frontend.mapscale + 2
     for item in self.items:
         x = col * size + self.rect.x + 15
         y = row * size + self.rect.y + 75
         sprite = ButtonSprite(self.frontend.tilemaps,
             pygame.Rect(x,y, size, size),
             eventstack=self.frontend.eventstack,
             onclick=self.select,
             onclick_params=[item],
             animations=item.getsubtree('animations'),
             layer=self._layer + 1,
             fps=5,
             sendself=False,
             mouseover=item.displayname(),
             frontend=self.frontend)
         self._addtemp(make_hash(), sprite)
         col += 1
         if col * size + 15 > self.rect.x + self.rect.w - 15:
             col = 0
             row += 1
Esempio n. 2
0
    def add_survey_hash(cls, data: OrderedDict) -> OrderedDict:
        data_for_hash = data.get("surveys")

        if data_for_hash is not None:
            data["hashes"]["survey"] = make_hash(data_for_hash)

        return data
Esempio n. 3
0
 def addadmin(self):
     if not self.exists('user', 'username', 'admin'):
         passhash, salt = make_hash('admin')
         with self.cursor as cur:
             cur.execute("INSERT INTO user(username, passhash, salt) "
                         "VALUES ({ph}, {salt});".format(ph = passhash,
                                                         salt = salt))
Esempio n. 4
0
 def item(self, action):
     if action == 'add':
         debug('Opening add item dialog')
         offset = (self.rect.w/10, self.rect.h/10)
         irect = pygame.Rect(self.rect.x+offset[0], self.rect.y+offset[1],self.rect.w - 2* offset[0], self.rect.h- 2*offset[1])
         self.c = ContainerDialog(irect,
             self.frontend,
             'Add item to container',
             layer=self._layer+1,
             items=self.addfrom,
             onclose=self.closesubwindow,
             onselect=self.additem,
             onselect_parms=[],
             animation='view',
             can_add=False,
             can_remove=False,
             addfrom=[])
         self._addtemp(make_hash(), self.c)
     elif action == 'close':
         self.delete() 
         if self.onclose is not None:
             self.onclose(self.items, *self.onclose_parms)
     elif action == 'remove':
         if self.selected in self.items:
             del self.items[self.items.index(self.selected)]
         self.selected = None
         self.layout()
Esempio n. 5
0
    def add_location_hash(cls, data: OrderedDict) -> OrderedDict:
        data_for_hash = data.get("location")

        if data_for_hash is not None:
            data["hashes"]["location"] = make_hash(data_for_hash)

        return data
Esempio n. 6
0
    def add_production_hash(cls, data: OrderedDict) -> OrderedDict:
        data_for_hash = [data.get("wellbore"), data.get("production")]

        if data_for_hash is not None:
            data["hashes"]["production"] = make_hash(data_for_hash)

        return data
Esempio n. 7
0
 def set_hash(self):
     """
     >>> o = EzdmObject({'test': 0})
     >>> hash = o.set_hash()
     >>> hash == o.get_hash()
     True
     """
     myhash = make_hash()
     self.put('hash', myhash)
     return myhash
Esempio n. 8
0
 def tileicons(self, x, y, scn_x, scn_y, scale):
     rect = pygame.Rect(scn_x, scn_y, scale, scale)
     if self.frontend.mode != 'editor':
         if not self.gamemap.tile(x,y).get('revealed', False):
             return
         player = self.frontend.game.player
         loc = player.location()
         if loc['x'] == x and loc['y'] == y and not 'player' in self.frontend.sprites:
             playerbtn = ButtonSprite(
                 self.frontend.tilemaps,
                 rect,
                 self.frontend.eventstack,
                 onclick = self.click,
                 onclick_params = [(scn_x,scn_y)],
                 animations = player.getsubtree('animations'),
                 layer=self._layer+2,
                 fps=5,
                 mouseover=player.displayname(),
                 frontend=self.frontend)
             self.frontend.sprites['player'] = playerbtn
     scn_x = 50+(self.tilesize*x)
     scn_y = 65+(self.tilesize*y)
     npc = None
     animations = {'view':[]}
     for objtype, item in self.gamemap.tile_objects(x,y):
         if objtype != 'npc':
             animations['view'] += item.get('animations/view')
         else:
             npc = ButtonSprite(
                 self.frontend.tilemaps,
                 rect,
                 self.frontend.eventstack,
                 onclick = self.click,
                 onclick_params = [(scn_x,scn_y)],
                 animations = item.getsubtree('animations'),
                 layer=self._layer+2,
                 fps=5,
                 mouseover=item.displayname(),
                 frontend=self.frontend)
     if animations['view'] and npc is None:
         itemsprite = ButtonSprite(
             self.frontend.tilemaps,
             rect,
             self.frontend.eventstack,
             onclick = self.click,
             onclick_params = [(scn_x,scn_y)],
             animations = animations,
             layer=self._layer+1,
             fps=3,
             frontend=self.frontend)
         self._addtemp(make_hash(), itemsprite)
     if npc is not None and not npc.get_hash() in self.frontend.sprites:
         self.frontend.sprites[npc.get_hash()] = npc
         if not npc in self.frontend.game.characters: 
             self.frontend.game.characters.append(npc)
Esempio n. 9
0
 def targetclick(self,x,y,objtype, item):
     minx, miny = self.frontend.rightwindow_rect.x + 10, self.frontend.rightwindow_rect.y + 10
     if self.frontend.mode == 'editor':
         rmBtn = Button('Remove',
         self.removefromtile,
         [x,y,objtype,item],
         self.frontend.eventstack,
         self.frontend.imagecache,
         pos=(minx,miny + 185)
         )
         self._addtemp(make_hash(), rmBtn)
Esempio n. 10
0
    def layout(self):
        self._rmtemp()

        itemlist = []
        for itemfile in file_list('items'):
            itemfile = os.path.basename(itemfile)
            itemlist.append(Item(load_yaml('items',itemfile)))
        inventory_rect = pygame.Rect(self.rect.x,self.rect.y, self.rect.w - 523, self.rect.h)
        pack = ContainerDialog(
            inventory_rect,
            self.frontend,
            'Pack:',
            layer=self._layer +1,
            items=[Item(i) for i in self.char.get('inventory/pack',[])],
            onclose=self.update_inventory,
            onselect=self.equip_item,
            onselect_parms=[],
            can_add=False,
            can_remove=False,
            addfrom=itemlist
            )
        self._addtemp('Inventory_pack_dialog', pack)
        image_x = self.rect.w - 522
        image_y = 10
        self.image.blit(self.frontend.imagecache['inventory_background.png'], (image_x, image_y))
        rects = load_yaml('images','gui_rects.yaml')
        debug(self.char())
        portrait = self.frontend.imagecache[self.char.get('personal/portrait')]
        portrait = pygame.transform.smoothscale(portrait, (256,256))
        prect = rects['inventory_portrait']
        self.image.blit(portrait,(image_x + prect['x'],image_y + prect['y']))
        image_x += self.rect.x
        image_y += self.rect.y
        for itemtuple in self.char.inventory_generator(['equiped']):
            debug(itemtuple)
            item, slot = itemtuple[1], itemtuple[2]
            irect = rects[slot]
            irect = pygame.Rect(image_x + irect['x'], image_y + irect['y'], irect['w'], irect['h'])
            debug(slot, irect)
            sprite = ButtonSprite(
                self.frontend.tilemaps,
                irect,
                self.frontend.eventstack,
                onclick=self.unequip_item,
                onclick_params=[slot],
                animations=item.getsubtree('animations'),
                layer=self._layer + 2,
                fps=5,
                mouseover=item.displayname(),
                frontend=self.frontend,
                sendself=True
                )
            sprite.setanimation('view')
            self._addtemp(make_hash(), sprite)
Esempio n. 11
0
 def __init__(self, tilemaps, rect, eventstack, onclick=None, onclick_params=[], animations={}, layer=2, fps=60,sendself=False, mouseover='', frontend=None):
     self._layer = layer
     AnimatedSprite.__init__(self, tilemaps, rect, animations, layer, fps)
     self.registered_events = []
     self.eventstack = eventstack
     self.onclick = onclick
     self.onclick_params = onclick_params
     self.sendself = sendself
     self.registered_events.append(self.eventstack.register_event("button1", self, self.click))
     self.mouseover_text = mouseover
     if mouseover:
         self.mo_hash = make_hash()
         self.frontend = frontend
         self.registered_events.append(self.eventstack.register_event("mouseover", self, self.mouseover))
Esempio n. 12
0
 def zoomicons(self, x, y, scn_x, scn_y):
     objlist = list(self.gamemap.tile_objects(x,y))
     n = len(objlist)
     if not n:
         return
     col, row = 0, 0
     if n%2 != 0:
         n += 1
     colcount = n/2
     if n < 4:
         scale = int(128/n)
     else:
         scale = int(128/colcount)
     for objtype,item in objlist:
         s_x = scn_x + col*scale
         s_y = scn_y + row*scale
         rect = pygame.Rect(s_x, s_y, scale, scale)
         if objtype != 'money':
             animations = item.getsubtree('animations')
             name=item.displayname()
         else:
             animations = item
             name='Money'
         itemsprite = ButtonSprite(
         self.frontend.tilemaps,
         rect,
         self.frontend.eventstack,
         onclick = self.targetclick,
         onclick_params = [x,y,objtype, item],
         animations = animations,
         layer=self._layer+2,
         mouseover=name,
         fps=5,
         frontend=self.frontend)
         if objtype == 'npc':
             itemsprite.setanimation('stand')
         else:
             itemsprite.setanimation('view')
         self._addtemp(make_hash(), itemsprite)
         col += 1
         if col == colcount:
             col = 0
             row += 1
Esempio n. 13
0
 def load(self):
     self._rmtemp()
     itemlist = []
     for itemfile in file_list(self.dirname):
         itemfile = os.path.basename(itemfile)
         if self.dirname == 'items':
             itemlist.append(Item(load_yaml(self.dirname,itemfile)))
         else:
             itemlist.append(NPC(load_yaml(self.dirname,itemfile)))
     c = ContainerDialog(self.rect,
         self.frontend,
         'Load %s' %self.dirname,
         7,
         items=itemlist,
         onselect=self.loaditem,
         onselect_parms=[],
         animation='view',
         can_add=False,
         can_remove=False
         )
     self._addtemp(make_hash(), c)
Esempio n. 14
0
 def register_event(self, event, sprite, method):
     id = make_hash()
     self.events[event][sprite] = (method, id)
     return id 
Esempio n. 15
0
 def add_document_hash(cls, data: OrderedDict) -> OrderedDict:
     data = cls.remove_variants(data)
     hashes = {"document": make_hash(data)}
     data["hashes"] = hashes
     return data
Esempio n. 16
0
 def editorlayout(self):
     debug('Building editor layout')
     self._rmtemp()
     self.baselayout()
     col, row = 0, 0
     for key in [i for i in self.template if '__Y' in i]:
         value = self.item.get(realkey(key),False)
         if value is False:
             self.item.put(realkey(key), self.template[key])            
     list1 = sorted([i for i in self.template if not i.startswith('conditional/') and not i.startswith('events/') and not '__Y' in i and not 'animations' in i and i != 'personal/portrait'])
     list3 = sorted([i for i in self.template if  i.startswith('events/')])
     list2 = sorted([i for i in self.conditional_sprites if not 'animations' in i])
     if [i for i in self.template if 'equiped' in i]:
         list4=['inventory']
     else:
         list4 = []
     allkeys = list1 + list2 + list3 + list4
     for key in allkeys:
         x = col * 450 + self.rect.x + 15
         y = row * 35 + self.rect.y + 75
         if key == 'inventory':
             b = Button('Iventory', 
                 self.showinventory, 
                 [],
                 self.frontend.eventstack,
                 self.frontend.imagecache,
                 pos=(x ,y),
                 layer=6,
                 fontsize=14)
             self._addtemp('%s_button' % key, b)
             row += 1
             continue
         if key.startswith('events/') or key.startswith('__T'):
             b = Button(realkey(key), 
                 self.make_event, 
                 [realkey(key)],
                 self.frontend.eventstack,
                 self.frontend.imagecache,
                 pos=(x ,y),
                 layer=6,
                 sendself=True,
                 fontsize=14)
             self._addtemp('%s_button' % key, b)
         else: 
             sprites = self.handlekey(key, x,y)
             for sprite in sprites:
                 self._addtemp('%s_%s' % (key,sprites.index(sprite)), sprite)
         row += 1
         if row * 35 + self.rect.y + 75 + 128> self.rect.y + self.rect.h -75:
             row = 0
             col += 1
     for key in sorted([i for i in self.conditional_sprites if 'animations' in i])+sorted(i for i in self.template if 'animations' in i and not 'conditional' in i and i != 'personal/portrait'):
         keyname = realkey(key)
         value = self.item.get(keyname,[])
         if not value:
             value = self.template[key]
         self.item.put(keyname, value)
     if self.item.animations:
         x = col * 450 + self.rect.x + 15
         y = row * 35 + self.rect.y + 75
         self.animation_editor(x,y)
     y = y + 75
     for sprite in self.handlekey('personal/portrait', x,y):
         self._addtemp(make_hash(), sprite)
Esempio n. 17
0
File: dbm.py Progetto: asyks/mipedia
 def insert_one(cls, u, p, e):
   h = util.make_hash(u, p)
   with db.transaction():
     db.insert('users', username=u, passwordhash=h, email=e)