File: config.py

package info (click to toggle)
lightyears 1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 1,324 kB
  • ctags: 454
  • sloc: python: 3,499; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,202 bytes parent folder | download | duplicates (2)
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
51
52
53
54
55
56
57
58
# 
# 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, primitives


CFG_VERSION = "1.4"

class Config:
    def __init__(self):
        self.version = CFG_VERSION
        (w, h, fs) = primitives.RESOLUTIONS[ 0 ]
        self.resolution = (w, h)
        self.fullscreen = False
        self.mute = True
        self.font_scale = fs
        self.seen_before = False

cfg = Config()

FILENAME = None

def Initialise(delete_file):
    global cfg, FILENAME

    home = extra.Get_Home()
    if ( home == None ):
        FILENAME = "config.dat"
    else:
        FILENAME = os.path.join(home, ".lightyears.cfg")

    if delete_file:
        # Don't load old configuration
        Save()
        return

    try:
        f = file(FILENAME, "rb")
        cfg2 = pickle.load(f)
        f.close()
        if cfg2.version == CFG_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