Pull SelectableSurfActor out of vehicles.
[koperkapel.git] / koperkapel / actors / orientatedsurf.py
1 """ Actor that takes a surface. """
2
3 from pygame.transform import rotate
4 from pgzero.actor import POS_TOPLEFT, ANCHOR_CENTER
5
6 from .surf import SurfActor
7 from ..constants import TILE_SIZE
8
9
10 class OrientatedSurfActor(SurfActor):
11     def __init__(self, surf, pos=POS_TOPLEFT, anchor=ANCHOR_CENTER, angle=0,
12                  **kwargs):
13         self._handle_unexpected_kwargs(kwargs)
14
15         self._angle = angle
16         self._base_surf = surf
17         super().__init__(surf, pos, anchor)
18         self._init_position(pos, anchor, **kwargs)
19
20     @property
21     def angle(self):
22         return self._angle
23
24     @angle.setter
25     def angle(self, angle):
26         cur_anchor = self._anchor_value
27         if angle not in (self._angle, self._angle + 180, self._angle - 180):
28             self._anchor_value = (cur_anchor[1], cur_anchor[0])
29         self._angle = angle
30         self._surf = self._orig_surf = rotate(self._base_surf, angle)
31
32     @property
33     def surf(self):
34         """ The original surface displaying the actor. """
35         return self._orig_surf
36
37     @surf.setter
38     def surf(self, surf):
39         self._base_surf = surf
40         self._orig_surf = self._surf = rotate(surf, self._angle)
41         self._update_pos()
42
43
44 class SelectableSurfActor(OrientatedSurfActor):
45     def __init__(self, seat, selected_seat):
46         self._selected = False
47         self._seat = seat
48         self._selected_seat = selected_seat
49         super().__init__(surf=self._seat, angle=0)
50
51     @property
52     def selected(self):
53         return self._selected
54
55     @selected.setter
56     def selected(self, value):
57         self._selected = value
58         self.surf = self._selected_seat if value else self._seat