view orpg/mapper/fog_msg.py @ 122:36919b8a3ef9 alpha

Traipse Alpha 'OpenRPG' {091031-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 Mercurial's hgweb folder is ported to upmana Happy Halloween!
author sirebral
date Sat, 31 Oct 2009 22:07:55 -0500
parents 449a8900f9ac
children 54446a995007 e842a5f1b775
line wrap: on
line source

# Copyright (C) 2000-2001 The OpenRPG Project
#
#    openrpg-dev@lists.sourceforge.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# --
#
# File: mapper/fog_msg.py
# Author: Mark Tarrabain
# Maintainer:
# Version:
#   $Id: fog_msg.py,v 1.16 2006/11/04 21:24:21 digitalxero Exp $
#
__version__ = "$Id: fog_msg.py,v 1.16 2006/11/04 21:24:21 digitalxero Exp $"

from base_msg import *
from region import *
#from orpg.minidom import Element
import string
from xml.etree.ElementTree import ElementTree

class fog_msg(map_element_msg_base):

    def __init__(self,reentrant_lock_object = None):
        self.tag = "fog"
        map_element_msg_base.__init__(self,reentrant_lock_object)
        self.use_fog = 0
        self.fogregion=IRegion()
        self.fogregion.Clear()

    def get_line(self,outline,action,output_act):
        elem = Element( "poly" )
        if ( output_act ): elem.set( "action", action )
        if ( outline == 'all' ) or ( outline == 'none' ): elem.set( "outline", outline )
        else:
            elem.set( "outline", "points" )
            for pair in string.split( outline, ";" ):
                p = string.split( pair, "," )
                point = Element( "point" )
                point.set( "x", p[ 0 ] )
                point.set( "y", p[ 1 ] )
                elem.append( point )
        str = elem.toxml()
        elem.unlink()
        return str

    # convenience method to use if only this line is modified
    #   outputs a <map/> element containing only the changes to this line
    def standalone_update_text(self,update_id_string):
        buffer = "<map id='" + update_id_string + "'>"
        buffer += "<fog>"
        buffer += self.get_changed_xml()
        buffer += "</fog></map>"
        return buffer

    def get_all_xml(self,action="new",output_action=1):
        return self.toxml(action,output_action)

    def get_changed_xml(self,action="update",output_action=1):
        return self.toxml(action,output_action)

    def toxml(self,action,output_action):
        if not (self.use_fog): return ""
        fog_string = ""
        if self.fogregion.isEmpty(): fog_string=self.get_line("all","del",output_action)
        for ri in self.fogregion.GetRectList():
            x1=ri.GetX()
            x2=x1+ri.GetW()-1
            y1=ri.GetY()
            y2=y1+ri.GetH()-1
            fog_string += self.get_line(str(x1)+","+str(y1)+";"+
                                         str(x2)+","+str(y1)+";"+
                                         str(x2)+","+str(y2)+";"+
                                         str(x1)+","+str(y2),action,output_action)
        s = "<fog"
        if fog_string:
            s += ">"
            s += fog_string
            s += "</fog>"
        else: s+="/>"
        return s

    def interpret_dom(self,xml_dom):
        self.use_fog=1
        #print 'fog_msg.interpret_dom called'
        children = xml_dom.getchildren()
        #print "children",children
        for l in children:
            action = l.get("action")
            outline = l.get("outline")
            #print "action/outline",action, outline
            if (outline=="all"):
                polyline=[]
                self.fogregion.Clear()
            elif (outline=="none"):
                polyline=[]
                self.use_fog=0
                self.fogregion.Clear()
            else:
                polyline=[]
                list = l.getchildren()
                for node in list:
                    polyline.append( IPoint().make( int(node.get("x")), int(node.get("y")) ) )
                    # pointarray = outline.split(";")
                    # for m in range(len(pointarray)):
                    #     pt=pointarray[m].split(",")
                    #     polyline.append(IPoint().make(int(pt[0]),int(pt[1])))
                    #print "length of polyline", len(polyline)
            if (len(polyline)>2):
                if action=="del": self.fogregion.FromPolygon(polyline,0)
                else: self.fogregion.FromPolygon(polyline,1)

    def init_from_dom(self,xml_dom):
        self.interpret_dom(xml_dom)