def _image_url(card_data, face_index): layout = card_data['layout'] if Layout.simple_faced_layout(layout) \ or Layout.split_faced_layout(layout) \ or Layout.double_sided_layout(layout): return card_data['card_faces'][face_index]['image_url'] else: raise NotImplementedError( f"Don't have a Cockatrice pattern for image_url of: {layout}")
def image_urls(self): data = self.get_json() layout = data['layout'] if Layout.simple_faced_layout(layout) or Layout.split_faced_layout( layout): return [data['card_faces'][0]['image_url']] elif Layout.double_sided_layout(layout): return [ x['image_url'] for x in self.card_faces() if 'image_url' in x ] else: raise ValueError(f"Unknown layout type: {layout}")
def _mana_cost(card_data, face_index): layout = card_data['layout'] if Layout.simple_faced_layout(layout) or Layout.split_faced_layout(layout): mana_costs = [ _clean_mana_cost(x['mana_cost']) for x in card_data['card_faces'] ] return ' // '.join(mana_costs) elif Layout.double_sided_layout(layout): return _clean_mana_cost(card_data['card_faces'][face_index].get( 'mana_cost', '')) else: raise NotImplementedError( f"Don't have a Cockatrice pattern for mana cost of: {layout}")
def _card_name(card_data, face_index, scarred): layout = card_data['layout'] if Layout.simple_faced_layout(layout) or Layout.double_sided_layout( layout): name = card_data['card_faces'][face_index]['name'] elif Layout.split_faced_layout(layout): name = card_data['name'] else: raise NotImplementedError( f"Don't have a Cockatrice pattern for card name of: {layout}") if scarred: return f"{name}++" else: return f"{name}'"
def _oracle_text(card, card_data, face_index): layout = card_data['layout'] if Layout.simple_faced_layout(layout) or Layout.double_sided_layout( layout): rules_text = card_data['card_faces'][face_index]['oracle_text'] elif Layout.split_faced_layout(layout): rules_text = card_data['oracle_text'] else: raise NotImplementedError( f"Don't have a Cockatrice pattern for text of: {layout}") achievement_lines = [] if card.linked_achievements(): achievement_lines.append("\n\n***") for ach in card.linked_achievements(): achievement_lines.append(ach.conditions) rules_text += '\n\n'.join(achievement_lines) return rules_text
def _add_one_card_xmls(card, root): """ In cockatrice, each physical face of a card has its own object. This doesn't apply to the abstract faces of a split card like Fire // Ice or to adventures, only to cards that physically have two sides with game content on them. (All physical cards have two physical sides.) """ card_data = card.get_json() layout = card_data['layout'] is_scarred = card.version != 1 if Layout.double_sided_layout(layout): face_indices = [0, 1] else: face_indices = [0] for face_index in face_indices: card_elem = SubElement(root, 'card') name = SubElement(card_elem, 'name') name.text = _card_name( card_data, face_index, scarred=is_scarred, ) set = SubElement(card_elem, 'set') set.text = 'clo' set.set('picurl', _image_url(card_data, face_index)) tablerow = SubElement(card_elem, 'tablerow') tablerow.text = _table_row(card_data, face_index) text = SubElement(card_elem, 'text') text.text = _oracle_text(card, card_data, face_index) # Props props = SubElement(card_elem, 'prop') props_cmc = SubElement(props, 'cmc') props_cmc.text = str(card_data['cmc']) props_layout = SubElement(props, 'layout') props_layout.text = layout props_side = SubElement(props, 'side') props_side.text = 'front' if face_index == 0 else 'back' props_maintype = SubElement(props, 'maintype') props_maintype.text = _card_maintype(card) mana_cost = _mana_cost(card_data, face_index) if mana_cost: # Most double faced cards have no mana cost on the back. props_manacost = SubElement(props, 'manacost') props_manacost.text = mana_cost card_face = card_data['card_faces'][face_index] if card_face.get('loyalty'): props_loyalty = SubElement(props, 'loyalty') props_loyalty.text = card_face['loyalty'] if card_face.get('power'): props_pt = SubElement(props, 'pt') props_pt.text = '{}/{}'.format(card_face['power'], card_face['toughness']) if Layout.double_sided_layout(layout): other_face_index = (face_index + 1) % 2 related = SubElement(card_elem, 'related') related.set('attach', 'attach') related.text = _card_name(card_data, other_face_index, is_scarred)
class EditMultiFaceCardForm(FlaskForm): face_0_name = StringField('Name') face_0_mana_cost = StringField('Mana Cost') face_0_color_override = StringField('Color Override') face_0_image_url = TextAreaField('Image Url') face_0_art_crop_url = TextAreaField('Art Crop Url') face_0_type_line = StringField('Type Line') face_0_oracle_text = TextAreaField('Rules Text') face_0_flavor_text = TextAreaField('Flavor Text') face_0_power = StringField('Power') face_0_toughness = StringField('Toughness') face_0_loyalty = StringField('Loyalty') face_1_name = StringField('Name') face_1_mana_cost = StringField('Mana Cost') face_1_color_override = StringField('Color Override') face_1_image_url = TextAreaField('Image Url') face_1_art_crop_url = TextAreaField('Art Crop Url') face_1_type_line = StringField('Type Line') face_1_oracle_text = TextAreaField('Rules Text') face_1_flavor_text = TextAreaField('Flavor Text') face_1_power = StringField('Power') face_1_toughness = StringField('Toughness') face_1_loyalty = StringField('Loyalty') comment = TextAreaField('Comment') layout = SelectField('Layout', choices=Layout.choices(), validators=[DataRequired()]) update_as = SelectField('Update As') submit = SubmitField('Update') # Used when adding a scar in order to mark the scar as applied. scar_id = HiddenField('Scar ID') def group_fields(self): """Group the form fields to allow programatic access.""" self.faces = [ { 'name': self.face_0_name, 'mana_cost': self.face_0_mana_cost, 'color_override': self.face_0_color_override, 'image_url': self.face_0_image_url, 'art_crop_url': self.face_0_art_crop_url, 'type_line': self.face_0_type_line, 'oracle_text': self.face_0_oracle_text, 'flavor_text': self.face_0_flavor_text, 'power': self.face_0_power, 'toughness': self.face_0_toughness, 'loyalty': self.face_0_loyalty, }, { 'name': self.face_1_name, 'mana_cost': self.face_1_mana_cost, 'color_override': self.face_1_color_override, 'image_url': self.face_1_image_url, 'art_crop_url': self.face_1_art_crop_url, 'type_line': self.face_1_type_line, 'oracle_text': self.face_1_oracle_text, 'flavor_text': self.face_1_flavor_text, 'power': self.face_1_power, 'toughness': self.face_1_toughness, 'loyalty': self.face_1_loyalty, }, ]