Add display error handling (messy)

pull/1/head
Jake Funke 2017-03-13 17:42:13 +00:00
parent b68c4362ec
commit 138a981c3f
2 changed files with 22 additions and 16 deletions

View File

@ -171,15 +171,12 @@ class Plant(object):
legendary_range = round((2/3)*(CONST_RARITY_MAX-common_range-uncommon_range-rare_range)) 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)) # 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 common_max = common_range
uncommon_max = common_max + uncommon_range uncommon_max = common_max + uncommon_range
rare_max = uncommon_max + rare_range rare_max = uncommon_max + rare_range
legendary_max = rare_max + legendary_range legendary_max = rare_max + legendary_range
godly_max = CONST_RARITY_MAX godly_max = CONST_RARITY_MAX
# print common_max, uncommon_max, rare_max, legendary_max, godly_max
if 0 <= rare_seed <= common_max: if 0 <= rare_seed <= common_max:
rarity = 0 rarity = 0
elif common_max < rare_seed <= uncommon_max: elif common_max < rare_seed <= uncommon_max:
@ -240,7 +237,6 @@ class Plant(object):
mutation = random.randint(0,len(self.mutation_dict)-1) mutation = random.randint(0,len(self.mutation_dict)-1)
if self.mutation == 0: if self.mutation == 0:
self.mutation = mutation self.mutation = mutation
#print "mutation!"
return True return True
else: else:
return False return False
@ -258,7 +254,6 @@ class Plant(object):
output += self.stage_dict[self.stage] + " " output += self.stage_dict[self.stage] + " "
if self.stage >= 2: if self.stage >= 2:
output += self.species_dict[self.species] + " " output += self.species_dict[self.species] + " "
# print output
return output.strip() return output.strip()
def start_life(self): def start_life(self):
@ -282,7 +277,6 @@ class Plant(object):
if self.stage < len(self.stage_dict)-1: if self.stage < len(self.stage_dict)-1:
if self.ticks >= life_stages[self.stage]: if self.ticks >= life_stages[self.stage]:
self.growth() self.growth()
#print self.parse_plant()
if self.mutate_check(): if self.mutate_check():
1==1 1==1
if self.water_check(): if self.water_check():
@ -465,7 +459,7 @@ if __name__ == '__main__':
my_data.data_write_json(my_plant) my_data.data_write_json(my_plant)
my_plant.start_life() my_plant.start_life()
my_data.start_threads(my_plant) 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') botany_menu.show(["water","look","garden","instructions"], title=' botany ', subtitle='options')
my_data.save_plant(my_plant) my_data.save_plant(my_plant)
my_data.data_write_json(my_plant) my_data.data_write_json(my_plant)

View File

@ -29,7 +29,6 @@ class CursedMenu(object):
screen_thread = threading.Thread(target=self.update_plant_live, args=()) screen_thread = threading.Thread(target=self.update_plant_live, args=())
screen_thread.daemon = True screen_thread.daemon = True
screen_thread.start() screen_thread.start()
# TODO: tweaking this to try to get rid of garble bug
self.screen.clear() self.screen.clear()
def show(self, options, title, subtitle): def show(self, options, title, subtitle):
@ -131,14 +130,13 @@ class CursedMenu(object):
self.gardenmenutoggle = not self.gardenmenutoggle self.gardenmenutoggle = not self.gardenmenutoggle
else: else:
plant_table_formatted = "" plant_table_formatted = ""
for line in this_garden: for plant in this_garden:
plant_table_formatted += clear_bar if not this_garden[plant]["dead"]:
plant_table_formatted += clear_bar
self.gardenmenutoggle = not self.gardenmenutoggle self.gardenmenutoggle = not self.gardenmenutoggle
for y, line in enumerate(plant_table_formatted.splitlines(), 2): for y, line in enumerate(plant_table_formatted.splitlines(), 2):
self.screen.addstr(y+12, 2, line) 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() self.screen.refresh()
def draw(self): def draw(self):
@ -148,22 +146,23 @@ class CursedMenu(object):
# TODO: display refresh is hacky. Could be more precise # TODO: display refresh is hacky. Could be more precise
self.screen.refresh() self.screen.refresh()
self.screen.border(0) self.screen.border(0)
# TODO: separate screen for garden menu, interactive
# if self.gardenmenutoggle: # if self.gardenmenutoggle:
# self.draw_garden() # self.draw_garden()
# else: # else:
# self.draw_default() # self.draw_default()
self.draw_default()
try: try:
self.draw_default()
self.screen.refresh() self.screen.refresh()
except Exception as exception: except Exception as exception:
# Makes sure data is saved in event of a crash due to window resizing # Makes sure data is saved in event of a crash due to window resizing
self.screen.addstr(0,0,"Enlarge terminal!")
self.__exit__() self.__exit__()
traceback.print_exc() traceback.print_exc()
def update_plant_live(self): def update_plant_live(self):
# Updates plant data on menu screen, live! # Updates plant data on menu screen, live!
# Will eventually use this to display ascii art... # Will eventually use this to display ascii art...
# self.set_options(self.options)
while not self.exit: while not self.exit:
self.plant_string = self.plant.parse_plant() self.plant_string = self.plant.parse_plant()
self.plant_ticks = str(self.plant.ticks) self.plant_ticks = str(self.plant.ticks)
@ -219,6 +218,7 @@ available in the readme :)
for y, line in enumerate(instructions_txt.splitlines(), 2): for y, line in enumerate(instructions_txt.splitlines(), 2):
self.screen.addstr(self.maxy-12+y,self.maxx-47, line) self.screen.addstr(self.maxy-12+y,self.maxx-47, line)
self.screen.refresh() self.screen.refresh()
def handle_request(self, request): def handle_request(self, request):
'''This is where you do things with the request''' '''This is where you do things with the request'''
if request == None: return if request == None: return
@ -229,9 +229,21 @@ available in the readme :)
if request == "water": if request == "water":
self.plant.water() self.plant.water()
if request == "instructions": 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": 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): def __exit__(self):
self.exit = True self.exit = True
curses.curs_set(2) curses.curs_set(2)