|
| 1 | +from abc import ABCMeta, abstractmethod |
| 2 | + |
| 3 | + |
| 4 | +class IGUISpriteInterface(metaclass=ABCMeta): |
| 5 | + """ |
| 6 | + A sprite Interface class specifically designed for the GUI. Very similar to pygame's |
| 7 | + DirtySprite but without the Dirty flag. |
| 8 | + """ |
| 9 | + |
| 10 | + @abstractmethod |
| 11 | + def add(self, *groups): |
| 12 | + """add the sprite to groups |
| 13 | +
|
| 14 | + Sprite.add(*groups): return None |
| 15 | +
|
| 16 | + Any number of Group instances can be passed as arguments. The |
| 17 | + Sprite will be added to the Groups it is not already a member of. |
| 18 | +
|
| 19 | + """ |
| 20 | + |
| 21 | + @abstractmethod |
| 22 | + def remove(self, *groups): |
| 23 | + """remove the sprite from groups |
| 24 | +
|
| 25 | + Sprite.remove(*groups): return None |
| 26 | +
|
| 27 | + Any number of Group instances can be passed as arguments. The Sprite |
| 28 | + will be removed from the Groups it is currently a member of. |
| 29 | +
|
| 30 | + """ |
| 31 | + |
| 32 | + @abstractmethod |
| 33 | + def add_internal(self, group): |
| 34 | + """ |
| 35 | + For adding this sprite to a group internally. |
| 36 | +
|
| 37 | + :param group: The group we are adding to. |
| 38 | + """ |
| 39 | + |
| 40 | + @abstractmethod |
| 41 | + def remove_internal(self, group): |
| 42 | + """ |
| 43 | + For removing this sprite from a group internally. |
| 44 | +
|
| 45 | + :param group: The group we are removing from. |
| 46 | + """ |
| 47 | + |
| 48 | + @abstractmethod |
| 49 | + def kill(self): |
| 50 | + """remove the Sprite from all Groups |
| 51 | +
|
| 52 | + Sprite.kill(): return None |
| 53 | +
|
| 54 | + The Sprite is removed from all the Groups that contain it. This won't |
| 55 | + change anything about the state of the Sprite. It is possible to |
| 56 | + continue to use the Sprite after this method has been called, including |
| 57 | + adding it to Groups. |
| 58 | +
|
| 59 | + """ |
| 60 | + |
| 61 | + @abstractmethod |
| 62 | + def groups(self): |
| 63 | + """list of Groups that contain this Sprite |
| 64 | +
|
| 65 | + Sprite.groups(): return group_list |
| 66 | +
|
| 67 | + Returns a list of all the Groups that contain this Sprite. |
| 68 | +
|
| 69 | + """ |
| 70 | + |
| 71 | + @abstractmethod |
| 72 | + def alive(self): |
| 73 | + """does the sprite belong to any groups |
| 74 | +
|
| 75 | + Sprite.alive(): return bool |
| 76 | +
|
| 77 | + Returns True when the Sprite belongs to one or more Groups. |
| 78 | + """ |
| 79 | + |
| 80 | + @abstractmethod |
| 81 | + def _set_visible(self, val): |
| 82 | + """set the visible value (0 or 1) """ |
| 83 | + self._visible = val |
| 84 | + |
| 85 | + @abstractmethod |
| 86 | + def _get_visible(self): |
| 87 | + """return the visible value of that sprite""" |
| 88 | + |
| 89 | + @abstractmethod |
| 90 | + def update(self, time_delta: float): |
| 91 | + """ |
| 92 | + A stub to override. |
| 93 | +
|
| 94 | + :param time_delta: the time passed in seconds between calls to this function. |
| 95 | + """ |
| 96 | + |
| 97 | + @property |
| 98 | + @abstractmethod |
| 99 | + def visible(self): |
| 100 | + """ |
| 101 | + You can make this sprite disappear without removing it from the group |
| 102 | + assign 0 for invisible and 1 for visible |
| 103 | + """ |
| 104 | + |
| 105 | + @visible.setter |
| 106 | + @abstractmethod |
| 107 | + def visible(self, value): |
| 108 | + """ |
| 109 | + :param value: |
| 110 | + """ |
| 111 | + |
| 112 | + @property |
| 113 | + @abstractmethod |
| 114 | + def layer(self): |
| 115 | + """ |
| 116 | + Layer property can only be set before the sprite is added to a group, |
| 117 | + after that it is read only and a sprite's layer in a group should be |
| 118 | + set via the group's change_layer() method. |
| 119 | +
|
| 120 | + Overwrites dynamic property from sprite class for speed. |
| 121 | + """ |
| 122 | + |
| 123 | + @layer.setter |
| 124 | + @abstractmethod |
| 125 | + def layer(self, value): |
| 126 | + """ |
| 127 | + :param value: |
| 128 | + """ |
| 129 | + |
| 130 | + @property |
| 131 | + @abstractmethod |
| 132 | + def image(self): |
| 133 | + """ |
| 134 | + Layer property can only be set before the sprite is added to a group, |
| 135 | + after that it is read only and a sprite's layer in a group should be |
| 136 | + set via the group's change_layer() method. |
| 137 | +
|
| 138 | + Overwrites dynamic property from sprite class for speed. |
| 139 | + """ |
| 140 | + |
| 141 | + @image.setter |
| 142 | + @abstractmethod |
| 143 | + def image(self, value): |
| 144 | + """ |
| 145 | +
|
| 146 | + :param value: |
| 147 | + :return: |
| 148 | + """ |
| 149 | + |
| 150 | + @property |
| 151 | + @abstractmethod |
| 152 | + def rect(self): |
| 153 | + """ |
| 154 | + Layer property can only be set before the sprite is added to a group, |
| 155 | + after that it is read only and a sprite's layer in a group should be |
| 156 | + set via the group's change_layer() method. |
| 157 | +
|
| 158 | + Overwrites dynamic property from sprite class for speed. |
| 159 | + """ |
| 160 | + |
| 161 | + @rect.setter |
| 162 | + @abstractmethod |
| 163 | + def rect(self, value): |
| 164 | + """ |
| 165 | + :param value: |
| 166 | + """ |
| 167 | + |
| 168 | + @property |
| 169 | + @abstractmethod |
| 170 | + def blendmode(self): |
| 171 | + """ |
| 172 | + Layer property can only be set before the sprite is added to a group, |
| 173 | + after that it is read only and a sprite's layer in a group should be |
| 174 | + set via the group's change_layer() method. |
| 175 | +
|
| 176 | + Overwrites dynamic property from sprite class for speed. |
| 177 | + """ |
| 178 | + @blendmode.setter |
| 179 | + @abstractmethod |
| 180 | + def blendmode(self, value): |
| 181 | + """ |
| 182 | + :param value: |
| 183 | + """ |
0 commit comments