changeset 585:c2de5aafe788

- added debug flag to loaders to enable/disable annoying print spam on maploading
author chewie@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 08 Aug 2010 15:56:19 +0000
parents a2dde16ddc62
children dc19d9e38880
files engine/python/fife/extensions/loaders.py engine/python/fife/extensions/serializers/xmlmap.py
diffstat 2 files changed, 60 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/engine/python/fife/extensions/loaders.py	Sun Aug 08 11:49:09 2010 +0000
+++ b/engine/python/fife/extensions/loaders.py	Sun Aug 08 15:56:19 2010 +0000
@@ -32,7 +32,7 @@
 
 fileExtensions = ('xml',)
 
-def loadMapFile(path, engine, callback=None):
+def loadMapFile(path, engine, callback=None, debug=True):
 	""" load map file and get (an optional) callback if major stuff is done:
 	- map creation
 	- parsed imports
@@ -40,21 +40,38 @@
 	- parsed cameras
 	the callback will send both a string and a float (which shows
 	the overall process), callback(string, float)
-		
-	@return	map	: map object
+	
+	@type	engine:		object
+	@param	engine: 	FIFE engine instance
+	@type	callback:	function
+	@param	callback:	callback for maploading progress
+	@type	debug:		bool
+	@param	debug:		flag to activate / deactivate print statements
+	
+	@type	map:	object
+	@return	map:	FIFE map object
 	"""
-	map_loader = XMLMapLoader(engine, callback)
+	map_loader = XMLMapLoader(engine, callback, debug)
 	map = map_loader.loadResource(fife.ResourceLocation(path))
-	print "--- Loading map took: ", map_loader.time_to_load, " seconds."
+	if debug: print "--- Loading map took: ", map_loader.time_to_load, " seconds."
 	return map
 
 
-def loadImportFile(path, engine):
+def loadImportFile(path, engine, debug=False):
+	""" uses XMLObjectLoader to load import files from path
+	
+	@type	path:	string
+	@param	path:	path to import file
+	@type	engine:	object
+	@param	engine:	FIFE engine instance
+	@type	debug:	bool
+	@param	debug:	flag to activate / deactivate print statements
+	"""
 	object_loader = XMLObjectLoader(engine.getImagePool(), engine.getAnimationPool(), engine.getModel(), engine.getVFS())
 	res = None
 	try:
 		res = object_loader.loadResource(fife.ResourceLocation(path))
-		print 'imported object file ' + path
+		if debug: print 'imported object file ' + path
 	except WrongFileType:
 		pass
 #		print 'ignored non-object file ' + path
@@ -63,12 +80,30 @@
 #		print 'ignored already loaded file ' + path
 	return res
 
-def loadImportDir(path, engine):
+def loadImportDir(path, engine, debug=False):
+	""" helper function to call loadImportFile on a directory
+	
+	@type	path:	string
+	@param	path:	path to import directory
+	@type	engine:	object
+	@param	engine:	FIFE engine instance
+	@type	debug:	bool
+	@param	debug:	flag to activate / deactivate print statements
+	"""
 	for file in filter(lambda f: f.split('.')[-1] == 'xml', engine.getVFS().listFiles(path)):
-		loadImportFile('/'.join([path, file]), engine)
+		loadImportFile('/'.join([path, file]), engine, debug)
+
+def loadImportDirRec(path, engine, debug=False):
+	""" helper function to call loadImportFile recursive on a directory
 
-def loadImportDirRec(path, engine):
-	loadImportDir(path, engine)
+	@type	path:	string
+	@param	path:	path to import directory
+	@type	engine:	object
+	@param	engine:	FIFE engine instance
+	@type	debug:	bool
+	@param	debug:	flag to activate / deactivate print statements	
+	"""
+	loadImportDir(path, engine, debug)
 
 	for dir in filter(lambda d: not d.startswith('.'), engine.getVFS().listDirectories(path)):
-		loadImportDirRec('/'.join([path, dir]), engine)
+		loadImportDirRec('/'.join([path, dir]), engine, debug)
--- a/engine/python/fife/extensions/serializers/xmlmap.py	Sun Aug 08 11:49:09 2010 +0000
+++ b/engine/python/fife/extensions/serializers/xmlmap.py	Sun Aug 08 15:56:19 2010 +0000
@@ -34,21 +34,26 @@
 FORMAT = '1.0'
 
 class XMLMapLoader(fife.ResourceLoader):
-	def __init__(self, engine, callback):
+	def __init__(self, engine, callback, debug):
 		""" The XMLMapLoader parses the xml map using several section. 
 		Each section fires a callback (if given) which can e. g. be
 		used to show a progress bar.
 		
 		The callback sends two values, a string and a float (which shows
 		the overall process): callback(string, float)
-			
-		@param	engine	:	a pointer to fife.engine
+
+		@type	engine:		object
+		@param	engine:		a pointer to fife.engine
+		@type	callback:	function
 		@param	callback:	a callback with two arguments, optional
+		@type	debug:		bool
+		@param	debug:		flag to activate / deactivate print statements
 		"""
 		fife.ResourceLoader.__init__(self)
 		self.thisown = 0
 		
 		self.callback = callback
+		self.debug = debug
 
 		self.engine = engine
 		self.vfs = self.engine.getVFS()
@@ -124,19 +129,19 @@
 
 			# Don't parse duplicate imports
 			if (dir,file) in parsedImports:
-				print "Duplicate import:" ,(dir,file)
+				if self.debug: print "Duplicate import:" ,(dir,file)
 				continue
 			parsedImports[(dir,file)] = 1
 
 			if file and dir:
-				loaders.loadImportFile('/'.join(dir, file), self.engine)
+				loaders.loadImportFile('/'.join(dir, file), self.engine, self.debug)
 			elif file:
-				loaders.loadImportFile(file, self.engine)
+				loaders.loadImportFile(file, self.engine, self.debug)
 			elif dir:
-				loaders.loadImportDirRec(dir, self.engine)
+				loaders.loadImportDirRec(dir, self.engine, self.debug)
 				map.importDirs.append(dir)
 			else:
-				print 'Empty import statement?'
+				if self.debug: print 'Empty import statement?'
 				
 			if self.callback:
 				i += 1