From 870a211f4fe4690c33562f403ead149f37d360c9 Mon Sep 17 00:00:00 2001 From: Tymewalk Date: Wed, 6 Apr 2016 14:01:00 -0500 Subject: [PATCH 1/2] Use modulus when setting costume So we can have costume numbers like -1 and 9001 set a costume even if they don't exist. --- slither/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slither/__init__.py b/slither/__init__.py index c2f3860..c213607 100644 --- a/slither/__init__.py +++ b/slither/__init__.py @@ -74,9 +74,9 @@ def costumeNumber(self): @costumeNumber.setter def costumeNumber(self, val): - if val < len(self.costumes.keys()): # TODO: use mod to wrap around - self.costumeName = list(self.costumes.keys())[val] - self._costumeNumber = val + val = val % len(self.costumes.keys()) + self.costumeName = list(self.costumes.keys())[val] + self._costumeNumber = val @property def costumeName(self): From c2df67458b01dfef254ea9eb7aee3afb772e54d7 Mon Sep 17 00:00:00 2001 From: Tymewalk Date: Wed, 6 Apr 2016 14:08:12 -0500 Subject: [PATCH 2/2] Use direct length of dict instead of length of keys of dict That's confusing and asking for trouble. --- slither/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/slither/__init__.py b/slither/__init__.py index c213607..cbc20dc 100644 --- a/slither/__init__.py +++ b/slither/__init__.py @@ -63,7 +63,7 @@ def deleteCostumeByName(self, name): def deleteCostumeByNumber(self, number): '''Delete a costume by number.''' - if number < len(self.costumes.keys()): + if number < len(self.costumes): costumeName = self.costumes.keys()[number] self.deleteCostumeByName(costumeName) # TODO: Fix this stupid "get name from number" thing @@ -74,7 +74,7 @@ def costumeNumber(self): @costumeNumber.setter def costumeNumber(self, val): - val = val % len(self.costumes.keys()) + val = val % len(self.costumes) self.costumeName = list(self.costumes.keys())[val] self._costumeNumber = val @@ -165,6 +165,7 @@ def play(self): pass raise e return sound +# Why is this here? slitherSound = Sound() def setup(caption=sys.argv[0]):