comparison gamelib/scenes/machine.py @ 759:386475464202 pyntnclick

Inspect game state for Thing.set_interact() instead of setting it manually everywhere.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 26 Jan 2013 13:00:31 +0200
parents c910c8b51d55
children a8510f4e2ea1 43b49f1de828
comparison
equal deleted inserted replaced
758:f4853f817a7a 759:386475464202
98 98
99 INITIAL_DATA = { 99 INITIAL_DATA = {
100 'contents': set(), 100 'contents': set(),
101 } 101 }
102 102
103 def update_contents(self): 103 def select_interact(self):
104 """Update the interact after a contents change."""
105 contents = self.get_data('contents') 104 contents = self.get_data('contents')
106 if not contents: 105 if not contents:
107 self.set_interact("empty") 106 return "empty"
108 elif len(contents) == 1: 107 elif len(contents) == 1:
109 if "can" in contents: 108 if "can" in contents:
110 self.set_interact("can") 109 return "can"
111 elif "tube" in contents: 110 elif "tube" in contents:
112 self.set_interact("tube") 111 return "tube"
113 else: 112 else:
114 self.set_interact("can_and_tube") 113 return "can_and_tube"
115 114
116 def interact_without(self): 115 def interact_without(self):
117 return Result("You really don't want to put your hand in there.") 116 return Result("You really don't want to put your hand in there.")
118 117
119 def interact_with_empty_can(self, item): 118 def interact_with_empty_can(self, item):
120 contents = self.get_data('contents') 119 contents = self.get_data('contents')
121 if "can" in contents: 120 if "can" in contents:
122 return Result("There is already a can in the welder.") 121 return Result("There is already a can in the welder.")
123 self.game.remove_inventory_item(item.name) 122 self.game.remove_inventory_item(item.name)
124 contents.add("can") 123 contents.add("can")
125 self.update_contents() 124 self.set_interact()
126 return Result("You carefully place the can in the laser welder.") 125 return Result("You carefully place the can in the laser welder.")
127 126
128 def interact_with_tube_fragment(self, item): 127 def interact_with_tube_fragment(self, item):
129 contents = self.get_data('contents') 128 contents = self.get_data('contents')
130 if "tube" in contents: 129 if "tube" in contents:
131 return Result("There is already a tube fragment in the welder.") 130 return Result("There is already a tube fragment in the welder.")
132 self.game.remove_inventory_item(item.name) 131 self.game.remove_inventory_item(item.name)
133 contents.add("tube") 132 contents.add("tube")
134 self.update_contents() 133 self.set_interact()
135 return Result("You carefully place the tube fragments in the" 134 return Result("You carefully place the tube fragments in the"
136 " laser welder.") 135 " laser welder.")
137 136
138 def get_description(self): 137 def get_description(self):
139 contents = self.get_data('contents') 138 contents = self.get_data('contents')
177 elif "tube" in contents: 176 elif "tube" in contents:
178 return Result("The laser welder needs something to weld the" 177 return Result("The laser welder needs something to weld the"
179 " tube fragments to.") 178 " tube fragments to.")
180 else: 179 else:
181 welder_slot.set_data("contents", set()) 180 welder_slot.set_data("contents", set())
182 welder_slot.update_contents() 181 welder_slot.set_interact()
183 if self.game.is_in_inventory("cryo_pipes_one"): 182 if self.game.is_in_inventory("cryo_pipes_one"):
184 self.game.replace_inventory_item("cryo_pipes_one", 183 self.game.replace_inventory_item("cryo_pipes_one",
185 "cryo_pipes_two") 184 "cryo_pipes_two")
186 return Result("With high-precision spitzensparken, you weld" 185 return Result("With high-precision spitzensparken, you weld"
187 " together a second pipe. You bundle the two" 186 " together a second pipe. You bundle the two"