view orpg/mapper/base.py @ 227:81d0bfd5e800 alpha

Traipse Alpha 'OpenRPG' {100612-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 (Preparing to close updates) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order Fixes: Fix to InterParse that was causing an Infernal Loop with Namespace Internal Fix to XML data, removed old Minidom and switched to Element Tree Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread Fix to metaservers.xml file not being created
author sirebral
date Sat, 12 Jun 2010 03:50:37 -0500
parents 449a8900f9ac
children
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/base.py
# Author: Chris Davis
# Maintainer:
# Version:
#   $Id: base.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
#
# Description:
#
__version__ = "$Id: base.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"

from images import ImageHandler
from orpg.tools.rgbhex import *
from orpg.orpg_windows import *
from math import *
from threading import Lock
import time

class cmpPoint(wx.Point):
    def __init__(self,*_args,**_kwargs):
        wx.Point.__init__(self,*_args,**_kwargs)

    def __cmp__(self,other):
        try:
            if self.x < other.x: return -1
            elif self.x > other.x: return 1
            elif self.y < other.y: return -1
            elif self.y > other.y: return 1
            else: return 0
        except: return -2

class cmpColour(wx.Colour):
    def __init__(self,*_args,**_kwargs):
        wx.Colour.__init__(self,*_args,**_kwargs)

    def __cmp__(self,other):
        try:
            (r,g,b) = self.Get()
            my_value = b*256*256 + g*256 + r
            (r,g,b) = other.Get()
            other_value = b*256*256 + g*256 + r
            if my_value < other_value: return -1
            elif my_value > other_value: return 1
            else: return 0
        except: return -2

class protectable_attributes:

    def __init__(self):
        self._set("_protected_attr",[])

    def _set(self,name,value):
        self.__dict__[name] = value

    def __setattr__(self,name,value):
        if name in self._protected_attr:
            full_name = "_protect_" + name
            if hasattr(self,full_name):
                (p,c) = getattr(self,full_name)
                if p != value: self._set(full_name,(value,1))
            else: self._set(full_name,(value,1))
        else: self._set(name,value)

    def __getattr__(self,name):
        if name in self._protected_attr:
            (p,c) = self.__dict__["_protect_" + name]
            return p
        else: raise AttributeError

    def _clean_attr(self,name):
        if name in self._protected_attr:
            (p,c) = self.__dict__["_protect_" + name]
            self._set("_protect_" + name,(p,0))

    def _dirty_attr(self,name):
        if name in self._protected_attr:
            (p,c) = self.__dict__["_protect_" + name]
            self._set("_protect_" + name,(p,1))

    def _changed_attr(self):
        changed = {}
        for name in self._protected_attr:
            (p,c) = self.__dict__["_protect_" + name]
            if c: changed[name] = p
        return changed

    def _clean_all_attr(self):
        for name in self._protected_attr:
            (p,c) = self.__dict__["_protect_" + name]
            self._set("_protect_" + name,(p,0))

    def _dirty_all_attr(self):
        for name in self._protected_attr:
            (p,c) = self.__dict__["_protect_" + name]
            self._set("_protect_" + name,(p,1))

##-----------------------------
## base class for layer objects
##-----------------------------

class layer_base:

    def __init__(self):
        self.lock = Lock()

    def layerDraw(self,dc,scale='',topleft='',size=''):
        pass

    def layerToXML(self, action):
        pass

    def layerTakeDOM(self, xml_dom):
        pass

    def hit_test(self,pos):
        pass