CardInventory
Bases: UserDict
Represents an inventory of unique Flesh and Blood cards.
This is essentially a dict[InventoryItem, int]
, where the value of a
particular key denotes the number of copies in the inventory.
Note
This class inherits collections.UserDict
, and thus supports any common
dict
methods.
Warning
Note that since this object is essentially a dict
, calling len()
on it
will not return the total number of cards in the inventory. Instead, it
returns the total number of different types of cards in the inventory.
To get the overall number of cards in the inventory, use the count()
method.
Attributes:
Name | Type | Description |
---|---|---|
data |
dict[InventoryItem, int]
|
The underlying |
Source code in fab/inventory.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
|
add(identifier, rarity, foiling, count=1, edition='U')
¶
Adds one or more copies of a unique card to this inventory.
This method builds a InventoryItem
object from the specified
parameters. To add a pre-built InventoryItem
object to the collection,
use add_item()
. If the inventory already contains the specified card,
its count is increased by the value specified (to set the count, use
set()
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
count |
int
|
The number of copies to add to the inventory. |
1
|
edition |
str
|
The edition code of the card (see |
'U'
|
foiling |
str
|
The foiling code of the card (see |
required |
identifier |
str
|
The identifier of the card to add. |
required |
rarity |
str
|
The rarity code of the card (see |
required |
Source code in fab/inventory.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|
add_item(item, count=1)
¶
Adds one or more copies of a card inventory item to this inventory.
If the inventory already contains the specified item, its count is
increased by the value specified (to set the count, use set_item()
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item |
InventoryItem
|
The card inventory item to add. |
required |
count |
int
|
The number of copies to add to the inventory. |
1
|
Source code in fab/inventory.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
count()
¶
Computes the total number of cards in this inventory.
Return
The total number of cards in the inventory.
Source code in fab/inventory.py
296 297 298 299 300 301 302 303 |
|
edition_counts()
¶
Returns the counts of each edition code contained in this card inventory.
Returns:
Type | Description |
---|---|
dict[str, int]
|
A |
Source code in fab/inventory.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
editions()
¶
Returns the set of edition codes contained in this card inventory.
Returns:
Type | Description |
---|---|
list[str]
|
A unique |
Source code in fab/inventory.py
320 321 322 323 324 325 326 327 328 329 330 |
|
foiling_counts()
¶
Returns the counts of each foiling code contained in this card inventory.
Returns:
Type | Description |
---|---|
dict[str, int]
|
A |
Source code in fab/inventory.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
|
foilings()
¶
Returns the set of foiling codes contained in this card inventory.
Returns:
Type | Description |
---|---|
list[str]
|
A unique |
Source code in fab/inventory.py
347 348 349 350 351 352 353 354 355 356 357 |
|
from_dict(data)
staticmethod
¶
Parses a new card inventory from the specified dict
representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
dict[str, int]
|
The |
required |
Returns:
Type | Description |
---|---|
CardInventory
|
A new |
Source code in fab/inventory.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
|
from_json(jsonstr)
staticmethod
¶
Parses a new card inventory from the specified JSON string representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
jsonstr |
str
|
The JSON string representation to parse. |
required |
Returns:
Type | Description |
---|---|
CardInventory
|
A new |
Source code in fab/inventory.py
375 376 377 378 379 380 381 382 383 384 385 386 |
|
identifier_counts()
¶
Returns the counts of each identifier contained in this card inventory.
Returns:
Type | Description |
---|---|
dict[str, int]
|
A |
Source code in fab/inventory.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
|
identifiers()
¶
Returns the set of identifiers contained in this card inventory.
Returns:
Type | Description |
---|---|
list[str]
|
A unique |
Source code in fab/inventory.py
403 404 405 406 407 408 409 410 411 412 413 |
|
load(file_path)
staticmethod
¶
Loads a card inventory from the specified .json
file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The |
required |
Returns:
Type | Description |
---|---|
CardInventory
|
The parsed card inventory object loaded from the specified file path. |
Source code in fab/inventory.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
|
lookup(edition=None, foiling=None, identifier=None, rarity=None, set=None)
¶
Returns a subset of the card inventory based on the specified search parameters.
This is akin to filtering the inventory. Any arguments with None
values are ignored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edition |
Optional[str]
|
The edition code of cards to include in the result. |
None
|
foiling |
Optional[str]
|
The foiling code of cards to include in the result. |
None
|
identifier |
Optional[str]
|
The identifier of cards to include in the result. |
None
|
rarity |
Optional[str]
|
The rarity of cards to include in the result. |
None
|
set |
Optional[str]
|
The card set code of cards to include in the result. |
None
|
Returns:
Type | Description |
---|---|
CardInventory
|
A subset of the inventory filtered by the specified arguments. |
Source code in fab/inventory.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
|
rarities()
¶
Returns the set of rarity codes contained in this card inventory.
Returns:
Type | Description |
---|---|
list[str]
|
A unique |
Source code in fab/inventory.py
466 467 468 469 470 471 472 473 474 475 476 |
|
rarity_counts()
¶
Returns the counts of each rarity code contained in this card inventory.
Returns:
Type | Description |
---|---|
dict[str, int]
|
A |
Source code in fab/inventory.py
478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
|
save(file_path)
¶
Saves the card inventory to the specified .json
file path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The |
required |
Source code in fab/inventory.py
493 494 495 496 497 498 499 500 501 502 503 504 |
|
set(identifier, rarity, foiling, count=1, edition='U')
¶
Sets the number of copies associated with a unique card.
This method builds a InventoryItem
object from the specified
parameters. To set a pre-built InventoryItem
object in the collection,
use set_item()
. To add to the current count associated with an item,
use add()
.
Note
Setting a card's count to 0
does not delete the item from the
inventory but rather simply sets the count to 0
. This is useful for
tracking when you used to own a card, or when plan to obtain a
copy of a particular card.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
count |
int
|
The number of copies to set the inventory count to. |
1
|
edition |
str
|
The edition code of the card (see |
'U'
|
foiling |
str
|
The foiling code of the card (see |
required |
identifier |
str
|
The identifier of the card. |
required |
rarity |
str
|
The rarity code of the card (see |
required |
Source code in fab/inventory.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
|
set_item(item, count=1)
¶
Sets the number of copies of a card inventory item in this inventory.
If the inventory already contains the specified item, its count is
increased by the value specified (to set the count, use set_item()
).
Note
Setting a card's count to 0
does not delete the item from the
inventory but rather simply sets the count to 0
. This is useful for
tracking when you used to own a card, or when plan to obtain a
copy of a particular card.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item |
InventoryItem
|
The card inventory item. |
required |
count |
int
|
The number of copies to set. |
1
|
Source code in fab/inventory.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 |
|
to_cardlist(catalog=None)
¶
Converts this unique card inventory into a list of generic representations of cards.
Note
To instantiate the card list this way, a card catalog (CardList
)
must be provided, defaulting to card.CARD_CATALOG
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
catalog |
Optional[CardList]
|
The card catalog to use as a reference, defaulting to |
None
|
Returns:
Type | Description |
---|---|
CardList
|
A |
Source code in fab/inventory.py
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
|
to_dict()
¶
Converts the inventory object into a raw dictionary of python primitives.
Returns:
Type | Description |
---|---|
dict[str, int]
|
A raw |
Source code in fab/inventory.py
593 594 595 596 597 598 599 600 601 602 603 604 |
|
to_json()
¶
Computes the JSON string representation of the inventory.
Returns:
Type | Description |
---|---|
str
|
The JSON string representation of the card inventory. |
Source code in fab/inventory.py
606 607 608 609 610 611 612 613 |
|