comparison orpg/mapper/miniatures_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 211ac836b6a0
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/miniatures_msg.py
21 # Author: Chris Davis
22 # Maintainer:
23 # Version:
24 # $Id: miniatures_msg.py,v 1.8 2006/11/04 21:24:21 digitalxero Exp $
25 #
26 # Description: This file contains some of the basic definitions for the chat
27 # utilities in the orpg project.
28 #
29 __version__ = "$Id: miniatures_msg.py,v 1.8 2006/11/04 21:24:21 digitalxero Exp $"
30
31 from base_msg import *
32
33 class mini_msg(map_element_msg_base):
34
35 def __init__(self,reentrant_lock_object = None):
36 self.tagname = "miniature" # set this to be for minis. Tagname gets used in some base class functions.
37 map_element_msg_base.__init__(self,reentrant_lock_object) # call base class
38
39
40
41 # convenience method to use if only this mini is modified
42 # outputs a <map/> element containing only the changes to this mini
43 def standalone_update_text(self,update_id_string):
44 buffer = "<map id='" + update_id_string + "'>"
45 buffer += "<miniatures>"
46 buffer += self.get_changed_xml()
47 buffer += "</miniatures></map>"
48 return buffer
49
50 # convenience method to use if only this mini is modified
51 # outputs a <map/> element that deletes this mini
52 def standalone_delete_text(self,update_id_string):
53 buffer = None
54
55 if self._props.has_key("id"):
56 buffer = "<map id='" + update_id_string + "'>"
57 buffer += "<miniatures>"
58 buffer += "<miniature action='del' id='" + self._props("id") + "'/>"
59 buffer += "</miniatures></map>"
60
61 return buffer
62
63 # convenience method to use if only this mini is modified
64 # outputs a <map/> element to add this mini
65 def standalone_add_text(self,update_id_string):
66 buffer = "<map id='" + update_id_string + "'>"
67 buffer += "<miniatures>"
68 buffer += self.get_all_xml()
69 buffer += "</miniatures></map>"
70 return buffer
71
72 def get_all_xml(self,action="new",output_action=1):
73 return map_element_msg_base.get_all_xml(self,action,output_action)
74
75 def get_changed_xml(self,action="update",output_action=1):
76 return map_element_msg_base.get_changed_xml(self,action,output_action)
77
78
79
80 class minis_msg(map_element_msg_base):
81
82 def __init__(self,reentrant_lock_object = None):
83 self.tagname = "miniatures"
84 map_element_msg_base.__init__(self,reentrant_lock_object)
85
86 def init_from_dom(self,xml_dom):
87 self.p_lock.acquire()
88 if xml_dom.tagName == self.tagname:
89 if xml_dom.getAttributeKeys():
90 for k in xml_dom.getAttributeKeys():
91 self.init_prop(k,xml_dom.getAttribute(k))
92
93 for c in xml_dom._get_childNodes():
94 mini = mini_msg(self.p_lock)
95
96 try:
97 mini.init_from_dom(c)
98 except Exception, e:
99 print e
100 continue
101
102 id = mini.get_prop("id")
103 action = mini.get_prop("action")
104
105
106 if action == "new":
107 self.children[id] = mini
108
109 elif action == "del":
110 if self.children.has_key(id):
111 self.children[id] = None
112 del self.children[id]
113
114 elif action == "update":
115 if self.children.has_key(id):
116 self.children[id].init_props(mini.get_all_props())
117
118 else:
119 self.p_lock.release()
120 raise Exception, "Error attempting to initialize a " + self.tagname + " from a non-<" + self.tagname + "/> element"
121 self.p_lock.release()
122
123
124
125 def set_from_dom(self,xml_dom):
126 self.p_lock.acquire()
127 if xml_dom.tagName == self.tagname:
128 if xml_dom.getAttributeKeys():
129 for k in xml_dom.getAttributeKeys():
130 self.set_prop(k,xml_dom.getAttribute(k))
131
132 for c in xml_dom._get_childNodes():
133 mini = mini_msg(self.p_lock)
134
135 try:
136 mini.set_from_dom(c)
137 except Exception, e:
138 print e
139 continue
140
141 id = mini.get_prop("id")
142 action = mini.get_prop("action")
143
144 if action == "new":
145 self.children[id] = mini
146
147 elif action == "del":
148 if self.children.has_key(id):
149 self.children[id] = None
150 del self.children[id]
151
152 elif action == "update":
153 if self.children.has_key(id):
154 self.children[id].set_props(mini.get_all_props())
155
156 else:
157 self.p_lock.release()
158 raise Exception, "Error attempting to set a " + self.tagname + " from a non-<" + self.tagname + "/> element"
159 self.p_lock.release()