From 1689d9365007c04c336a3b4d96dfcdfabe132fa5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 8 Sep 2017 00:23:59 -0400 Subject: [PATCH] Split Stats.all() into multiple functions Now we have three different functions for different groups. Also the get functions have a group argument to specify which one to search. --- statinfo.py | 43 +++++++++++++++++++++++++++++++++++++------ ui.py | 12 ++++-------- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/statinfo.py b/statinfo.py index 1f056ae..cb07543 100644 --- a/statinfo.py +++ b/statinfo.py @@ -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: diff --git a/ui.py b/ui.py index 978cb12..989ed82 100644 --- a/ui.py +++ b/ui.py @@ -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 @@ -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): @@ -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() } }