diff --git a/botany.py b/botany.py index b489a20..cddb66a 100755 --- a/botany.py +++ b/botany.py @@ -125,8 +125,8 @@ class Plant(object): def __init__(self, this_filename, generation=1): # Constructor self.plant_id = str(uuid.uuid4()) - self.life_stages = (3600*24, (3600*24)*3, (3600*24)*10, (3600*24)*20, (3600*24)*30) - # self.life_stages = (5, 10, 15, 20, 25) + # self.life_stages = (3600*24, (3600*24)*3, (3600*24)*10, (3600*24)*20, (3600*24)*30) + self.life_stages = (2, 4, 6, 8, 10) self.stage = 0 self.mutation = 0 self.species = random.randint(0,len(self.species_list)-1) @@ -198,9 +198,29 @@ class Plant(object): self.dead = True return self.dead + def guest_check(self): + user_dir = os.path.expanduser("~") + botany_dir = os.path.join(user_dir,'.botany') + visitor_filepath = os.path.join(botany_dir,'visitors.json') + guest_data = {'latest_timestamp': 0, 'visitors': []} + visitors = [] + if os.path.isfile(visitor_filepath): + with open(visitor_filepath, 'rw') as visitor_file: + data = json.load(visitor_file) + for element in data: + if element['user'] not in guest_data['visitors']: + guest_data['visitors'].append(element['user']) + if element['timestamp'] > guest_data['latest_timestamp']: + guest_data['latest_timestamp'] = element['timestamp'] + os.remove(visitor_filepath) + return guest_data + def water_check(self): - # if plant has been watered in 24h then it keeps growing - # time_delta_watered is difference from now to last watered + guest_data = self.guest_check() + if guest_data['visitors']: + if guest_data['latest_timestamp'] > self.watered_timestamp: + self.watered_timestamp = guest_data['latest_timestamp'] + self.time_delta_watered = int(time.time()) - self.watered_timestamp if self.time_delta_watered <= (24 * 3600): return True @@ -298,6 +318,9 @@ class DataManager(object): savefile_name = this_user + '_plant.dat' savefile_path = os.path.join(botany_dir, savefile_name) + #set this.savefile_path to guest_garden path + + garden_db_path = os.path.join(game_dir, 'sqlite/garden_db.sqlite') garden_json_path = os.path.join(game_dir, 'garden_file.json') harvest_file_path = os.path.join(botany_dir, 'harvest_file.dat') diff --git a/menu_screen.py b/menu_screen.py index ea3ddd5..2ce6a55 100644 --- a/menu_screen.py +++ b/menu_screen.py @@ -40,7 +40,7 @@ class CursedMenu(object): screen_thread.daemon = True screen_thread.start() self.screen.clear() - self.show(["water","look","garden","instructions"], title=' botany ', subtitle='options') + self.show(["water","look","garden","visit", "instructions"], title=' botany ', subtitle='options') def define_colors(self): # set curses color pairs manually @@ -128,6 +128,7 @@ class CursedMenu(object): def draw_plant_ascii(self, this_plant): ypos = 1 xpos = int((self.maxx-37)/2 + 25) + # TODO: pull this from botany class plant_art_list = [ 'poppy', 'cactus', @@ -184,12 +185,12 @@ class CursedMenu(object): self.screen.addstr(5+index ,4, clear_bar, curses.A_NORMAL) self.screen.addstr(5+index ,4, "%d - %s" % (index+1, self.options[index]), textstyle) - self.screen.addstr(11, 2, clear_bar, curses.A_NORMAL) self.screen.addstr(12, 2, clear_bar, curses.A_NORMAL) - self.screen.addstr(11, 2, "plant: ", curses.A_DIM) - self.screen.addstr(11, 9, self.plant_string, curses.A_NORMAL) - self.screen.addstr(12, 2, "score: ", curses.A_DIM) - self.screen.addstr(12, 9, self.plant_ticks, curses.A_NORMAL) + self.screen.addstr(13, 2, clear_bar, curses.A_NORMAL) + self.screen.addstr(12, 2, "plant: ", curses.A_DIM) + self.screen.addstr(12, 9, self.plant_string, curses.A_NORMAL) + self.screen.addstr(13, 2, "score: ", curses.A_DIM) + self.screen.addstr(13, 9, self.plant_ticks, curses.A_NORMAL) # display fancy water gauge if not self.plant.dead: @@ -516,6 +517,33 @@ class CursedMenu(object): pass self.clear_info_pane() + def visit_handler(self): + self.clear_info_pane() + self.draw_info_text("whose plant would you like to visit?") + self.screen.addstr(15, 2, '~') + guest_garden = "" + user_input = 0 + while user_input != 10: + user_input = self.screen.getch() + if user_input == 127: + if len(guest_garden) > 0: + guest_garden = guest_garden[:-1] + self.screen.addstr(15, 3, " " * (self.maxx-2) ) + if user_input in range(256): + if chr(user_input).isalnum(): + guest_garden += chr(user_input) + self.screen.addstr(15, 3, str(guest_garden)) + self.screen.refresh() + # test if user exists and has botany directory and file + guest_path = "/home/{}/.botany/{}_plant.dat".format(guest_garden, guest_garden) + if os.path.isfile(guest_path): + self.screen.addstr(16, 2, "...you watered ~" + str(guest_garden) + "'s plant...") + else: + self.screen.addstr(16, 2, "i can't seem to find directions to {}...".format(guest_garden)) + self.screen.getch() + self.clear_info_pane() + + def handle_request(self, request): # Menu options call functions here if request == None: return @@ -535,6 +563,15 @@ class CursedMenu(object): except Exception as exception: self.screen.refresh() # traceback.print_exc() + if request == "visit": + try: + self.visit_handler() + except Exception as exception: + print exception; + traceback.print_exc() + + # self.screen.refresh() + if request == "garden": try: self.draw_garden()