mirror of
https://github.com/Threnklyn/dungeon-sheets.git
synced 2026-06-06 21:01:26 +02:00
Cleaned up the display of spell components.
Fixes https://github.com/canismarko/dungeon-sheets/issues/91
This commit is contained in:
@@ -47,19 +47,17 @@ class Spell:
|
|||||||
classes = ()
|
classes = ()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if len(self.components) == 0:
|
s = self.name
|
||||||
s = self.name
|
requirements = list(self.components)
|
||||||
else:
|
|
||||||
s = self.name + " ({:s}) ".format(",".join(self.components))
|
|
||||||
# Indicate if this is a ritual or a concentration
|
# Indicate if this is a ritual or a concentration
|
||||||
indicators = [
|
indicators = [
|
||||||
("R", self.ritual),
|
("R", self.ritual),
|
||||||
("C", self.concentration),
|
("C", self.concentration),
|
||||||
("$", self.special_material),
|
("$", self.special_material),
|
||||||
]
|
]
|
||||||
indicators = tuple(letter for letter, is_active in indicators if is_active)
|
requirements.extend([letter for letter, is_active in indicators if is_active])
|
||||||
if len(indicators):
|
if len(requirements):
|
||||||
s += f' ({", ".join(indicators)})'
|
s += f' ({"/".join(requirements)})'
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@@ -88,4 +86,4 @@ class Spell:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def special_material(self):
|
def special_material(self):
|
||||||
return "worth at least" in self.materials.lower()
|
return "worth" in self.materials.lower()
|
||||||
|
|||||||
+12
-3
@@ -41,8 +41,17 @@ class TestSpells(TestCase):
|
|||||||
self.assertEqual(str(spell), "My spell (R)")
|
self.assertEqual(str(spell), "My spell (R)")
|
||||||
# Try with a ritual and a concentration
|
# Try with a ritual and a concentration
|
||||||
spell.concentration = True
|
spell.concentration = True
|
||||||
self.assertEqual(str(spell), "My spell (R, C)")
|
self.assertEqual(str(spell), "My spell (R/C)")
|
||||||
# Try with ritual/concentration/verbal/somatic
|
# Try with ritual/concentration/verbal/somatic
|
||||||
# spell.
|
spell.components = ("V", "S")
|
||||||
# self.assertEqual(str(spell), "My spell (R, C)")
|
self.assertEqual(str(spell), "My spell (V/S/R/C)")
|
||||||
# # Try with material components with a cost
|
# # Try with material components with a cost
|
||||||
|
spell.components = ("V", "S", "M")
|
||||||
|
spell.materials = "A stone worth 50 GP"
|
||||||
|
self.assertEqual(str(spell), "My spell (V/S/M/R/C/$)")
|
||||||
|
|
||||||
|
def test_special_material(self):
|
||||||
|
spell = Spell()
|
||||||
|
# From revivify
|
||||||
|
spell.materials = "Diamonds worth 300 gp, which the spell consumes"
|
||||||
|
self.assertTrue(spell.special_material)
|
||||||
|
|||||||
Reference in New Issue
Block a user