changeset 48:955cd24d7a05

Cleaned up main menu code
author Josef "Jeff" Sipek <jeffpc@josefsipek.net>
date Fri, 01 Jun 2007 02:47:31 -0400
parents d2efdc4ff196
children 43a1c4c6955c
files atcgame/config.py atcgame/mainmenu.py atcgame/maps.py atcgame/plane.py atcgame/plane_specs.py atcgame/utils.py
diffstat 6 files changed, 30 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/atcgame/config.py	Fri Jun 01 02:32:48 2007 -0400
+++ b/atcgame/config.py	Fri Jun 01 02:47:31 2007 -0400
@@ -1,3 +1,5 @@
+import os
+
 # type of labels used to display plane info
 #
 # values:
@@ -6,8 +8,10 @@
 
 plane_label	= 1
 
-# relative location of the plane specs directory
-plane_spec_dir	= "data/planes"
+datadir		= ""
 
-# relative location of the maps directory
-maps_dir	= "data/maps"
+def plane_spec_dir():
+	return os.path.join(datadir, "planes")
+
+def maps_dir():
+	return os.path.join(datadir, "maps")
--- a/atcgame/mainmenu.py	Fri Jun 01 02:32:48 2007 -0400
+++ b/atcgame/mainmenu.py	Fri Jun 01 02:47:31 2007 -0400
@@ -22,22 +22,19 @@
 	import pygame
 	
 	import config
-	
+	import utils
+
 	import colors
-	import utils
-	import plane
-	import message
-	
-	import single
 except ImportError, err:
 	print "Couldn't load module %s" % (err)
 	sys.exit()
 
 size = width, height = 1024, 768
 
-def main(datadir):
+def main(datadir_arg):
 	""" Main fn to run the main thread """
-	
+	config.datadir = datadir_arg
+
 	# Init
 	pygame.init()
 	screen = pygame.display.set_mode(size)
@@ -55,7 +52,7 @@
 	background = pygame.Surface(screen.get_size()).convert()
 	background.fill(colors.black)
 	
-	(splash_image, splash_rect) = utils.load_png(datadir+'/image/splash.png')
+	(splash_image, splash_rect) = utils.load_png('image/splash.png')
 	background.blit(splash_image, (0, 0))
 
 	#blit!
@@ -81,7 +78,7 @@
 		
 		screen.blit(background, (0, 0))
 		
-		(menu_img, menu_rect) = utils.load_png(datadir+'/image/menu_' + menustr[optsel & 3] + '.png')
+		(menu_img, menu_rect) = utils.load_png('image/menu_' + menustr[optsel & 3] + '.png')
 		screen.blit(menu_img, ((width - 334)/2.0, (height - 225)/2.0))
 		
 		pygame.display.flip()
@@ -89,6 +86,7 @@
 		if (optsel & 0x10):
 			optsel = optsel & 3
 			if (optsel == 0): # single player
+				import single
 				single.startgame(screen)
 			if (optsel == 1): # multi player
 				pass # FIXME: implement
--- a/atcgame/maps.py	Fri Jun 01 02:32:48 2007 -0400
+++ b/atcgame/maps.py	Fri Jun 01 02:47:31 2007 -0400
@@ -79,27 +79,27 @@
 	
 MAPS	= []
 
-maps_dir = os.listdir(config.maps_dir)
+maps_dir = os.listdir(config.maps_dir())
 
 for map_dir in maps_dir:
-	files = os.listdir(config.maps_dir + "/" + map_dir)
+	files = os.listdir(config.maps_dir() + "/" + map_dir)
 	
 	if (files.count("map.info") == 0):
-		print "Missing " + config.maps_dir + "/" + map_dir + "/map.info"
+		print "Missing " + config.maps_dir() + "/" + map_dir + "/map.info"
 		sys.exit(1)
 	
 	if (files.count("map.png") == 0):
-		print "Missing " + config.maps_dir + "/" + map_dir + "/map.png"
+		print "Missing " + config.maps_dir() + "/" + map_dir + "/map.png"
 		sys.exit(1)
 	
 	if (files.count("navaid.info") == 0):
-		print "Missing " + config.maps_dir + "/" + map_dir + "/navaid.info"
+		print "Missing " + config.maps_dir() + "/" + map_dir + "/navaid.info"
 		sys.exit(1)
 	
-	map_info = get_map_info(config.maps_dir + "/" + map_dir + "/map.info")
-	get_navaids(config.maps_dir + "/" + map_dir + "/navaid.info", map_info)
+	map_info = get_map_info(config.maps_dir() + "/" + map_dir + "/map.info")
+	get_navaids(config.maps_dir() + "/" + map_dir + "/navaid.info", map_info)
 	
-	map_info.image = config.maps_dir + "/" + map_dir + "/map.png"
+	map_info.image = "maps/" + map_dir + "/map.png"
 	
 	MAPS.append(map_info)
 	print "Parsed and added '" + map_dir + "' map (" + str(map_info.ninfo.__len__()) + " navaids)"
--- a/atcgame/plane.py	Fri Jun 01 02:32:48 2007 -0400
+++ b/atcgame/plane.py	Fri Jun 01 02:47:31 2007 -0400
@@ -58,7 +58,7 @@
 		self.area = screen.get_rect()
 		
 		# plane image
-		(self.image, self.rect) = utils.load_png('data/image/plane.png')
+		(self.image, self.rect) = utils.load_png('image/plane.png')
 		
 		# call sign
 		self.callsign	= callsign
--- a/atcgame/plane_specs.py	Fri Jun 01 02:32:48 2007 -0400
+++ b/atcgame/plane_specs.py	Fri Jun 01 02:47:31 2007 -0400
@@ -20,7 +20,7 @@
 # all measurements in meters/sec or meters
 plane_SPECS	= []
 
-plane_dir = os.listdir(config.plane_spec_dir)
+plane_dir = os.listdir(config.plane_spec_dir())
 
 for f in plane_dir:
 	plane = {"fullname": str(None),
@@ -31,7 +31,7 @@
 		 "climb_normal": 0.0,
 		 "max_altitude": 0.0}
 	
-	fd = open(config.plane_spec_dir + "/" + f, 'r')
+	fd = open(config.plane_spec_dir() + "/" + f, 'r')
 	s = fd.read()
 	fd.close()
 	
--- a/atcgame/utils.py	Fri Jun 01 02:32:48 2007 -0400
+++ b/atcgame/utils.py	Fri Jun 01 02:47:31 2007 -0400
@@ -17,9 +17,11 @@
 import os
 from math import *
 
+import config
+
 def load_png(name):
 	""" Load image and return image object"""
-	fullname = os.path.join('', name)
+	fullname = os.path.join(config.datadir, name)
 	try:
 		image = pygame.image.load(fullname)
 		if image.get_alpha() is None: