4
# This class encapsulates a statistic in DSE. Instances of
5
# this class have two properties, .value and .maxvalue. The
6
# .value property is clamped to ensure that it is always in
7
# the range 0 - .maxvalue, inclusive.
12
#name: string intended to describe the stat in game (e.g. "Intelligence")
13
#startvalue: value the stat starts out with
14
#maxvalue: highest value this stat can reach
15
def __init__(self, name, startvalue, maxvalue):
18
self.__value=startvalue
19
self.__maxvalue=maxvalue
25
return str(self.__value)
27
#sets value and ensures it is within boundaries
28
#0-maxvalue, inclusive.
29
def set(self, new_value):
30
self.__value = new_value
31
self.__value = min(self.__value, self.__maxvalue)
32
self.__value = max(self.__value, 0)
34
#sets maxvalue and ensures value is within the new boundaries
35
def set_max(self, new_value):
36
self.__maxvalue = new_value
37
self.set(self.__value)
39
# Set up properties so the user can directly access value
40
# and maxvalue, and set or set_max is called when they are
43
value = property(fget = lambda self : self.__value,
46
maxvalue = property(fget = lambda self : self.__maxvalue,
49
#allow comparisons to integer
50
def __cmp__(self, other):
51
#correctly raises exception if we try to compare to anything not castable to integer
53
return cmp(self.__value, cmp_to)
55
# Renders this Stat into the stats window.
58
ui.text(self.name, minwidth=150)
59
ui.bar(600, 20, self.__maxvalue, self.__value, ypos=0.5, yanchor='center')
66
# This is the window that the stats are kept in, if any.