105
|
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/tokens_msg.py
|
|
21 # Author: Chris Davis
|
|
22 # Maintainer:
|
|
23 # Version:
|
|
24 # $Id: tokens_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: tokens_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 = "token" # 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 # convenience method to use if only this mini is modified
|
|
40 # outputs a <map/> element containing only the changes to this mini
|
|
41 def standalone_update_text(self,update_id_string):
|
|
42 buffer = "<map id='" + update_id_string + "'>"
|
|
43 buffer += "<tokens>"
|
|
44 buffer += self.get_changed_xml()
|
|
45 buffer += "</tokens></map>"
|
|
46 return buffer
|
|
47
|
|
48 # convenience method to use if only this mini is modified
|
|
49 # outputs a <map/> element that deletes this mini
|
|
50 def standalone_delete_text(self,update_id_string):
|
|
51 buffer = None
|
|
52 if self._props.has_key("id"):
|
|
53 buffer = "<map id='" + update_id_string + "'>"
|
|
54 buffer += "<tokens>"
|
|
55 buffer += "<token action='del' id='" + self._props("id") + "'/>"
|
|
56 buffer += "</tokens></map>"
|
|
57 return buffer
|
|
58
|
|
59 # convenience method to use if only this mini is modified
|
|
60 # outputs a <map/> element to add this mini
|
|
61 def standalone_add_text(self,update_id_string):
|
|
62 buffer = "<map id='" + update_id_string + "'>"
|
|
63 buffer += "<tokens>"
|
|
64 buffer += self.get_all_xml()
|
|
65 buffer += "</tokens></map>"
|
|
66 return buffer
|
|
67
|
|
68 def get_all_xml(self,action="new",output_action=1):
|
|
69 return map_element_msg_base.get_all_xml(self,action,output_action)
|
|
70
|
|
71 def get_changed_xml(self,action="update",output_action=1):
|
|
72 return map_element_msg_base.get_changed_xml(self,action,output_action)
|
|
73
|
|
74 class minis_msg(map_element_msg_base):
|
|
75
|
|
76 def __init__(self,reentrant_lock_object = None):
|
|
77 self.tagname = "tokens"
|
|
78 map_element_msg_base.__init__(self,reentrant_lock_object)
|
|
79
|
|
80 def init_from_dom(self,xml_dom):
|
|
81 self.p_lock.acquire()
|
|
82 if xml_dom.tagName == self.tagname:
|
|
83 if xml_dom.getAttributeKeys():
|
|
84 for k in xml_dom.getAttributeKeys():
|
|
85 self.init_prop(k,xml_dom.getAttribute(k))
|
|
86
|
|
87 for c in xml_dom._get_childNodes():
|
|
88 mini = mini_msg(self.p_lock)
|
|
89 try: mini.init_from_dom(c)
|
|
90 except Exception, e: print e; continue
|
|
91 id = mini.get_prop("id")
|
|
92 action = mini.get_prop("action")
|
|
93
|
|
94 if action == "new": self.children[id] = mini
|
|
95 elif action == "del":
|
|
96 if self.children.has_key(id):
|
|
97 self.children[id] = None
|
|
98 del self.children[id]
|
|
99
|
|
100 elif action == "update":
|
|
101 if self.children.has_key(id):
|
|
102 self.children[id].init_props(mini.get_all_props())
|
|
103 else:
|
|
104 self.p_lock.release()
|
|
105 raise Exception, "Error attempting to initialize a " + self.tagname + " from a non-<" + self.tagname + "/> element"
|
|
106 self.p_lock.release()
|
|
107
|
|
108 def set_from_dom(self,xml_dom):
|
|
109 self.p_lock.acquire()
|
|
110 if xml_dom.tagName == self.tagname:
|
|
111 if xml_dom.getAttributeKeys():
|
|
112 for k in xml_dom.getAttributeKeys():
|
|
113 self.set_prop(k,xml_dom.getAttribute(k))
|
|
114
|
|
115 for c in xml_dom._get_childNodes():
|
|
116 mini = mini_msg(self.p_lock)
|
|
117
|
|
118 try: mini.set_from_dom(c)
|
|
119 except Exception, e: print e; continue
|
|
120 id = mini.get_prop("id")
|
|
121 action = mini.get_prop("action")
|
|
122 if action == "new": self.children[id] = mini
|
|
123 elif action == "del":
|
|
124 if self.children.has_key(id):
|
|
125 self.children[id] = None
|
|
126 del self.children[id]
|
|
127 elif action == "update":
|
|
128 if self.children.has_key(id):
|
|
129 self.children[id].set_props(mini.get_all_props())
|
|
130 else:
|
|
131 self.p_lock.release()
|
|
132 raise Exception, "Error attempting to set a " + self.tagname + " from a non-<" + self.tagname + "/> element"
|
|
133 self.p_lock.release()
|