mirror of
https://github.com/Threnklyn/dungeon-sheets.git
synced 2026-06-07 13:15:53 +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 = ()
|
||||
|
||||
def __str__(self):
|
||||
if len(self.components) == 0:
|
||||
s = self.name
|
||||
else:
|
||||
s = self.name + " ({:s}) ".format(",".join(self.components))
|
||||
requirements = list(self.components)
|
||||
# Indicate if this is a ritual or a concentration
|
||||
indicators = [
|
||||
("R", self.ritual),
|
||||
("C", self.concentration),
|
||||
("$", self.special_material),
|
||||
]
|
||||
indicators = tuple(letter for letter, is_active in indicators if is_active)
|
||||
if len(indicators):
|
||||
s += f' ({", ".join(indicators)})'
|
||||
requirements.extend([letter for letter, is_active in indicators if is_active])
|
||||
if len(requirements):
|
||||
s += f' ({"/".join(requirements)})'
|
||||
return s
|
||||
|
||||
def __repr__(self):
|
||||
@@ -88,4 +86,4 @@ class Spell:
|
||||
|
||||
@property
|
||||
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)")
|
||||
# Try with a ritual and a concentration
|
||||
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
|
||||
# spell.
|
||||
# self.assertEqual(str(spell), "My spell (R, C)")
|
||||
spell.components = ("V", "S")
|
||||
self.assertEqual(str(spell), "My spell (V/S/R/C)")
|
||||
# # 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