annotate bGrease/component/__init__.py @ 42:66a06de1bddc

Renamed dialog to dialogue
author KarstenBock@gmx.net
date Tue, 06 Sep 2011 14:37:54 +0200
parents ff3e395abf91
children e856b604b650
rev   line source
5
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
1 #############################################################################
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
2 #
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
3 # Copyright (c) 2010 by Casey Duncan and contributors
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
4 # All Rights Reserved.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
5 #
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
6 # This software is subject to the provisions of the MIT License
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
7 # A copy of the license should accompany this distribution.
bc88f7d5ca8b 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
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
9 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
10 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
11 #
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
12 #############################################################################
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
13 """Components store all entity data in a given |World|. You can
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
14 think of components as tables with entities as their primary keys. Like
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
15 database tables, components are defined with a "schema" that specifies
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
16 the data fields. Each field in a component has a name and a type.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
17
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
18 Component objects themselves have a dict-like interface with entities
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
19 as keys and data records as values. An application will typically
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
20 interact with components via entity attributes, entity extents or
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
21 by joining them. For more information see:
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
22
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
23 - :class:`~grease.entity.Entity` class.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
24 - :class:`~grease.world.EntityExtent` class.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
25 - :meth:`~grease.world.ComponentParts.join` method of ComponentParts.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
26
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
27 See also :ref:`defining custom components in the tutorial <custom-component-example>`.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
28 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
29
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
30 __version__ = '$Id$'
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
31
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
32 __all__ = ('Component', 'ComponentError', 'Position', 'Transform', 'Movement',
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
33 'Shape', 'Renderable', 'Collision')
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
34
41
ff3e395abf91 Renamed grease to bGrease (Basic Grease) to get rid of conflicts with an already installed grease.
KarstenBock@gmx.net
parents: 5
diff changeset
35 from bGrease.component.general import Component
ff3e395abf91 Renamed grease to bGrease (Basic Grease) to get rid of conflicts with an already installed grease.
KarstenBock@gmx.net
parents: 5
diff changeset
36 from bGrease.geometry import Vec2d, Vec2dArray, Rect
ff3e395abf91 Renamed grease to bGrease (Basic Grease) to get rid of conflicts with an already installed grease.
KarstenBock@gmx.net
parents: 5
diff changeset
37 from bGrease import color
5
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
38
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
39
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
40 class ComponentError(Exception):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
41 """General component error"""
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
42
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
43
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
44 class Position(Component):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
45 """Predefined component that stores position and orientation info for
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
46 entities.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
47
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
48 Fields:
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
49
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
50 - **position** (Vec2d) -- Position vector
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
51 - **angle** (float) -- Angle, in degrees
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
52 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
53
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
54 def __init__(self):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
55 Component.__init__(self, position=Vec2d, angle=float)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
56
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
57
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
58 class Transform(Component):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
59 """Predefined component that stores offset, shear,
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
60 rotation and scale info for entity shapes.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
61
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
62 Fields:
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
63
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
64 - **offset** (Vec2d)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
65 - **shear** (Vec2d)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
66 - **rotation** (float)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
67 - **scale** (float, default 1.0)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
68 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
69
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
70 def __init__(self):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
71 Component.__init__(self, offset=Vec2d, shear=Vec2d, rotation=float, scale=float)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
72 self.fields['scale'].default = lambda: 1.0
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
73
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
74
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
75 class Movement(Component):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
76 """Predefined component that stores velocity,
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
77 acceleration and rotation info for entities.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
78
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
79 Fields:
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
80
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
81 - **velocity** (Vec2d) -- Rate of change of entity position
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
82 - **accel** (Vec2d) -- Rate of change of entity velocity
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
83 - **rotation** (Vec2d) -- Rate of change of entity angle, in degrees/time
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
84 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
85
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
86 def __init__(self):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
87 Component.__init__(self, velocity=Vec2d, accel=Vec2d, rotation=float)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
88
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
89
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
90 class Shape(Component):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
91 """Predefined component that stores shape vertices for entities
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
92
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
93 - **closed** (bool) -- If the shapes is closed implying an edge between
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
94 last and first vertices.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
95 - **verts** (Vec2dArray) -- Array of vertex points
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
96 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
97
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
98 def __init__(self):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
99 Component.__init__(self, closed=int, verts=Vec2dArray)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
100 self.fields['closed'].default = lambda: 1
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
101
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
102
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
103 class Renderable(Component):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
104 """Predefined component that identifies entities to be
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
105 rendered and provides their depth and color.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
106
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
107 - **depth** (float) -- Drawing depth, can be used to determine z-order
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
108 while rendering.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
109 - **color** (color.RGBA) -- Color used for entity. The effect of this
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
110 field depends on the renderer.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
111 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
112
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
113 def __init__(self):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
114 Component.__init__(self, depth=float, color=color.RGBA)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
115 self.fields['color'].default = lambda: color.RGBA(1,1,1,1)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
116
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
117
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
118 class Collision(Component):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
119 """Predefined component that stores collision masks to determine
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
120 which entities can collide.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
121
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
122 Fields:
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
123
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
124 - **aabb** (Rect) -- The axis-aligned bounding box for the entity.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
125 This is used for broad-phase collision detection.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
126
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
127 - **radius** (float) -- The collision radius of the entity, used for narrow-phase
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
128 collision detection. The exact meaning of this value depends on the collision
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
129 system in use.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
130
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
131 - **from_mask** (int) -- A bitmask that determines what entities this object
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
132 can collide with.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
133
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
134 - **into_mask** (int) -- A bitmask that determines what entities can collide
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
135 with this object.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
136
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
137 When considering an entity A for collision with entity B, A's ``from_mask`` is
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
138 bit ANDed with B's ``into_mask``. If the result is nonzero (meaning 1 or more
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
139 bits is set the same for each) then the collision test is made. Otherwise,
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
140 the pair cannot collide.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
141
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
142 The default value for both of these masks is ``0xffffffff``, which means that
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
143 all entities will collide with each other by default.
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
144 """
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
145 def __init__(self):
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
146 Component.__init__(self, aabb=Rect, radius=float, from_mask=int, into_mask=int)
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
147 self.fields['into_mask'].default = lambda: 0xffffffff
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
148 self.fields['from_mask'].default = lambda: 0xffffffff
bc88f7d5ca8b Added base files for grease
KarstenBock@gmx.net
parents:
diff changeset
149