1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#
# 20,000 Light Years Into Space
# This game is licensed under GPL v2, and copyright (C) Jack Whitham 2006-07.
#
import pickle, startup, os, extra
class Config:
def __init__(self):
# Default settings:
self.version = startup.Get_Game_Version()
self.resolution = (1024, 768)
self.fullscreen = True
self.font_scale = 4
self.seen_before = False
cfg = Config()
FILENAME = None
def Initialise():
global cfg, FILENAME
home = extra.Get_Home()
if ( home == None ):
FILENAME = "config.dat"
else:
FILENAME = os.path.join(home, ".lightyears.cfg")
try:
f = file(FILENAME, "rb")
cfg2 = pickle.load(f)
f.close()
if ( cfg2.version == startup.Get_Game_Version() ):
# Configuration is valid, we can use it.
cfg = cfg2
except Exception, x:
pass
def Save():
global cfg, FILENAME
try:
f = file(FILENAME, "wb")
pickle.dump(cfg, f)
f.close()
except Exception, x:
pass
|