comparison orpg/mapper/base.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/base.py
21 # Author: Chris Davis
22 # Maintainer:
23 # Version:
24 # $Id: base.py,v 1.18 2007/02/12 02:29:08 digitalxero Exp $
25 #
26 # Description:
27 #
28 __version__ = "$Id: base.py,v 1.18 2007/02/12 02:29:08 digitalxero Exp $"
29
30 from images import ImageHandler
31 from orpg.tools.rgbhex import *
32 from orpg.orpg_windows import *
33 from orpg.orpg_xml import *
34 from math import *
35 from threading import Lock
36 import time
37
38 class cmpPoint(wx.Point):
39 def __init__(self,*_args,**_kwargs):
40 wx.Point.__init__(self,*_args,**_kwargs)
41
42 def __cmp__(self,other):
43 try:
44 if self.x < other.x:
45 return -1
46 elif self.x > other.x:
47 return 1
48 elif self.y < other.y:
49 return -1
50 elif self.y > other.y:
51 return 1
52 else:
53 return 0
54 except:
55 return -2
56
57 class cmpColour(wx.Colour):
58 def __init__(self,*_args,**_kwargs):
59 wx.Colour.__init__(self,*_args,**_kwargs)
60
61 def __cmp__(self,other):
62 try:
63 (r,g,b) = self.Get()
64 my_value = b*256*256 + g*256 + r
65 (r,g,b) = other.Get()
66 other_value = b*256*256 + g*256 + r
67 if my_value < other_value:
68 return -1
69 elif my_value > other_value:
70 return 1
71 else: # they're equal
72 return 0
73 except:
74 return -2
75
76 class protectable_attributes:
77
78 def __init__(self):
79 self._set("_protected_attr",[])
80
81 def _set(self,name,value):
82 self.__dict__[name] = value
83
84 def __setattr__(self,name,value):
85 if name in self._protected_attr:
86 full_name = "_protect_" + name
87 if hasattr(self,full_name):
88 (p,c) = getattr(self,full_name)
89 if p != value:
90 self._set(full_name,(value,1))
91 else:
92 self._set(full_name,(value,1))
93 else:
94 self._set(name,value)
95
96 def __getattr__(self,name):
97 if name in self._protected_attr:
98 (p,c) = self.__dict__["_protect_" + name]
99 return p
100 else:
101 raise AttributeError
102
103 def _clean_attr(self,name):
104 if name in self._protected_attr:
105 (p,c) = self.__dict__["_protect_" + name]
106 self._set("_protect_" + name,(p,0))
107
108 def _dirty_attr(self,name):
109 if name in self._protected_attr:
110 (p,c) = self.__dict__["_protect_" + name]
111 self._set("_protect_" + name,(p,1))
112
113 def _changed_attr(self):
114 changed = {}
115 for name in self._protected_attr:
116 (p,c) = self.__dict__["_protect_" + name]
117 if c:
118 changed[name] = p
119 return changed
120
121 def _clean_all_attr(self):
122 for name in self._protected_attr:
123 (p,c) = self.__dict__["_protect_" + name]
124 self._set("_protect_" + name,(p,0))
125
126 def _dirty_all_attr(self):
127 for name in self._protected_attr:
128 (p,c) = self.__dict__["_protect_" + name]
129 self._set("_protect_" + name,(p,1))
130
131 ##-----------------------------
132 ## base class for layer objects
133 ##-----------------------------
134
135 class layer_base:
136
137 def __init__(self):
138 self.lock = Lock()
139
140 def layerDraw(self,dc,scale='',topleft='',size=''):
141 pass
142
143 def layerToXML(self, action):
144 pass
145
146 def layerTakeDOM(self, xml_dom):
147 pass
148
149 def hit_test(self,pos):
150 pass