5
5
from reportlab .lib .units import cm
6
6
7
7
8
+ class CardType (object ):
9
+ @staticmethod
10
+ def decode_json (obj ):
11
+ return CardType (** obj )
12
+
13
+ def __init__ (
14
+ self ,
15
+ card_type ,
16
+ card_type_image ,
17
+ group_global_type = None ,
18
+ group_cost = None ,
19
+ defaultCardCount = 10 ,
20
+ tabTextHeightOffset = 0 ,
21
+ tabCostHeightOffset = - 1 ,
22
+ ):
23
+ self .typeNames = tuple (card_type )
24
+ self .tabImageFile = card_type_image
25
+ self .group_global_type = group_global_type
26
+ self .group_cost = group_cost
27
+ self .defaultCardCount = defaultCardCount
28
+ self .tabTextHeightOffset = tabTextHeightOffset
29
+ self .tabCostHeightOffset = tabCostHeightOffset
30
+
31
+ def getTypeDefaultCardCount (self ):
32
+ return self .defaultCardCount
33
+
34
+ def getTypeNames (self ):
35
+ return self .typeNames
36
+
37
+ def getTabImageFile (self ):
38
+ if not self .tabImageFile :
39
+ return None
40
+ return self .tabImageFile
41
+
42
+ def getGroupGlobalType (self ):
43
+ return self .group_global_type
44
+
45
+ def getGroupCost (self ):
46
+ return self .group_cost
47
+
48
+ def getTabTextHeightOffset (self ):
49
+ return self .tabTextHeightOffset
50
+
51
+ def getTabCostHeightOffset (self ):
52
+ return self .tabCostHeightOffset
53
+
54
+
8
55
class Card (object ):
9
56
sets = None
10
57
types = None
@@ -31,7 +78,7 @@ def __init__(
31
78
potcost = 0 ,
32
79
debtcost = 0 ,
33
80
extra = "" ,
34
- count = - 1 ,
81
+ count = None ,
35
82
card_tag = "missing card_tag" ,
36
83
cardset_tags = None ,
37
84
group_tag = "" ,
@@ -61,32 +108,48 @@ def __init__(
61
108
self .cardset_tags = cardset_tags
62
109
self .group_tag = group_tag
63
110
self .group_top = group_top
64
- self .image = image
111
+ self .image = image # used for promo cards with unique "set" images
65
112
self .text_icon = text_icon
66
113
self .cardset_tag = cardset_tag
67
- self .setCardCount (count )
68
114
self .randomizer = randomizer
69
115
70
- def getCardCount (self ):
71
- return sum (i for i in self .count )
116
+ if count is not None :
117
+ if isinstance (count , int ):
118
+ self ._counts = [count ]
119
+ elif isinstance (count , str ) and count .isdigit ():
120
+ self ._counts = [int (count )]
121
+ else :
122
+ raise TypeError (
123
+ f"{ name or card_tag } : Count must be int or str: { count } has type { type (count )} "
124
+ )
125
+ else :
126
+ self ._counts = None
127
+
128
+ def getCardCount (self ) -> int :
129
+ return sum (self .getCardCounts ())
130
+
131
+ def getCardCounts (self ) -> list [int ]:
132
+ if self ._counts is None :
133
+ return [self .getType ().getTypeDefaultCardCount ()]
134
+ return self ._counts
72
135
73
136
def setCardCount (self , value ):
74
- value = int (value )
75
- if value < 0 :
76
- self .count = [self .getType ().getTypeDefaultCardCount ()]
77
- elif value == 0 :
78
- self .count = []
137
+ if value == 0 :
138
+ self ._counts = []
79
139
else :
80
- self .count = [value ]
140
+ self ._counts = [int ( value ) ]
81
141
82
- def addCardCount (self , value ):
83
- self .count .extend (value )
142
+ def mergeCardCount (self , value : list ):
143
+ if self ._counts is None :
144
+ self ._counts = value
145
+ else :
146
+ self ._counts .extend (value )
84
147
85
148
def getStackHeight (self , thickness ):
86
- # return height of the stacked cards in cm. Using hight in cm of a stack of 60 Copper cards as thickness.
149
+ # return height of the stacked cards in cm. Using height in cm of a stack of 60 Copper cards as thickness.
87
150
return self .getCardCount () * cm * (thickness / 60.0 ) + 2
88
151
89
- def getType (self ):
152
+ def getType (self ) -> CardType :
90
153
return Card .types [tuple (self .types )]
91
154
92
155
def getBonusBoldText (self , text ):
@@ -169,35 +232,28 @@ def get_GroupGlobalType(self):
169
232
def get_GroupCost (self ):
170
233
return self .getType ().getGroupCost ()
171
234
172
- def get_total_cost (self , c ):
173
- # Return a tuple that represents the total cost of card c
174
- # Hightest cost cards are in order:
175
- # - Types with group cost of "" sort at the very end
176
- # - cards with * since that can mean anything
177
- # - cards with numeric errors
178
- # convert cost (a string) into a number
179
- if c .get_GroupCost () == "" :
235
+ def cost_sort_key (self ):
236
+ """Return a tuple that represents the total cost of this card in (coins, potions, debt)
237
+ used for sorting cards by cost.
238
+ Highest cost cards are in order:
239
+ - Types with group cost of "" sort at the very end
240
+ - cards with * since that can mean anything
241
+ - cards with numeric errors
242
+ convert cost (a string) into a number
243
+ """
244
+ if self .get_GroupCost () == "" :
180
245
c_cost = 999
181
- elif not c .cost :
246
+ elif not self .cost :
182
247
c_cost = 0 # if no cost, treat as 0
183
- elif "*" in c .cost :
248
+ elif "*" in self .cost :
184
249
c_cost = 998 # make it a really big number
185
250
else :
186
251
try :
187
- c_cost = int (c .cost )
252
+ c_cost = int (self .cost )
188
253
except ValueError :
189
254
c_cost = 997 # can't, so make it a really big number
190
255
191
- return c_cost , c .potcost , c .debtcost
192
-
193
- def set_lowest_cost (self , other ):
194
- # set self cost fields to the lower of the two's total cost
195
- self_cost = self .get_total_cost (self )
196
- other_cost = self .get_total_cost (other )
197
- if other_cost < self_cost :
198
- self .cost = other .cost
199
- self .potcost = other .potcost
200
- self .debtcost = other .debtcost
256
+ return c_cost , self .potcost , self .debtcost
201
257
202
258
def setImage (self , use_set_icon = False ):
203
259
setImage = None
@@ -235,50 +291,3 @@ def __init__(self, num):
235
291
236
292
def isBlank (self ):
237
293
return True
238
-
239
-
240
- class CardType (object ):
241
- @staticmethod
242
- def decode_json (obj ):
243
- return CardType (** obj )
244
-
245
- def __init__ (
246
- self ,
247
- card_type ,
248
- card_type_image ,
249
- group_global_type = None ,
250
- group_cost = None ,
251
- defaultCardCount = 10 ,
252
- tabTextHeightOffset = 0 ,
253
- tabCostHeightOffset = - 1 ,
254
- ):
255
- self .typeNames = tuple (card_type )
256
- self .tabImageFile = card_type_image
257
- self .group_global_type = group_global_type
258
- self .group_cost = group_cost
259
- self .defaultCardCount = defaultCardCount
260
- self .tabTextHeightOffset = tabTextHeightOffset
261
- self .tabCostHeightOffset = tabCostHeightOffset
262
-
263
- def getTypeDefaultCardCount (self ):
264
- return self .defaultCardCount
265
-
266
- def getTypeNames (self ):
267
- return self .typeNames
268
-
269
- def getTabImageFile (self ):
270
- if not self .tabImageFile :
271
- return None
272
- return self .tabImageFile
273
-
274
- def getGroupGlobalType (self ):
275
- return self .group_global_type
276
-
277
- def getGroupCost (self ):
278
- return self .group_cost
279
-
280
- def getTabTextHeightOffset (self ):
281
- return self .tabTextHeightOffset
282
-
283
- def getTabCostHeightOffset (self ):
284
- return self .tabCostHeightOffset
0 commit comments