Hardcore nvidia graphics display drivers

pull/1/head
Jake Funke 2017-03-15 06:51:52 +00:00
parent 17248eed50
commit 0ca4683a1e
2 changed files with 29 additions and 20 deletions

View File

@ -10,6 +10,7 @@ import getpass
import threading import threading
import errno import errno
import uuid import uuid
import fcntl
from operator import itemgetter from operator import itemgetter
from menu_screen import * from menu_screen import *
@ -304,13 +305,12 @@ class DataManager(object):
this_user = getpass.getuser() this_user = getpass.getuser()
savefile_name = this_user + '_plant.dat' savefile_name = this_user + '_plant.dat'
savefile_path = os.path.join(botany_dir,savefile_name) savefile_path = os.path.join(botany_dir, savefile_name)
garden_file_path = os.path.join(game_dir,'garden_file.dat') garden_file_path = os.path.join(game_dir, 'garden_file.dat')
def __init__(self): def __init__(self):
self.this_user = getpass.getuser() self.this_user = getpass.getuser()
# check if instance is already running # check if instance is already running
self.lock_file()
# check for .botany dir in home # check for .botany dir in home
try: try:
os.makedirs(self.botany_dir) os.makedirs(self.botany_dir)
@ -319,19 +319,6 @@ class DataManager(object):
raise raise
self.savefile_name = self.this_user + '_plant.dat' 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): def check_plant(self):
# check for existing save file # check for existing save file
if os.path.isfile(self.savefile_path): if os.path.isfile(self.savefile_path):
@ -404,6 +391,9 @@ class DataManager(object):
def garden_update(self, this_plant): def garden_update(self, this_plant):
# garden is a dict of dicts # garden is a dict of dicts
# garden contains one entry for each plant id # 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) age_formatted = self.plant_age_convert(this_plant)
this_plant_id = this_plant.plant_id this_plant_id = this_plant.plant_id
plant_info = { plant_info = {
@ -421,7 +411,10 @@ class DataManager(object):
new_file_check = False new_file_check = False
# TODO: it would be smart to lock this file down somehow, write to # TODO: it would be smart to lock this file down somehow, write to
# it only through the software (to prevent tampering) # 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: else:
# create empty garden list # create empty garden list
this_garden = {} this_garden = {}
@ -483,4 +476,3 @@ if __name__ == '__main__':
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)
my_data.garden_update(my_plant) my_data.garden_update(my_plant)
my_data.clear_lock()

View File

@ -69,9 +69,9 @@ class CursedMenu(object):
# garden/leaderboard thing # garden/leaderboard thing
# 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)
try: try:
self.draw_default() self.draw_default()
self.screen.border(0)
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
@ -99,8 +99,19 @@ class CursedMenu(object):
self.__exit__() self.__exit__()
#traceback.print_exc() #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): def draw_default(self):
# draws default menu # draws default menu
# TODO: draw bee
clear_bar = " " * (int(self.maxx*2/3)) clear_bar = " " * (int(self.maxx*2/3))
self.screen.addstr(2,2, self.title, curses.A_STANDOUT) # Title for this menu 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 self.screen.addstr(4,2, self.subtitle, curses.A_BOLD) #Subtitle for this menu
@ -131,6 +142,7 @@ class CursedMenu(object):
else: else:
self.screen.addstr(5,13, clear_bar, curses.A_NORMAL) 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.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): def update_plant_live(self):
# updates plant data on menu screen, live! # updates plant data on menu screen, live!
@ -187,13 +199,18 @@ class CursedMenu(object):
def draw_garden(self): def draw_garden(self):
# draws neighborhood # draws neighborhood
# TODO: use age from start date to now, not ticks or static
clear_bar = " " * (self.maxx-2) + "\n" 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] control_keys = [curses.KEY_UP, curses.KEY_DOWN, curses.KEY_LEFT, curses.KEY_RIGHT]
# load data # load data
with open(self.garden_file_path, 'rb') as f: with open(self.garden_file_path, 'rb') as f:
this_garden = pickle.load(f) this_garden = pickle.load(f)
# format data # format data
if self.infotoggle != 2: 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) plant_table_formatted = self.format_garden_data(this_garden)
self.infotoggle = 2 self.infotoggle = 2
else: else:
@ -232,7 +249,7 @@ class CursedMenu(object):
"You think about all the seedlings who came before it.", "You think about all the seedlings who came before it.",
"You and your seedling make a great team.", "You and your seedling make a great team.",
"Your seedling grows slowly and quietly.", "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:[ 2:[
"The " + this_species + " makes you feel relaxed.", "The " + this_species + " makes you feel relaxed.",