def create_random_card(self, widget=None): """Create a random card on the desktop""" cardid = "tsp." + str(random.randint(1, 301)) w, h = self.cd.get_wh() x = (random.random() - 0.5) * (w - 2.5) y = random.random() * (h - 3.5) / 2 self.my_player.move_card(cards.get(cardid), None, self.my_player.battlefield, x, y)
def show_card(self, cardid): """Show a card picture and information""" self.hbuttonbox_transform.hide() if cardid is not None: try: self.cardpic.set_from_pixbuf(pics.get(cardid)) except RuntimeError: pass # If there is not picture, continue anyways card = cards.get(cardid) self._enlarged_card = card self.carddetails.set_markup(card.markup()) if cardid[-1] in ("a", "b"): self.hbuttonbox_transform.show() else: self.cardpic.set_from_pixbuf(pics.get("deckmaster"))
def create_carditem(self, cardid, cardname, itemid=None, x=0, y=0): # Check for card id card = cards.get(cardid) if card is None: l = cards.find_by_name(cardname) if l == []: raise RuntimeError(_("'%s' not found in database. Update?") % cardname) else: card = l[0] item = self.new_item(card, self, x, y) if itemid is None: itemid = self._get_new_itemid(item) item.itemid = itemid else: self._set_itemid(itemid, item) self.send_network_cmd("enter", cardid, cardname, itemid, item.x, item.y) self.battlefield.append(item) return item
def add_to_deck(self, cardid, sideboard=False): """Add a card to the deck""" if self.deck.readonly: self.show_dialog(None, _("This deck is read-only."), dialog_type="error") return card = cards.get(cardid) (self.deck.sideboard if sideboard else self.deck.decklist).append(card) # Look if the card has recently been deleted for row in self.cards: if row[0] == cardid and row[8] == sideboard and row[9]: row[9] = False break else: it = self.cards.append((card.id, card.name, card.manacost, card.get_composed_type(), card.power, card.toughness, card.rarity, card.setname, sideboard, False, card.price, _price_to_text(card.price), card.releasedate)) self.cardview.set_cursor(self.cards.get_path(it)) self.cardview.scroll_to_cell(self.cardview.get_model().get_path(it)) self.delayed_decksave() self.update_cardcount()
def execute_command(self, cmd, *args): """Execute a single network command""" if cmd == "reset": self.library = [] self.hand = [] self.graveyard = [] self.exile = [] self.set_life(config.DEFAULT_LIFE) for item in self.battlefield[:]: self.remove_carditem(item) self.updated_library() self.updated_hand() self.updated_graveyard() self.updated_exile() elif cmd == "tray": self.create_tray(args[0]) self.tray.x = args[1] self.tray.y = args[2] self.tray.repaint() elif cmd == "update": self.library = [None] * args[0] self.hand = [None] * args[1] self.updated_library() self.updated_hand() elif cmd == "setlife": self.set_life(args[0]) elif cmd == "enter": self.create_carditem(*args) elif cmd == "exit": item = self._get_item_by_id(args[0]) if item is self.tray: self.remove_tray() else: self.remove_carditem(item) elif cmd == "bury": self.graveyard.append(cards.get(args[0])) self.updated_graveyard() elif cmd == "unbury": assert(args[0] < len(self.graveyard)) i = args[0] self.graveyard[i:i+1] = [] self.updated_graveyard() elif cmd == "exile": self.exile.append(cards.get(args[0])) self.updated_exile() elif cmd == "unexile": assert(args[0] < len(self.exile)) i = args[0] self.exile[i:i+1] = [] self.updated_exile() elif cmd == "mulligan": self.library.append(self.hand.pop()) self.updated_library() self.updated_hand() elif cmd == "move": itemid, x, y = args item = self._get_item_by_id(itemid) if item is None: raise ValueError(_("Client sent unknown item id.")) item.repaint() item.x = x item.y = y item.repaint() elif cmd == "tap": item = self._get_item_by_id(args[0]) item.toggle_tapped() elif cmd == "flip": item = self._get_item_by_id(args[0]) item.toggle_flipped() elif cmd == "face": item = self._get_item_by_id(args[0]) item.turn_over() elif cmd == "counters": item = self._get_item_by_id(args[2]) num, counter = args[0], args[1] if num != 0: item.counters[counter] = num elif counter in item.counters: del item.counters[counter]
def add(self, cardid, sideboard=False): """Add a card by id to the deck""" card = cards.get(cardid) if card is not None: (self.sideboard if sideboard else self.deck).append(card)
def selected_token(self, tokenid): self.entrybar_unfocus() token = cards.get(tokenid) item = self.my_player.create_carditem(token.id, str(token)) item.istoken = True