diff --git a/botany.py b/botany.py index 8a4ebad..de03ffc 100644 --- a/botany.py +++ b/botany.py @@ -10,6 +10,7 @@ import getpass import threading import errno import uuid +import fcntl from operator import itemgetter from menu_screen import * @@ -304,13 +305,12 @@ class DataManager(object): this_user = getpass.getuser() savefile_name = this_user + '_plant.dat' - savefile_path = os.path.join(botany_dir,savefile_name) - garden_file_path = os.path.join(game_dir,'garden_file.dat') + savefile_path = os.path.join(botany_dir, savefile_name) + garden_file_path = os.path.join(game_dir, 'garden_file.dat') def __init__(self): self.this_user = getpass.getuser() # check if instance is already running - self.lock_file() # check for .botany dir in home try: os.makedirs(self.botany_dir) @@ -319,19 +319,6 @@ class DataManager(object): raise self.savefile_name = self.this_user + '_plant.dat' - def lock_file(self): - # Only allow one instance of game - pid = str(os.getpid()) - this_filename = "instance.lock" - self.pid_file_path = os.path.join(self.botany_dir,this_filename) - if os.path.isfile(self.pid_file_path): - print "botany already running, exiting. (pid %s)" % pid - sys.exit() - file(self.pid_file_path, 'w').write(pid) - - def clear_lock(self): - os.unlink(self.pid_file_path) - def check_plant(self): # check for existing save file if os.path.isfile(self.savefile_path): @@ -404,6 +391,9 @@ class DataManager(object): def garden_update(self, this_plant): # garden is a dict of dicts # garden contains one entry for each plant id + # TODO: this should calculate age based on time since start, not just + # when they saved it + # IE someone logged out, still gaining age, just not gaining ticks age_formatted = self.plant_age_convert(this_plant) this_plant_id = this_plant.plant_id plant_info = { @@ -421,7 +411,10 @@ class DataManager(object): new_file_check = False # TODO: it would be smart to lock this file down somehow, write to # it only through the software (to prevent tampering) - os.chmod(self.garden_file_path, 0666) + # TODO: this is not the right way to do this, other users who run + # it can't chmod that file + # TODO: json file also needs to be writeable by all + # os.chmod(self.garden_file_path, 0666) else: # create empty garden list this_garden = {} @@ -483,4 +476,3 @@ if __name__ == '__main__': my_data.save_plant(my_plant) my_data.data_write_json(my_plant) my_data.garden_update(my_plant) - my_data.clear_lock() diff --git a/menu_screen.py b/menu_screen.py index d2eb02d..1760558 100644 --- a/menu_screen.py +++ b/menu_screen.py @@ -69,9 +69,9 @@ class CursedMenu(object): # garden/leaderboard thing # TODO: display refresh is hacky. Could be more precise self.screen.refresh() - self.screen.border(0) try: self.draw_default() + self.screen.border(0) self.screen.refresh() except Exception as exception: # Makes sure data is saved in event of a crash due to window resizing @@ -99,8 +99,19 @@ class CursedMenu(object): self.__exit__() #traceback.print_exc() + def ascii_render(self, filename, ypos, xpos): + this_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),"art") + this_filename = os.path.join(this_dir,filename) + this_file = open(this_filename,"r") + this_string = this_file.readlines() + this_file.close() + for y, line in enumerate(this_string, 2): + self.screen.addstr(ypos+y,xpos,line, curses.A_NORMAL) + # self.screen.refresh() + def draw_default(self): # draws default menu + # TODO: draw bee clear_bar = " " * (int(self.maxx*2/3)) self.screen.addstr(2,2, self.title, curses.A_STANDOUT) # Title for this menu self.screen.addstr(4,2, self.subtitle, curses.A_BOLD) #Subtitle for this menu @@ -131,6 +142,7 @@ class CursedMenu(object): else: self.screen.addstr(5,13, clear_bar, curses.A_NORMAL) self.screen.addstr(5,13, " - you can't water a dead plant :(", curses.A_NORMAL) + self.ascii_render("bee.txt",-1,self.maxx-27) def update_plant_live(self): # updates plant data on menu screen, live! @@ -187,13 +199,18 @@ class CursedMenu(object): def draw_garden(self): # draws neighborhood + # TODO: use age from start date to now, not ticks or static clear_bar = " " * (self.maxx-2) + "\n" + clear_block = clear_bar * 5 control_keys = [curses.KEY_UP, curses.KEY_DOWN, curses.KEY_LEFT, curses.KEY_RIGHT] # load data with open(self.garden_file_path, 'rb') as f: this_garden = pickle.load(f) # format data if self.infotoggle != 2: + for y, line in enumerate(clear_block.splitlines(), 2): + self.screen.addstr(y+12, 2, line) + self.screen.refresh() plant_table_formatted = self.format_garden_data(this_garden) self.infotoggle = 2 else: @@ -232,7 +249,7 @@ class CursedMenu(object): "You think about all the seedlings who came before it.", "You and your seedling make a great team.", "Your seedling grows slowly and quietly.", - "You briefly meditate on the paths your life could take.", + "You meditate on the paths your plant's life could take.", ], 2:[ "The " + this_species + " makes you feel relaxed.",