comparison orpg/mapper/background.py @ 227:81d0bfd5e800 alpha

Traipse Alpha 'OpenRPG' {100612-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Preparing to close updates) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order Fixes: Fix to InterParse that was causing an Infernal Loop with Namespace Internal Fix to XML data, removed old Minidom and switched to Element Tree Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread Fix to metaservers.xml file not being created
author sirebral
date Sat, 12 Jun 2010 03:50:37 -0500
parents 06f10429eedc
children
comparison
equal deleted inserted replaced
182:4b2884f29a72 227:81d0bfd5e800
19 # 19 #
20 # File: background.py 20 # File: background.py
21 # Author: Chris Davis 21 # Author: Chris Davis
22 # Maintainer: 22 # Maintainer:
23 # Version: 23 # Version:
24 # $Id: background.py,v 1.29 2007/03/09 14:11:55 digitalxero Exp $ 24 # $Id: background.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
25 # 25 #
26 # Description: This file contains some of the basic definitions for the chat 26 # Description: This file contains some of the basic definitions for the chat
27 # utilities in the orpg project. 27 # utilities in the orpg project.
28 # 28 #
29 __version__ = "$Id: background.py,v 1.29 2007/03/09 14:11:55 digitalxero Exp $" 29 __version__ = "$Id: background.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
30 30
31 from base import * 31 from base import *
32 import thread, urllib, os.path, time, mimetypes 32 import thread, urllib, os.path, time, mimetypes
33 33
34 from orpg.orpgCore import component 34 from orpg.orpgCore import component
35 from orpg.tools.orpg_log import logger 35 from orpg.tools.orpg_log import logger
36 from orpg.tools.orpg_settings import settings 36 from orpg.tools.orpg_settings import settings
37 from xml.etree.ElementTree import fromstring
37 38
38 ##----------------------------- 39 ##-----------------------------
39 ## background layer 40 ## background layer
40 ##----------------------------- 41 ##-----------------------------
41 42
208 self.isUpdated = False 209 self.isUpdated = False
209 return xml_str 210 return xml_str
210 else: return '' 211 else: return ''
211 212
212 def layerTakeDOM(self, xml_dom): 213 def layerTakeDOM(self, xml_dom):
213 type = BG_COLOR 214 bg_type = xml_dom.get("type")
214 color = xml_dom.getAttribute("color") 215 urlpath = xml_dom.get('path')
215 logger.debug("color=" + color) 216 color = xml_dom.get("color")
216 path = urllib.unquote(xml_dom.getAttribute("path")) 217
217 logger.debug("path=" + path) 218 if urlpath != None:
218 # Begin ted's map changes 219 path = urllib.unquote(xml_dom.get("path"))
219 if xml_dom.hasAttribute("color"): 220 logger.debug("path=" + path)
220 r,g,b = self.r_h.rgb_tuple(xml_dom.getAttribute("color")) 221
222 if color != None:
223 logger.debug("color=" + color)
224 r,g,b = self.r_h.rgb_tuple(color)
221 self.set_color(cmpColour(r,g,b)) 225 self.set_color(cmpColour(r,g,b))
222 # End ted's map changes 226
223 if xml_dom.hasAttribute("type"): 227 if bg_type != None:
224 type = int(xml_dom.getAttribute("type")) 228 logger.debug("type=" + bg_type)
225 logger.debug("type=" + str(type)) 229 bg_type = int(xml_dom.get("type"))
226 if type == BG_TEXTURE: 230 if bg_type == BG_TEXTURE:
227 if path != "": self.set_texture(path) 231 if path != "": self.set_texture(path)
228 elif type == BG_IMAGE: 232 elif bg_type == BG_IMAGE:
229 if path != "": self.set_image(path, 1) 233 if path != "": self.set_image(path, 1)
230 elif type == BG_NONE: self.clear() 234 elif bg_type == BG_NONE: self.clear()
231 if xml_dom.hasAttribute('local') and xml_dom.getAttribute('local') == 'True' and os.path.exists(urllib.unquote(xml_dom.getAttribute('localPath'))): 235 if xml_dom.get('local') == 'True' and os.path.exists(urllib.unquote(xml_dom.get('localPath'))):
232 self.localPath = urllib.unquote(xml_dom.getAttribute('localPath')) 236 self.localPath = urllib.unquote(xml_dom.get('localPath'))
233 self.local = True 237 self.local = True
234 self.localTime = int(xml_dom.getAttribute('localTime')) 238 self.localTime = int(xml_dom.get('localTime'))
235 if self.localTime-time.time() <= 144000: 239 if self.localTime-time.time() <= 144000:
236 file = open(self.localPath, "rb") 240 file = open(self.localPath, "rb")
237 imgdata = file.read() 241 imgdata = file.read()
238 file.close() 242 file.close()
239 filename = os.path.split(self.localPath) 243 filename = os.path.split(self.localPath)
242 thread.start_new_thread(self.upload, (postdata, self.localPath, type)) 246 thread.start_new_thread(self.upload, (postdata, self.localPath, type))
243 247
244 def upload(self, postdata, filename, type): 248 def upload(self, postdata, filename, type):
245 self.lock.acquire() 249 self.lock.acquire()
246 if type == 'Image' or type == 'Texture': 250 if type == 'Image' or type == 'Texture':
247 url = component.get('settings').get_setting('ImageServerBaseURL') 251 url = settings.get_setting('ImageServerBaseURL')
248 file = urllib.urlopen(url, postdata) 252 file = urllib.urlopen(url, postdata)
249 recvdata = file.read() 253 recvdata = file.read()
250 file.close() 254 file.close()
251 try: 255 try:
252 xml_dom = minidom.parseString(recvdata)._get_documentElement() 256 xml_dom = fromstring(recvdata)
253 if xml_dom.nodeName == 'path': 257 if xml_dom.tag == 'path':
254 path = xml_dom.getAttribute('url') 258 path = xml_dom.get('url')
255 path = urllib.unquote(path) 259 path = urllib.unquote(path)
256 if type == 'Image': self.set_image(path, 1) 260 if type == 'Image': self.set_image(path, 1)
257 else: self.set_texture(path) 261 else: self.set_texture(path)
258 self.localPath = filename 262 self.localPath = filename
259 self.local = True 263 self.local = True
260 self.localTime = time.time() 264 self.localTime = time.time()
261 else: 265 else: print xml_dom.get('msg')
262 print xml_dom.getAttribute('msg')
263 except Exception, e: 266 except Exception, e:
264 print e 267 print e
265 print recvdata 268 print recvdata
266 self.lock.release() 269 self.lock.release()