Created
July 2, 2018 04:01
-
-
Save DNA/1584d8854b9a1d115bf5a35ccbe129d7 to your computer and use it in GitHub Desktop.
Stats class for Renpy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Stat(object): | |
class Delta(object): | |
def __init__(self, parent): | |
self.parent = parent | |
self.value = parent.value | |
def __repr__(self): | |
return '<Stat.Delta value={}>'.format(self.calculate()) | |
def __str__(self): | |
return str(self.calculate()) | |
def calculate(self): | |
delta = self.parent.value - self.value | |
if self.parent.dir == 'down': delta *= -1 | |
return delta | |
def is_positive(self): return self.calculate > 0 | |
def is_negative(self): return self.calculate < 0 | |
def is_zero(self): return self.calculate == 0 | |
def reset(self): self.value = self.parent.value | |
def __init__(self, name, value, max, min): | |
self.name = name | |
self.value = value | |
self.max = max | |
self.min = min | |
self.dir = dir | |
self.delta = self.Delta(self) | |
def __repr__(self): | |
return '<Stat "{}" value={} delta={}>'.format(self.name, self.value, self.delta) | |
def __str__(self): | |
return str(self.value) | |
def __add__(self, value): | |
self.value += value | |
return self.value | |
def __sub__(self, value): | |
self.value -= value | |
return self.value | |
def __eq__(self, other): return self.value == other | |
def __ne__(self, other): return self.value != other | |
def __lt__(self, other): return self.value < other | |
def __le__(self, other): return self.value <= other | |
def __gt__(self, other): return self.value > other | |
def __ge__(self, other): return self.value >= other | |
strength = Stat('Strength', 20, 0, 100) | |
print repr(strength) | |
print repr(strength.delta) | |
print strength + 6 | |
print strength.delta | |
print repr(strength) | |
print strength - 8 | |
print strength.delta | |
print repr(strength) | |
strength.delta.reset() | |
print repr(strength) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment