+ '''On Rudi's advice, I'll try to code some screen control into pure Python classes
+ This method enables/disables security bar, and sets max value depending on brothel upgrades
+ Index 0 = Show/No show of bar, index 1 = max value of bar
+ '''
What I meant to convey with my advise is that we should package GUI code up in classes and functions, so we don't overwrite global variables with variables that look "local", when in fact they are in the global namespace. Putting GUI code in game logic classes (anything else than GUI code) is quite the opposite of what I want
With that being said, lets look at the complete method:
+ def gui_security_bar(self):
+ '''On Rudi's advice, I'll try to code some screen control into pure Python classes
+ This method enables/disables security bar, and sets max value depending on brothel upgrades
+ Index 0 = Show/No show of bar, index 1 = max value of bar
+ '''
+ result = []
+
+ if len([girl for girl in self.get_girls() if girl.action == 'Guard']) > 0:
+ result.append(True)
+ else: result.append(False)
+
+ if self.upgrades['mainhall']['2']['active']:
+ result.append(100)
+ elif self.upgrades['mainhall']['1']['active']:
+ result.append(50)
+ else: result.append(20)
+
+ return result
Basically, this method answers two questions:
1) Is there a guard?
2) What's the maximum value for security at the bar?
So this method actually describes its instance and should therefore be part of the class. I would not consider that GUI code
Here's another, IMHO clearer, way to answer the two questions:
def is_guarded(self):
'''Returns True if there is at least one guard here.
'''
guards = [girl for girl in self.get_girls() if girl.action == 'Guard']
return bool(guards)
def get_bar_security_max(self):
'''Returns the maximum value for bar security (20 - 100).
'''
if self.upgrades['mainhall']['2']['active']:
maxsec = 100
elif self.upgrades['mainhall']['1']['active']:
maxsec = 50
else:
maxsec = 20
return maxsec
UPDATE: After reading Xelas post in the General discussion, I realize that "bar" probably refers to a GUI element. Well, my bad. It does not change anything important.