mirror of
https://github.com/PaiGramTeam/SIMNet.git
synced 2024-11-22 06:17:57 +00:00
🎨 Refactor RecordCard
and Fix CI Check
This commit is contained in:
parent
d13e2e28c9
commit
f789d40bcc
@ -124,4 +124,4 @@ class BaseChronicleClient(BaseClient):
|
||||
if not data["list"]:
|
||||
raise DataNotPublic({"retcode": 10102})
|
||||
|
||||
return [RecordCard(**card) for card in data["list"]]
|
||||
return [RecordCard.creat(**card) for card in data["list"]]
|
||||
|
@ -1,6 +1,4 @@
|
||||
"""Genshin calculator models."""
|
||||
|
||||
|
||||
import collections
|
||||
from typing import Dict, Any, Literal, Optional, List
|
||||
|
||||
@ -347,7 +345,7 @@ class CalculatorResult(APIModel):
|
||||
List[CalculatorConsumable]: A list of CalculatorConsumable objects representing the total
|
||||
consumables used across all categories.
|
||||
"""
|
||||
artifacts = [i for a in self.artifacts for i in a.consumable_list]
|
||||
artifacts = [i for a in self.artifacts for i in a.consumable_list] # skipcq: PYL-E1133
|
||||
combined = self.character + self.weapon + self.talents + artifacts
|
||||
|
||||
grouped: Dict[int, List[CalculatorConsumable]] = collections.defaultdict(list)
|
||||
|
@ -1,6 +1,6 @@
|
||||
import enum
|
||||
import re
|
||||
from typing import Optional, Any, Dict, List, Union
|
||||
from typing import Optional, Any, Dict, List, Union, Type
|
||||
|
||||
from pydantic import Field, validator
|
||||
|
||||
@ -22,6 +22,9 @@ __all__ = (
|
||||
)
|
||||
|
||||
|
||||
RECORD_CARD_MAP: Dict[int, Type["RecordCard"]] = {}
|
||||
|
||||
|
||||
class Account(APIModel):
|
||||
"""A representation of an account.
|
||||
|
||||
@ -253,24 +256,19 @@ class RecordCard(BaseRecordCard):
|
||||
url (str): The URL of the record card.
|
||||
"""
|
||||
|
||||
def __new__(cls, **kwargs: Any) -> "RecordCard":
|
||||
"""Creates an appropriate record card instance based on the provided game ID.
|
||||
@classmethod
|
||||
def creat(cls, **kwargs: Any):
|
||||
"""Creates a record card.
|
||||
|
||||
Args:
|
||||
**kwargs: The arguments passed in to create the record card.
|
||||
**kwargs: Keyword arguments.
|
||||
|
||||
Returns:
|
||||
RecordCard: An instance of a subclass of `BaseRecordCard` based on the provided game ID.
|
||||
RecordCard: The record card.
|
||||
"""
|
||||
game_id = kwargs.get("game_id", 0)
|
||||
if game_id == 1:
|
||||
cls = HonkaiRecordCard # skipcq: PYL-W0642
|
||||
if game_id == 2:
|
||||
cls = GenshinRecordCard # skipcq: PYL-W0642
|
||||
if game_id == 6:
|
||||
cls = StarRailRecodeCard # skipcq: PYL-W0642
|
||||
|
||||
return super().__new__(cls) # skipcq: PYL-E1120
|
||||
new_cls = RECORD_CARD_MAP.get(game_id, cls)
|
||||
return new_cls(**kwargs)
|
||||
|
||||
|
||||
class GenshinRecordCard(RecordCard):
|
||||
@ -418,3 +416,8 @@ class StarRailRecodeCard(RecordCard):
|
||||
int: The number of chests the user has found.
|
||||
"""
|
||||
return int(self.data[3].value)
|
||||
|
||||
|
||||
RECORD_CARD_MAP.setdefault(1, HonkaiRecordCard)
|
||||
RECORD_CARD_MAP.setdefault(2, GenshinRecordCard)
|
||||
RECORD_CARD_MAP.setdefault(6, StarRailRecodeCard)
|
||||
|
Loading…
Reference in New Issue
Block a user