3 CONFIG
= 'game_config.xml'
6 WINDOW_SIZE
= (640, 480)
7 BACKGROUND_COLOR
= (1, 0, 0, 0)
8 GUI_THEME
= 'theme_two.zip'
9 WIDGETS_FILE
= 'widgets.xml'
20 from DerGUI
import GUISystem
24 from OpenGL
.GL
import *
26 from OpenGL
.GLU
import *
30 from xml
.dom
.minidom
import parse
, parseString
32 from experimental
import *
36 print "Engine.py class... more documentation to come"
40 def __init__(self
, config_file
=CONFIG
):
42 assert exists(config_file
)
43 dom
= parse(config_file
)
44 self
.config
= reduceDOM(dom
)
45 self
.config
= reduceConfig(self
.config
)
49 window_size
= WINDOW_SIZE
51 if self
.config
.has_key('window_size'):
53 window_size
= eval(self
.config
['window_size'])
55 print "Engine.__init__(): Error in eval() using default window size of", WINDOW_SIZE
57 video_flags
= OPENGL|DOUBLEBUF
58 self
.display
= pygame
.display
.set_mode(window_size
, video_flags
)
62 background_color
= BACKGROUND_COLOR
64 if self
.config
.has_key('background_color'):
66 background_color
= eval(self
.config
['background_color'])
68 print "Engine.__init__(): Error in eval(), using default background color of", BACKGROUND_COLOR
70 glShadeModel(GL_SMOOTH
)
71 glClearColor(background_color
[0],
76 glEnable(GL_DEPTH_TEST
)
77 glDepthFunc(GL_LEQUAL
)
78 glHint(GL_PERSPECTIVE_CORRECTION_HINT
, GL_NICEST
)
82 if self
.config
.has_key('window_title'):
83 self
.window_title
= self
.config
['window_title']
85 self
.window_title
= WINDOW_CAPTION
86 print "Engine.__init__(): No window title specified, using default of", WINDOW_CAPTION
88 pygame
.display
.set_caption(self
.window_title
)
90 # lamina and gui stuff
94 if self
.config
.has_key('gui_theme'):
95 gui_theme
= self
.config
['gui_theme']
97 print "Engine.__init__(): No gui theme specified, using default of", GUI_THEME
99 self
.lamina_screen
= lamina
.LaminaScreenSurface()
100 self
.gui_system
= GUISystem(WIDGETS_FILE
, gui_theme
)
109 if self
.config
.has_key('pack_dir'):
110 pack_dir
= self
.config
['pack_dir']
112 print "Engine.__init__(): No pack directory specified, using default of", PACK_DIR
114 for file in listdir(pack_dir
):
115 if is_zipfile(os
.path
.join(pack_dir
, file)):
116 self
.zipfiles
.append(ZipFile(os
.path
.join(pack_dir
, file)))
118 for item
in self
.zipfiles
[-1].namelist():
119 self
.filelist
[item
] = "self.zipfiles[" + str(len(self
.zipfiles
) - 1) + "].read(\"" + item
+ "\")"
128 def addFile(self
, filename
, parent
=''):
130 if self
.filelist
.has_key(filename
):
132 dom
= parseString(eval(self
.filelist
[filename
]))
135 parsed
= reduceDOM(dom
)
142 'object_instance': {},
146 for item
in parsed
[1][0]:
150 for defx
in item
[1][0]:
152 if defx
[0] == 'object':
153 obj
= reduceObjectDef(defx
)
154 results
[obj
['name']] = obj
156 if defx
[0] == 'menu':
157 menu
= reduceMenuDef(defx
)
158 results
[menu
[0]] = menu
160 if item
[0] == 'instance':
162 for defx
in item
[1][0]:
164 inst
= reduceInstance(defx
)
165 instances
.append(inst
)
167 # do instance stuff here
168 for item
in instances
:
171 results
['parent'] = parent
173 self
.files
[parent
]['children'].append(filename
)
180 if __name__
== '__main__': main()