view orpg/mapper/fog_msg.py @ 137:54446a995007 alpha

Traipse Alpha 'OpenRPG' {091018-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 (See documentation for usage) Mercurial's hgweb folder is ported to upmana **Pretty important update that can help remove thousands of dead children from your gametree. **Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! **New Gametree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author sirebral
date Wed, 18 Nov 2009 19:57:52 -0600
parents 36919b8a3ef9
children 8e07c1a2c69b
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
        children = xml_dom.getchildren()
        for l in children:
            action = l.get("action")
            outline = l.get("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")) ) )
            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)