annotate src/parpg/bGrease/entity.py @ 84:1e7465a785c4

Removed the pos value from the fifeagent component. getItemActions of Gamescenecontroller gets the position by calling a method of the behaviour.
author KarstenBock@gmx.net
date Fri, 09 Sep 2011 15:30:23 +0200
parents 96af64cf3b81
children 9b5498e3bda0
rev   line source
27
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
1 #############################################################################
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
2 #
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
3 # Copyright (c) 2010 by Casey Duncan and contributors
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
4 # All Rights Reserved.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
5 #
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
6 # This software is subject to the provisions of the MIT License
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
7 # A copy of the license should accompany this distribution.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
8 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
9 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
10 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
11 #
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
12 #############################################################################
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
13 """Grease entities are useful as actionable, interactive
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
14 game elements that are often visible to the player.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
15
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
16 You might use entities to represent:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
17
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
18 - Characters
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
19 - Bullets
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
20 - Particles
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
21 - Pick-ups
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
22 - Space Ships
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
23 - Weapons
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
24 - Trees
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
25 - Planets
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
26 - Explosions
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
27
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
28 See :ref:`an example entity class in the tutorial <tut-entity-example>`.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
29 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
30
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
31 __version__ = '$Id$'
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
32
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
33 __all__ = ('Entity', 'EntityComponentAccessor', 'ComponentEntitySet')
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
34
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
35
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
36 class EntityMeta(type):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
37 """The entity metaclass enforces fixed slots of `entity_id` and `world`
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
38 for all subclasses. This prevents accidental use of other entity instance
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
39 attributes, which may not be saved.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
40
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
41 Class attributes are not affected by this restriction, but subclasses
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
42 should be careful not to cause name collisions with world components,
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
43 which are exposed as entity attributes. Using a naming convention for
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
44 class attributes, such as UPPER_CASE_WITH_UNDERSCORES is recommended to
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
45 avoid name clashes.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
46
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
47 Note as a result of this, entity subclasses are not allowed to define
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
48 `__slots__`, and doing so will cause a `TypeError` to be raised.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
49 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
50
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
51 def __new__(cls, name, bases, clsdict):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
52 if '__slots__' in clsdict:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
53 raise TypeError('__slots__ may not be defined in Entity subclasses')
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
54 clsdict['__slots__'] = ('world', 'entity_id')
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
55 return type.__new__(cls, name, bases, clsdict)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
56
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
57
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
58 class Entity(object):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
59 """Base class for grease entities.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
60
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
61 Entity objects themselves are merely identifiers within a :class:`grease.world.World`.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
62 They also provide a facade for convenient entity-wise access of component
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
63 data. However, they do not contain any data themselves other than an
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
64 entity id.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
65
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
66 Entities must be instantiated in the context of a world. To instantiate an
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
67 entity, you must pass the world as the first argument to the constructor.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
68 Subclasses that implement the :meth:`__init__()` method, must accept the world
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
69 as their first argument (after ``self``). Other constructor arguments can be
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
70 specified arbitarily by the subclass.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
71 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
72 __metaclass__ = EntityMeta
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
73
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
74 def __new__(cls, world, *args, **kw):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
75 """Create a new entity and add it to the world"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
76 entity = object.__new__(cls)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
77 entity.world = world
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
78 entity.entity_id = world.new_entity_id()
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
79 world.entities.add(entity)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
80 return entity
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
81
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
82 def __getattr__(self, name):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
83 """Return an :class:`EntityComponentAccessor` for this entity
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
84 for the component named.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
85
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
86 Example::
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
87
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
88 my_entity.movement
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
89 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
90 component = getattr(self.world.components, name)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
91 return EntityComponentAccessor(component, self)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
92
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
93 def __setattr__(self, name, value):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
94 """Set the entity data in the named component for this entity.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
95 This sets the values of the component fields to the values of
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
96 the matching attributes of the value provided. This value must
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
97 have attributes for each of the component fields.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
98
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
99 This allows you to easily copy component data from one entity
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
100 to another.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
101
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
102 Example::
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
103
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
104 my_entity.position = other_entity.position
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
105 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
106 if name in self.__class__.__slots__:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
107 super(Entity, self).__setattr__(name, value)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
108 else:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
109 component = getattr(self.world.components, name)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
110 component.set(self, value)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
111
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
112 def __delattr__(self, name):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
113 """Remove this entity and its data from the component.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
114
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
115 Example::
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
116
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
117 del my_entity.renderable
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
118 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
119 component = getattr(self.world.components, name)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
120 del component[self]
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
121
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
122 def __hash__(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
123 return self.entity_id
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
124
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
125 def __eq__(self, other):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
126 return self.world is other.world and self.entity_id == other.entity_id
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
127
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
128 def __repr__(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
129 return "<%s id: %s of %s %x>" % (
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
130 self.__class__.__name__, self.entity_id,
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
131 self.world.__class__.__name__, id(self.world))
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
132
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
133 def delete(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
134 """Delete the entity from its world. This removes all of its
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
135 component data. If then entity has already been deleted,
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
136 this call does nothing.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
137 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
138 self.world.entities.discard(self)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
139
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
140 @property
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
141 def exists(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
142 """True if the entity still exists in the world"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
143 return self in self.world.entities
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
144
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
145
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
146 class EntityComponentAccessor(object):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
147 """A facade for accessing specific component data for a single entity.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
148 The implementation is lazy and does not actually access the component
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
149 data until needed. If an attribute is set for a component that the
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
150 entity is not yet a member of, it is automatically added to the
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
151 component first.
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
152
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
153 :param component: The :class:`grease.Component` being accessed
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
154 :param entity: The :class:`Entity` being accessed
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
155 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
156
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
157 # beware, name mangling ahead. We want to avoid clashing with any
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
158 # user-configured component field names
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
159 __data = None
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
160
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
161 def __init__(self, component, entity):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
162 clsname = self.__class__.__name__
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
163 self.__dict__['_%s__component' % clsname] = component
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
164 self.__dict__['_%s__entity' % clsname] = entity
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
165
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
166 def __nonzero__(self):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
167 """The accessor is True if the entity is in the component,
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
168 False if not, for convenient membership tests
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
169 """
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
170 return self.__entity in self.__component
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
171
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
172 def __getattr__(self, name):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
173 """Return the data for the specified field of the entity's component"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
174 if self.__data is None:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
175 try:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
176 data = self.__component[self.__entity]
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
177 except KeyError:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
178 raise AttributeError(name)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
179 clsname = self.__class__.__name__
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
180 self.__dict__['_%s__data' % clsname] = data
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
181 return getattr(self.__data, name)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
182
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
183 def __setattr__(self, name, value):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
184 """Set the data for the specified field of the entity's component"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
185 if self.__data is None:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
186 clsname = self.__class__.__name__
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
187 if self.__entity in self.__component:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
188 self.__dict__['_%s__data' % clsname] = self.__component[self.__entity]
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
189 else:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
190 self.__dict__['_%s__data' % clsname] = self.__component.set(self.__entity)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
191 setattr(self.__data, name, value)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
192
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
193
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
194 class ComponentEntitySet(set):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
195 """Set of entities in a component, can be queried by component fields"""
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
196
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
197 _component = None
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
198
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
199 def __init__(self, component, entities=()):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
200 self.__dict__['_component'] = component
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
201 super(ComponentEntitySet, self).__init__(entities)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
202
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
203 def __getattr__(self, name):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
204 if self._component is not None and name in self._component.fields:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
205 return self._component.fields[name].accessor(self)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
206 raise AttributeError(name)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
207
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
208 def __setattr__(self, name, value):
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
209 if self._component is not None and name in self._component.fields:
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
210 self._component.fields[name].accessor(self).__set__(value)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
211 raise AttributeError(name)
09b581087d68 Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
212