Example #1
0
    def __init__(self, card_data: dict) -> None:
        self.scryfall_oracle_id: str = card_data.get(
            "identifiers", {}).get("scryfallOracleId")

        self.name: str = card_data.get("faceName", card_data["name"])
        self.side = card_data.get("side")

        self.mana_cost: str = card_data.get("manaCost")

        cmc_text = card_data.get("faceConvertedManaCost",
                                 card_data.get("convertedManaCost"))
        self.converted_mana_cost: float = (float(cmc_text) if cmc_text
                                           is not None else float(0))

        self.colour: int = Colour.colour_codes_to_flags(
            card_data.get("colors", []))
        self.colour_indicator: int = Colour.colour_codes_to_flags(
            card_data.get("colorIndicator", []))
        self.colour_count: int = bin(self.colour).count("1")
        # self.colour_sort_key: int = COLOUR_TO_SORT_KEY[self.colour_flags]
        self.colour_sort_key: int = 0  # TODO: Colour sort keys

        self.power: Optional[str] = card_data.get("power")
        self.toughness: Optional[str] = card_data.get("toughness")
        self.loyalty: Optional[str] = card_data.get("loyalty")
        self.rules_text: Optional[str] = card_data.get("text")
        self.hand_modifier: str = card_data.get("hand")
        self.life_modifier: str = card_data.get("life")

        self.type_line: Optional[str] = card_data.get("type")
        self.types: List[str] = card_data.get("types", [])
        self.subtypes: List[str] = card_data.get("subtypes", [])
        self.supertypes: List[str] = card_data.get("supertypes", [])
Example #2
0
 def test_color_rg_param(self) -> None:
     """
     Tests that a multiple colour query is converted to the correct parametes
     """
     root_param = self.parser.parse("color:rg")
     self.assertIsInstance(root_param, CardComplexColourParam)
     self.assertEqual(root_param.colours, [Colour.red(), Colour.green()])
     self.assertEqual(root_param.operator, ">=")
Example #3
0
    def get_colour_identity(self) -> int:
        """
        Gets the bits of the colour identity for this card
        :return:
        """
        if 'colorIdentity' in self.value_dict:
            return Colour.colour_codes_to_flags(self.value_dict['colorIdentity'])

        return 0
Example #4
0
    def get_colour(self) -> int:
        """
        Gets the colour bits of the card
        :return:
        """
        if 'colors' in self.value_dict:
            return Colour.colour_codes_to_flags(self.value_dict['colors'])

        return 0
Example #5
0
    def test_multiple_colour_params(self) -> None:
        """
        Tests that a colour query string is converted to parameters
        """
        root_param = self.parser.parse("color>=uw -c:red")
        self.assertIsInstance(root_param, AndParam)
        self.assertEqual(len(root_param.child_parameters), 2)
        white_blue_param, not_red_param = root_param.child_parameters
        self.assertIsInstance(white_blue_param, CardComplexColourParam)
        self.assertIsInstance(not_red_param, CardComplexColourParam)

        self.assertListEqual(white_blue_param.colours,
                             [Colour.blue(), Colour.white()])
        self.assertEqual(white_blue_param.operator, ">=")
        self.assertEqual(white_blue_param.negated, False)

        self.assertEqual(not_red_param.colours, [Colour.red()])
        self.assertEqual(not_red_param.operator, ">=")
        self.assertEqual(not_red_param.negated, True)
Example #6
0
    def update_colours(self):
        """
        Updates all colours from file
        """
        logger.info('Updating colour list')

        for colour in import_json(COLOUR_JSON_PATH):
            colour_obj = Colour.objects.filter(symbol=colour['symbol']).first()
            if colour_obj is not None:
                logger.info('Updating existing colour %s', colour_obj)
                self.increment_updated('Colour')
            else:
                logger.info('Creating new colour %s', colour['name'])
                colour_obj = Colour(symbol=colour['symbol'],
                                    name=colour['name'],
                                    display_order=colour['display_order'],
                                    bit_value=colour['bit_value'])
                colour_obj.full_clean()
                colour_obj.save()
                self.increment_updated('Colour')
Example #7
0
    def test_less_than_colour_identity(self) -> None:
        """
        Tests that a colour identity string is converted to parameters
        """
        root_param = self.parser.parse("id<=esper t:instant")
        self.assertIsInstance(root_param, AndParam)
        self.assertEqual(len(root_param.child_parameters), 2)
        esper_param, instant_param = root_param.child_parameters

        self.assertIsInstance(esper_param, CardComplexColourParam)
        self.assertEqual(
            esper_param.colours,
            [Colour.white(), Colour.blue(),
             Colour.black()])
        self.assertEqual(esper_param.operator, "<=")
        self.assertFalse(esper_param.negated)

        self.assertIsInstance(instant_param, CardGenericTypeParam)
        self.assertEqual(instant_param.card_type, "instant")
        self.assertFalse(instant_param.negated)
Example #8
0
    def update_colours(self) -> None:
        """
        Updates all colours from file
        """
        logger.info("Updating colour list")

        for colour in import_json(COLOUR_JSON_PATH):
            colour_obj = Colour.objects.filter(symbol=colour["symbol"]).first()
            if colour_obj is not None:
                logger.info("Updating existing colour %s", colour_obj)
                self.increment_updated("Colour")
            else:
                logger.info("Creating new colour %s", colour["name"])
                colour_obj = Colour(symbol=colour["symbol"])
                self.increment_created("Colour")
            colour_obj.name = colour["name"]
            colour_obj.display_order = colour["display_order"]
            colour_obj.bit_value = colour["bit_value"]
            colour_obj.chart_colour = colour["chart_colour"]
            colour_obj.full_clean()
            colour_obj.save()
Example #9
0
    def test_no_colour_id_and_type_param(self) -> None:
        """
        Tests that a colour identity plus a type parameter parse ok
        """
        root_param = self.parser.parse("id:c t:land")
        self.assertIsInstance(root_param, AndParam)
        self.assertEqual(len(root_param.child_parameters), 2)
        id_param, type_param = root_param.child_parameters
        self.assertIsInstance(id_param, CardComplexColourParam)
        self.assertIsInstance(type_param, CardGenericTypeParam)
        self.assertEqual(id_param.colours, [Colour.colourless()])
        self.assertEqual(id_param.operator, "<=")

        self.assertEqual(type_param.operator, ":")
        self.assertEqual(type_param.card_type, "land")
Example #10
0
    def __init__(self, card_data: dict, is_token: bool = False) -> None:
        self.is_token: bool = is_token
        self.scryfall_oracle_id: str = card_data.get(
            "identifiers", {}).get("scryfallOracleId")
        self.name: str = card_data["name"]
        self.converted_mana_cost: float = float(
            card_data.get("convertedManaCost", 0.0))
        self.colour_identity: int = Colour.colour_codes_to_flags(
            card_data.get("colorIdentity", []))
        self.colour_identity_count: int = bin(self.colour_identity).count("1")

        self.layout: str = card_data.get("layout", "normal")

        self.rulings: List[Dict[str, str]] = card_data.get("rulings", [])
        self.legalities: Dict[str, str] = card_data.get("legalities", {})
        self.is_reserved: bool = bool(card_data.get("isReserved", False))