Skip to content

Commit

Permalink
List feats in the order that they're added
Browse files Browse the repository at this point in the history
Feats are collected in character.py first by race, then by background,
and finally by class. And within each of these, they're collected by
level. That yields a very nice order that lends itself for some
additional subheadings. In order to do so change "fts" to list instead
of set, to preserve order.
  • Loading branch information
PJBrs committed Jan 2, 2024
1 parent 7a7ea5e commit 42a2070
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions dungeonsheets/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def other_weapon_proficiencies_text(self):

@property
def features(self):
fts = set(self.custom_features)
fts = list(self.custom_features)
fighting_style_defined = False
set_of_fighting_styles = {
"Fighting Style (Archery)",
Expand All @@ -468,7 +468,8 @@ def features(self):
if not self.has_class:
return fts
for c in self.class_list:
fts |= set(c.features)
for item in list(c.features):
fts.append(item)
for feature in fts:
if (
fighting_style_defined
Expand All @@ -478,15 +479,17 @@ def features(self):
fts.remove(temp_feature)
break
if self.race is not None:
fts |= set(getattr(self.race, "features", ()))
for item in getattr(self.race, "features", ()):
fts.append(item)
# some races have level-based features (Ex: Aasimar)
if hasattr(self.race, "features_by_level"):
for lvl in range(1, self.level + 1):
fts |= set(self.race.features_by_level[lvl])
for item in list(self.race.features_by_level[lvl]):
fts.append(item)
if self.background is not None:
fts |= set(getattr(self.background, "features", ()))

return sorted(tuple(fts), key=(lambda x: x.name))
for item in getattr(self.background, "features", ()):
fts.append(item)
return fts

@property
def custom_features_text(self):
Expand Down

0 comments on commit 42a2070

Please sign in to comment.