Mercurial > traipse_dev
comparison orpg/mapper/map_msg.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | 78407d627cba |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: mapper/map_msg.py | |
21 # Author: OpenRPG | |
22 # Maintainer: | |
23 # Version: | |
24 # $Id: map_msg.py,v 1.16 2007/03/09 14:11:55 digitalxero Exp $ | |
25 # | |
26 # Description: | |
27 # | |
28 __version__ = "$Id: map_msg.py,v 1.16 2007/03/09 14:11:55 digitalxero Exp $" | |
29 | |
30 #from base import * | |
31 from base_msg import * | |
32 from background_msg import * | |
33 from grid_msg import * | |
34 from miniatures_msg import * | |
35 from whiteboard_msg import * | |
36 from fog_msg import * | |
37 | |
38 """ | |
39 <map name=? id=? > | |
40 <bg type=? file=? color=? /> | |
41 <grid size=? snap=? /> | |
42 <miniatures serial=? > | |
43 <miniature path=? posx=? posy=? heading=? face=? owner=? label=? locked=? width=? height=? /> | |
44 </miniatures> | |
45 </map> | |
46 | |
47 """ | |
48 | |
49 class map_msg(map_element_msg_base): | |
50 | |
51 def __init__(self,reentrant_lock_object = None): | |
52 self.tagname = "map" | |
53 map_element_msg_base.__init__(self,reentrant_lock_object) | |
54 | |
55 def init_from_dom(self,xml_dom): | |
56 self.p_lock.acquire() | |
57 if xml_dom.tagName == self.tagname: | |
58 # If this is a map message, look for the "action=new" | |
59 # Notice we only do this when the root is a map tag | |
60 if self.tagname == "map" and xml_dom.hasAttribute("action") and xml_dom.getAttribute("action") == "new": | |
61 self.clear() | |
62 # Process all of the properties in each tag | |
63 if xml_dom.getAttributeKeys(): | |
64 for k in xml_dom.getAttributeKeys(): | |
65 self.init_prop(k,xml_dom.getAttribute(k)) | |
66 for c in xml_dom._get_childNodes(): | |
67 name = c._get_nodeName() | |
68 if not self.children.has_key(name): | |
69 if name == "miniatures": | |
70 self.children[name] = minis_msg(self.p_lock) | |
71 elif name == "grid": | |
72 self.children[name] = grid_msg(self.p_lock) | |
73 elif name == "bg": | |
74 self.children[name] = bg_msg(self.p_lock) | |
75 elif name == "whiteboard": | |
76 self.children[name] = whiteboard_msg(self.p_lock) | |
77 elif name == "fog": | |
78 self.children[name] = fog_msg(self.p_lock) | |
79 else: | |
80 print "Unrecognized tag " + name + " found in map_msg.init_from_dom - skipping" | |
81 continue | |
82 try: | |
83 self.children[name].init_from_dom(c) | |
84 except Exception, e: | |
85 print "map_msg.init_from_dom() exception: "+str(e) | |
86 continue | |
87 else: | |
88 self.p_lock.release() | |
89 raise Exception, "Error attempting to initialize a " + self.tagname + " from a non-<" + self.tagname + "/> element" | |
90 self.p_lock.release() | |
91 | |
92 def set_from_dom(self,xml_dom): | |
93 self.p_lock.acquire() | |
94 if xml_dom.tagName == self.tagname: | |
95 # If this is a map message, look for the "action=new" | |
96 # Notice we only do this when the root is a map tag | |
97 if self.tagname == "map" and xml_dom.hasAttribute("action") and xml_dom.getAttribute("action") == "new": | |
98 self.clear() | |
99 # Process all of the properties in each tag | |
100 if xml_dom.getAttributeKeys(): | |
101 for k in xml_dom.getAttributeKeys(): | |
102 self.set_prop(k,xml_dom.getAttribute(k)) | |
103 for c in xml_dom._get_childNodes(): | |
104 name = c._get_nodeName() | |
105 if not self.children.has_key(name): | |
106 if name == "miniatures": | |
107 self.children[name] = minis_msg(self.p_lock) | |
108 elif name == "grid": | |
109 self.children[name] = grid_msg(self.p_lock) | |
110 elif name == "bg": | |
111 self.children[name] = bg_msg(self.p_lock) | |
112 elif name == "whiteboard": | |
113 self.children[name] = whiteboard_msg(self.p_lock) | |
114 elif name == "fog": | |
115 self.children[name] = fog_msg(self.p_lock) | |
116 else: | |
117 print "Unrecognized tag " + name + " found in map_msg.init_from_dom - skipping" | |
118 continue | |
119 try: | |
120 self.children[name].set_from_dom(c) | |
121 except Exception, e: | |
122 print "map_msg.set_from_dom() exception: "+str(e) | |
123 continue | |
124 else: | |
125 self.p_lock.release() | |
126 raise Exception, "Error attempting to set a " + self.tagname + " from a non-<" + self.tagname + "/> element in map" | |
127 self.p_lock.release() | |
128 | |
129 def get_all_xml(self, action="new", output_action=1): | |
130 return map_element_msg_base.get_all_xml(self, action, output_action) | |
131 | |
132 def get_changed_xml(self, action="update", output_action=1): | |
133 return map_element_msg_base.get_changed_xml(self, action, output_action) |