card Module

Generic Card Class.

class librarian.card.Card(code=None, name=None, loaddict=None)

Bases: object

The card stores general information about the card.
  • code: the unique identifier for this card.
  • name: name of this card to be displayed.
  • abilities: dict of phase ids containing a list of action descriptors.
  • attributes: list of special details this card has.
  • info: dict of any information you would like.

Card can be saved to, and loaded from, a string. Call str() on a Card instance or .save_string() on the instance. This will return a string that when evaluated using eval() can be unpacked into the Card constructor re-create that card. For example. original = Card(1, 'cool card') savestring = str(card) loaded = Card(*eval(savestring)) assert loaded == original

add_ability(phase, ability)

Add the given ability to this Card under the given phase. Returns the length of the abilities for the given phase after the addition.

add_attribute(attribute)

Add the given attribute to this Card. Returns the length of attributes after addition.

get_abilities(phase)

Returns an ability list for the given phase ID.

get_info(key)

Return a value in the info for this card with the given key.

has_attribute(attribute)

Return true if this card contains the given attribute.

is_valid()

Returns True if code is not 0 and self.name is not ‘’.

load(carddict)

Takes a carddict as produced by Card.save and sets this card instances information to the previously saved cards information.

save()

Converts the Card as is into a dictionary capable of reconstructing the card with Card.load or serialized to a string for storage.

set_info(key, value, append=True)

Set any special info you wish to the given key. Each info is stored in a list and will be appended to rather then overriden unless append is False.

Project Versions

Previous topic

deck Module

This Page