|
12 | 12 | from system.lib.swf import SupercellSWF |
13 | 13 |
|
14 | 14 |
|
| 15 | +CACHE = {} |
| 16 | + |
| 17 | + |
15 | 18 | class MovieClipFrame: |
16 | 19 | def __init__(self): |
17 | 20 | self._elements_count: int = 0 |
@@ -110,6 +113,9 @@ def load(self, swf: "SupercellSWF", tag: int): |
110 | 113 | swf.reader.read(frame_length) |
111 | 114 |
|
112 | 115 | def render(self, swf: "SupercellSWF", matrix=None) -> Image.Image: |
| 116 | + if self in CACHE: |
| 117 | + return CACHE[self].copy() |
| 118 | + |
113 | 119 | matrix_bank = swf.get_matrix_bank(self.matrix_bank_index) |
114 | 120 |
|
115 | 121 | # TODO: make it faster |
@@ -137,6 +143,8 @@ def render(self, swf: "SupercellSWF", matrix=None) -> Image.Image: |
137 | 143 |
|
138 | 144 | image.paste(rendered_shape, (x, y), rendered_shape) |
139 | 145 |
|
| 146 | + CACHE[self] = image |
| 147 | + |
140 | 148 | return image |
141 | 149 |
|
142 | 150 | def get_sides(self, swf: "SupercellSWF") -> Tuple[float, float, float, float]: |
@@ -171,3 +179,7 @@ def get_sides(self, swf: "SupercellSWF") -> Tuple[float, float, float, float]: |
171 | 179 | bottom = max(bottom, shape_bottom) |
172 | 180 |
|
173 | 181 | return left, top, right, bottom |
| 182 | + |
| 183 | + def get_position(self) -> Tuple[float, float]: |
| 184 | + left, top, _, _ = self.get_sides() |
| 185 | + return left, top |
0 commit comments