diff --git a/botany.py b/botany.py index ae7ae41..16d9537 100644 --- a/botany.py +++ b/botany.py @@ -171,15 +171,12 @@ class Plant(object): legendary_range = round((2/3)*(CONST_RARITY_MAX-common_range-uncommon_range-rare_range)) # godly_range = round((2/3)*(CONST_RARITY_MAX-common_range-uncommon_range-rare_range-legendary_range)) - # print common_range, uncommon_range, rare_range, legendary_range, godly_range - common_max = common_range uncommon_max = common_max + uncommon_range rare_max = uncommon_max + rare_range legendary_max = rare_max + legendary_range godly_max = CONST_RARITY_MAX - # print common_max, uncommon_max, rare_max, legendary_max, godly_max if 0 <= rare_seed <= common_max: rarity = 0 elif common_max < rare_seed <= uncommon_max: @@ -240,7 +237,6 @@ class Plant(object): mutation = random.randint(0,len(self.mutation_dict)-1) if self.mutation == 0: self.mutation = mutation - #print "mutation!" return True else: return False @@ -258,7 +254,6 @@ class Plant(object): output += self.stage_dict[self.stage] + " " if self.stage >= 2: output += self.species_dict[self.species] + " " - # print output return output.strip() def start_life(self): @@ -282,7 +277,6 @@ class Plant(object): if self.stage < len(self.stage_dict)-1: if self.ticks >= life_stages[self.stage]: self.growth() - #print self.parse_plant() if self.mutate_check(): 1==1 if self.water_check(): @@ -465,7 +459,7 @@ if __name__ == '__main__': my_data.data_write_json(my_plant) my_plant.start_life() my_data.start_threads(my_plant) - botany_menu = CursedMenu(my_plant,my_data.garden_file_path) +botany_menu = CursedMenu(my_plant,my_data.garden_file_path) botany_menu.show(["water","look","garden","instructions"], title=' botany ', subtitle='options') my_data.save_plant(my_plant) my_data.data_write_json(my_plant) diff --git a/menu_screen.py b/menu_screen.py index fe69058..1e6b34a 100644 --- a/menu_screen.py +++ b/menu_screen.py @@ -29,7 +29,6 @@ class CursedMenu(object): screen_thread = threading.Thread(target=self.update_plant_live, args=()) screen_thread.daemon = True screen_thread.start() - # TODO: tweaking this to try to get rid of garble bug self.screen.clear() def show(self, options, title, subtitle): @@ -131,14 +130,13 @@ class CursedMenu(object): self.gardenmenutoggle = not self.gardenmenutoggle else: plant_table_formatted = "" - for line in this_garden: - plant_table_formatted += clear_bar + for plant in this_garden: + if not this_garden[plant]["dead"]: + plant_table_formatted += clear_bar self.gardenmenutoggle = not self.gardenmenutoggle for y, line in enumerate(plant_table_formatted.splitlines(), 2): self.screen.addstr(y+12, 2, line) - # TODO: this needs to be updated so that it only draws if the window - # is big enough.. or try catch it self.screen.refresh() def draw(self): @@ -148,22 +146,23 @@ class CursedMenu(object): # TODO: display refresh is hacky. Could be more precise self.screen.refresh() self.screen.border(0) + # TODO: separate screen for garden menu, interactive # if self.gardenmenutoggle: # self.draw_garden() # else: # self.draw_default() - self.draw_default() try: + self.draw_default() self.screen.refresh() except Exception as exception: # Makes sure data is saved in event of a crash due to window resizing + self.screen.addstr(0,0,"Enlarge terminal!") self.__exit__() traceback.print_exc() def update_plant_live(self): # Updates plant data on menu screen, live! # Will eventually use this to display ascii art... - # self.set_options(self.options) while not self.exit: self.plant_string = self.plant.parse_plant() self.plant_ticks = str(self.plant.ticks) @@ -219,6 +218,7 @@ available in the readme :) for y, line in enumerate(instructions_txt.splitlines(), 2): self.screen.addstr(self.maxy-12+y,self.maxx-47, line) self.screen.refresh() + def handle_request(self, request): '''This is where you do things with the request''' if request == None: return @@ -229,9 +229,21 @@ available in the readme :) if request == "water": self.plant.water() if request == "instructions": - self.draw_instructions() + try: + self.draw_instructions() + except Exception as exception: + # Makes sure data is saved in event of a crash due to window resizing + self.screen.addstr(0,0,"Enlarge terminal!") + self.__exit__() + traceback.print_exc() if request == "garden": - self.draw_garden() + try: + self.draw_garden() + except Exception as exception: + self.screen.addstr(0,0,"Enlarge terminal!") + self.__exit__() + traceback.print_exc() + def __exit__(self): self.exit = True curses.curs_set(2)