Skip to content

Commit

Permalink
Split Stats.all() into multiple functions
Browse files Browse the repository at this point in the history
Now we have three different functions for different groups.  Also the
get functions have a group argument to specify which one to search.
  • Loading branch information
imayhaveborkedit committed Sep 8, 2017
1 parent 0d30aeb commit 1689d93
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
43 changes: 37 additions & 6 deletions statinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,28 +304,59 @@ class Stats:


@classmethod
def get(cls, name):
def get(cls, name, *, group=None):
if group is None:
group = cls.all_stats

try:
return next(filter(lambda s: s.name == name, (*cls.all(), cls.rerolls)))
return next(filter(lambda s: s.name == name, group()))
except StopIteration:
pass

@classmethod
def get_name(cls, buffname):
def get_name(cls, buffname, *, group=None):
if group is None:
group = cls.all_stats

try:
return next(filter(lambda s: s.buffername == buffname, (*cls.all(), cls.rerolls)))
return next(filter(lambda s: s.buffername == buffname, group()))
except StopIteration:
pass


@classmethod
def all_stats(cls):
"""
Return a tuple of all stats with memory locations.
"""
return (
cls.intelligence, cls.will, cls.strength, cls.endurance,
cls.dexterity, cls.agility, cls.speed, cls.eyesight,
cls.hearing, cls.smelltaste, cls.touch, cls.height,
cls.weight, cls.physique, cls.rerolls)

# Split into all_stats and all_real_stats (without rerolls)
@classmethod
def all(cls):
def all_real_stats(cls):
"""
Return a tuple of all stats, not including rerolls.
"""
return (
cls.intelligence, cls.will, cls.strength, cls.endurance,
cls.dexterity, cls.agility, cls.speed, cls.eyesight,
cls.hearing, cls.smelltaste, cls.touch, cls.height,
cls.weight, cls.physique)

@classmethod
def all_normal_stats(cls):
"""
Return a tuple of all stats that can have values of 1 to 18.
"""
return (
cls.intelligence, cls.will, cls.strength, cls.endurance,
cls.dexterity, cls.agility, cls.speed, cls.eyesight,
cls.hearing, cls.smelltaste, cls.touch)


@classmethod
def format(cls, stat, value):
try:
Expand Down
12 changes: 4 additions & 8 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _is_main_thread():

class BufferState:
order = list(reversed(
[stat.buffername for stat in statinfo.Stats.all()] + [DEFAULT_BUFFER]))
[stat.buffername for stat in statinfo.Stats.all_real_stats()] + [DEFAULT_BUFFER]))

def __init__(self, position=0):
self.position = position
Expand All @@ -76,7 +76,7 @@ def current(self):

@property
def current_stat(self):
b = statinfo.Stats.get_name(self.current)
b = statinfo.Stats.get_name(self.current, group=statinfo.Stats.all_real_stats)
return b.name if b else None

def up(self):
Expand Down Expand Up @@ -241,17 +241,13 @@ def _gen_buffers(self):
initial_document=Document(),
is_multiline=True),

'REROLLS_STAT_BUFFER': Buffer(
initial_document=make_stat_doc('Rerolls', 0),
is_multiline=False),

'MSG_BUFFER': Buffer(
initial_document=Document(),
is_multiline=True),

**{
stat.buffername: Buffer(initial_document=make_stat_doc(stat.name))
for stat in statinfo.Stats.all()
stat.buffername: Buffer(initial_document=make_stat_doc(stat.name))
for stat in statinfo.Stats.all_stats()
}
}

Expand Down

0 comments on commit 1689d93

Please sign in to comment.