Mercurial > traipse_dev
comparison orpg/mapper/background.py @ 139:8e07c1a2c69b alpha
Traipse Alpha 'OpenRPG' {091123-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 (Cleaning up for Beta)
Added Bookmarks
Fix to Remote Admin Commands
Minor fix to text based Server
Fix to Pretty Print, from Core
Fix to Splitter Nodes not being created
Fix to massive amounts of images loading, from Core
Added 'boot' command to remote admin
Added confirmation window for sent nodes
Minor changes to allow for portability to an OpenSUSE linux OS
Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG
Zoom Mouse plugin added
Images added to Plugin UI
Switching to Element Tree
Map efficiency, from FlexiRPG
Added Status Bar to Update Manager
default_manifest.xml renamed to default_upmana.xml
Cleaner clode for saved repositories
New TrueDebug Class in orpg_log (See documentation for usage)
Mercurial's hgweb folder is ported to upmana
Pretty important update that can help remove thousands of dead children from your gametree.
Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check
your gametree and look for dead children!!
New Gametree Recursion method, mapping, and context sensitivity. !Infinite Loops return error instead of freezing the
software!
New Syntax added for custom PC sheets
Tip of the Day added, from Core and community
Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from
ruining the fix.
author | sirebral |
---|---|
date | Mon, 23 Nov 2009 03:22:50 -0600 |
parents | 54446a995007 |
children | 06f10429eedc |
comparison
equal
deleted
inserted
replaced
138:1ed2feab0db9 | 139:8e07c1a2c69b |
---|---|
37 | 37 |
38 from orpg.orpgCore import component | 38 from orpg.orpgCore import component |
39 from orpg.tools.orpg_log import logger | 39 from orpg.tools.orpg_log import logger |
40 from orpg.tools.decorators import debugging | 40 from orpg.tools.decorators import debugging |
41 from orpg.tools.orpg_settings import settings | 41 from orpg.tools.orpg_settings import settings |
42 | |
43 from xml.etree.ElementTree import ElementTree, Element, tostring, fromstring, parse | |
44 | 42 |
45 ##----------------------------- | 43 ##----------------------------- |
46 ## background layer | 44 ## background layer |
47 ##----------------------------- | 45 ##----------------------------- |
48 | 46 |
100 def set_texture(self, path): | 98 def set_texture(self, path): |
101 self.isUpdated = True | 99 self.isUpdated = True |
102 self.type = BG_TEXTURE | 100 self.type = BG_TEXTURE |
103 if self.img_path != path: | 101 if self.img_path != path: |
104 try: | 102 try: |
105 self.bg_bmp = ImageHandler.load(path, "texture", 0) | 103 self.bg_bmp = ImageHandler.load(path, "texture", 0).ConvertToBitmap() |
106 if self.bg_bmp == None: | 104 if self.bg_bmp == None: |
107 logger.general("Invalid image type!") | 105 logger.general("Invalid image type!") |
108 raise Exception, "Invalid image type!" | 106 raise Exception, "Invalid image type!" |
109 except: self.error_loading_image(path) | 107 except: self.error_loading_image(path) |
110 self.img_path = path | 108 self.img_path = path |
112 | 110 |
113 def set_image(self, path, scale): | 111 def set_image(self, path, scale): |
114 self.isUpdated = True | 112 self.isUpdated = True |
115 self.type = BG_IMAGE | 113 self.type = BG_IMAGE |
116 if self.img_path != path: | 114 if self.img_path != path: |
117 self.bg_bmp = ImageHandler.load(path, "background", 0) | 115 self.bg_bmp = ImageHandler.load(path, "background", 0).ConvertToBitmap() |
118 try: | 116 try: |
119 if self.bg_bmp == None: | 117 if self.bg_bmp == None: |
120 logger.general("Invalid image type!") | 118 logger.general("Invalid image type!") |
121 raise Exception, "Invalid image type!" | 119 raise Exception, "Invalid image type!" |
122 except: self.error_loading_image(path) | 120 except: self.error_loading_image(path) |
134 | 132 |
135 def layerDraw(self, dc, scale, topleft, size): | 133 def layerDraw(self, dc, scale, topleft, size): |
136 if self.bg_bmp == None or not self.bg_bmp.Ok() or ((self.type != BG_TEXTURE) and (self.type != BG_IMAGE)): | 134 if self.bg_bmp == None or not self.bg_bmp.Ok() or ((self.type != BG_TEXTURE) and (self.type != BG_IMAGE)): |
137 return False | 135 return False |
138 dc2 = wx.MemoryDC() | 136 dc2 = wx.MemoryDC() |
139 | |
140 ### Temporary ### | |
141 try: self.bg_bmp = self.bg_bmp.ConvertToBitmap() | |
142 except: pass | |
143 ################# | |
144 | |
145 dc2.SelectObject(self.bg_bmp) | 137 dc2.SelectObject(self.bg_bmp) |
146 topLeft = [int(topleft[0]/scale), int(topleft[1]/scale)] | 138 topLeft = [int(topleft[0]/scale), int(topleft[1]/scale)] |
147 topRight = [int((topleft[0]+size[0]+1)/scale)+1, int((topleft[1]+size[1]+1)/scale)+1] | 139 topRight = [int((topleft[0]+size[0]+1)/scale)+1, int((topleft[1]+size[1]+1)/scale)+1] |
148 if (topRight[0] > self.canvas.size[0]): topRight[0] = self.canvas.size[0] | 140 if (topRight[0] > self.canvas.size[0]): topRight[0] = self.canvas.size[0] |
149 if (topRight[1] > self.canvas.size[1]): topRight[1] = self.canvas.size[1] | 141 if (topRight[1] > self.canvas.size[1]): topRight[1] = self.canvas.size[1] |
212 del dc2 | 204 del dc2 |
213 return True | 205 return True |
214 | 206 |
215 | 207 |
216 def layerToXML(self, action="update"): | 208 def layerToXML(self, action="update"): |
217 xml = Element('bg') | 209 xml_str = "<bg" |
218 if self.bg_color != None: | 210 if self.bg_color != None: |
219 (red,green,blue) = self.bg_color.Get() | 211 (red,green,blue) = self.bg_color.Get() |
220 hexcolor = self.r_h.hexstring(red, green, blue) | 212 hexcolor = self.r_h.hexstring(red, green, blue) |
221 xml.set('color', hexcolor) | 213 xml_str += ' color="' + hexcolor + '"' |
222 if self.img_path != None: xml.set('path', urllib.quote(self.img_path).replace('%3A', ':')) | 214 if self.img_path != None: xml_str += ' path="' + urllib.quote(self.img_path).replace('%3A', ':') + '"' |
223 if self.type != None: xml.set('type', str(self.type)) | 215 if self.type != None: xml_str += ' type="' + str(self.type) + '"' |
224 if self.local and self.img_path != None: | 216 if self.local and self.img_path != None: |
225 xml.set('local', 'True') | 217 xml_str += ' local="True"' |
226 xml.set('localPath', urllib.quote(self.localPath).replace('%3A', ':')) | 218 xml_str += ' localPath="' + urllib.quote(self.localPath).replace('%3A', ':') + '"' |
227 xml.set('localTime', str(self.localTime)) | 219 xml_str += ' localTime="' + str(self.localTime) + '"' |
220 xml_str += "/>" | |
221 logger.debug(xml_str) | |
228 if (action == "update" and self.isUpdated) or action == "new": | 222 if (action == "update" and self.isUpdated) or action == "new": |
229 self.isUpdated = False | 223 self.isUpdated = False |
230 return tostring(xml) | 224 return xml_str |
231 else: return '' | 225 else: return '' |
232 | 226 |
233 | 227 |
234 def layerTakeDOM(self, xml_dom): | 228 def layerTakeDOM(self, xml_dom): |
235 type = BG_COLOR | 229 type = BG_COLOR |
236 color = xml_dom.get("color") | 230 color = xml_dom.getAttribute("color") |
231 logger.debug("color=" + color) | |
232 path = urllib.unquote(xml_dom.getAttribute("path")) | |
233 logger.debug("path=" + path) | |
237 # Begin ted's map changes | 234 # Begin ted's map changes |
238 if xml_dom.get("color"): | 235 if xml_dom.hasAttribute("color"): |
239 r,g,b = self.r_h.rgb_tuple(xml_dom.get("color")) | 236 r,g,b = self.r_h.rgb_tuple(xml_dom.getAttribute("color")) |
240 self.set_color(cmpColour(r,g,b)) | 237 self.set_color(cmpColour(r,g,b)) |
241 # End ted's map changes | 238 # End ted's map changes |
242 if xml_dom.get("type"): | 239 if xml_dom.hasAttribute("type"): |
243 type = int(xml_dom.get("type")) | 240 type = int(xml_dom.getAttribute("type")) |
244 logger.debug("type=" + str(type)) | 241 logger.debug("type=" + str(type)) |
245 if type == BG_TEXTURE: | 242 if type == BG_TEXTURE: |
246 if xml_dom.get('path') != "": self.set_texture(xml_dom.get('path')) | 243 if path != "": self.set_texture(path) |
247 elif type == BG_IMAGE: | 244 elif type == BG_IMAGE: |
248 if xml_dom.get('path') != "": self.set_image(xml_dom.get('path'), 1) | 245 if path != "": self.set_image(path, 1) |
249 elif type == BG_NONE: self.clear() | 246 elif type == BG_NONE: self.clear() |
250 if xml_dom.get('local') and xml_dom.get('local') == 'True' and os.path.exists(urllib.unquote(xml_dom.get('localPath'))): | 247 if xml_dom.hasAttribute('local') and xml_dom.getAttribute('local') == 'True' and os.path.exists(urllib.unquote(xml_dom.getAttribute('localPath'))): |
251 self.localPath = urllib.unquote(xml_dom.get('localPath')) | 248 self.localPath = urllib.unquote(xml_dom.getAttribute('localPath')) |
252 self.local = True | 249 self.local = True |
253 self.localTime = int(xml_dom.get('localTime')) | 250 self.localTime = int(xml_dom.getAttribute('localTime')) |
254 if self.localTime-time.time() <= 144000: | 251 if self.localTime-time.time() <= 144000: |
255 file = open(self.localPath, "rb") | 252 file = open(self.localPath, "rb") |
256 imgdata = file.read() | 253 imgdata = file.read() |
257 file.close() | 254 file.close() |
258 filename = os.path.split(self.localPath) | 255 filename = os.path.split(self.localPath) |
259 (imgtype,j) = mimetypes.guess_type(filename[1]) | 256 (imgtype,j) = mimetypes.guess_type(filename[1]) |
260 postdata = urllib.urlencode({'filename':filename[1], | 257 postdata = urllib.urlencode({'filename':filename[1], 'imgdata':imgdata, 'imgtype':imgtype}) |
261 'imgdata':imgdata, | |
262 'imgtype':imgtype}) | |
263 thread.start_new_thread(self.upload, (postdata, self.localPath, type)) | 258 thread.start_new_thread(self.upload, (postdata, self.localPath, type)) |
264 | 259 |
265 | 260 |
266 def upload(self, postdata, filename, type): | 261 def upload(self, postdata, filename, type): |
267 self.lock.acquire() | 262 self.lock.acquire() |
268 if type == 'Image' or type == 'Texture': | 263 if type == 'Image' or type == 'Texture': |
269 url = component.get('settings').get_setting('ImageServerBaseURL') | 264 url = component.get('settings').get_setting('ImageServerBaseURL') |
270 recvdata = parse(urllib.urlopen(url, postdata)) | 265 file = urllib.urlopen(url, postdata) |
266 recvdata = file.read() | |
267 file.close() | |
271 try: | 268 try: |
272 xml_dom = fromstring(recvdata).getroot() | 269 xml_dom = minidom.parseString(recvdata)._get_documentElement() |
273 xml_dom = fromstring(recvdata) | 270 if xml_dom.nodeName == 'path': |
274 if xml_dom.tag == 'path': | 271 path = xml_dom.getAttribute('url') |
275 path = xml_dom.get('url') | |
276 path = urllib.unquote(path) | 272 path = urllib.unquote(path) |
277 if type == 'Image': self.set_image(path, 1) | 273 if type == 'Image': self.set_image(path, 1) |
278 else: self.set_texture(path) | 274 else: self.set_texture(path) |
279 self.localPath = filename | 275 self.localPath = filename |
280 self.local = True | 276 self.local = True |
281 self.localTime = time.time() | 277 self.localTime = time.time() |
282 else: | 278 else: |
283 print xml_dom.get('msg') | 279 print xml_dom.getAttribute('msg') |
284 except Exception, e: | 280 except Exception, e: |
285 print e | 281 print e |
286 print recvdata | 282 print recvdata |
287 self.lock.release() | 283 self.lock.release() |