comparison orpg/mapper/fog_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 072ffc1d466f
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/fog_msg.py
21 # Author: Mark Tarrabain
22 # Maintainer:
23 # Version:
24 # $Id: fog_msg.py,v 1.16 2006/11/04 21:24:21 digitalxero Exp $
25 #
26 __version__ = "$Id: fog_msg.py,v 1.16 2006/11/04 21:24:21 digitalxero Exp $"
27
28 from base_msg import *
29 from region import *
30 from orpg.minidom import Element
31 import string
32
33 class fog_msg(map_element_msg_base):
34
35 def __init__(self,reentrant_lock_object = None):
36 self.tagname = "fog"
37 map_element_msg_base.__init__(self,reentrant_lock_object)
38 self.use_fog = 0
39 self.fogregion=IRegion()
40 self.fogregion.Clear()
41
42 def get_line(self,outline,action,output_act):
43 elem = Element( "poly" )
44 if ( output_act ):
45 elem.setAttribute( "action", action )
46 if ( outline == 'all' ) or ( outline == 'none' ):
47 elem.setAttribute( "outline", outline )
48 else:
49 elem.setAttribute( "outline", "points" )
50 for pair in string.split( outline, ";" ):
51 p = string.split( pair, "," )
52 point = Element( "point" )
53 point.setAttribute( "x", p[ 0 ] )
54 point.setAttribute( "y", p[ 1 ] )
55 elem.appendChild( point )
56 str = elem.toxml()
57 elem.unlink()
58 return str
59
60 # convenience method to use if only this line is modified
61 # outputs a <map/> element containing only the changes to this line
62 def standalone_update_text(self,update_id_string):
63 buffer = "<map id='" + update_id_string + "'>"
64 buffer += "<fog>"
65 buffer += self.get_changed_xml()
66 buffer += "</fog></map>"
67 return buffer
68
69 def get_all_xml(self,action="new",output_action=1):
70 return self.toxml(action,output_action)
71
72 def get_changed_xml(self,action="update",output_action=1):
73 return self.toxml(action,output_action)
74
75 def toxml(self,action,output_action):
76 #print "fog_msg.toxml called"
77 #print "use_fog :",self.use_fog
78 #print "output_action :",output_action
79 #print "action :",action
80 if not (self.use_fog):
81 return ""
82 fog_string = ""
83 if self.fogregion.isEmpty():
84 fog_string=self.get_line("all","del",output_action)
85 for ri in self.fogregion.GetRectList():
86 x1=ri.GetX()
87 x2=x1+ri.GetW()-1
88 y1=ri.GetY()
89 y2=y1+ri.GetH()-1
90 fog_string += self.get_line(str(x1)+","+str(y1)+";"+
91 str(x2)+","+str(y1)+";"+
92 str(x2)+","+str(y2)+";"+
93 str(x1)+","+str(y2),action,output_action)
94 s = "<fog"
95 if fog_string:
96 s += ">"
97 s += fog_string
98 s += "</fog>"
99 else:
100 s+="/>"
101 return s
102
103 def interpret_dom(self,xml_dom):
104 self.use_fog=1
105 #print 'fog_msg.interpret_dom called'
106 children = xml_dom._get_childNodes()
107 #print "children",children
108 for l in children:
109 action = l.getAttribute("action")
110 outline = l.getAttribute("outline")
111 #print "action/outline",action, outline
112 if (outline=="all"):
113 polyline=[]
114 self.fogregion.Clear()
115 elif (outline=="none"):
116 polyline=[]
117 self.use_fog=0
118 self.fogregion.Clear()
119 else:
120 polyline=[]
121 list = l._get_childNodes()
122 for node in list:
123 polyline.append( IPoint().make( int(node.getAttribute("x")), int(node.getAttribute("y")) ) )
124 # pointarray = outline.split(";")
125 # for m in range(len(pointarray)):
126 # pt=pointarray[m].split(",")
127 # polyline.append(IPoint().make(int(pt[0]),int(pt[1])))
128 #print "length of polyline", len(polyline)
129 if (len(polyline)>2):
130 if action=="del":
131 self.fogregion.FromPolygon(polyline,0)
132 else:
133 self.fogregion.FromPolygon(polyline,1)
134
135 def init_from_dom(self,xml_dom):
136 self.interpret_dom(xml_dom)