| Conditions | 9 |
| Total Lines | 73 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | """ |
||
| 36 | def design_render(self, screen: Screen) -> Tuple[int, int, pygame.Surface]: |
||
| 37 | # Get points from fixture else rectangle |
||
| 38 | raw_points = self.__data[2] if self.__data else [[0, 0, 0], [30, 0, 1], [30, 10, 1], [0, 10, 1]] |
||
| 39 | |||
| 40 | # Get largest x/y |
||
| 41 | maxx = max([f[0] for f in raw_points]) |
||
| 42 | maxy = max([f[1] for f in raw_points]) |
||
| 43 | |||
| 44 | # Split the points up into their line groups |
||
| 45 | pen = 6 |
||
| 46 | points = [] |
||
| 47 | for point in raw_points: |
||
| 48 | if point[2] == 0: |
||
| 49 | points.append([]) |
||
| 50 | points[-1].append([point[0] + pen, point[1] + pen]) |
||
| 51 | |||
| 52 | # Generate the surface |
||
| 53 | surface = pygame.Surface((maxx + (pen * 2), maxy + (pen * 2)), pygame.SRCALPHA, 32) |
||
| 54 | surface = surface.convert_alpha() |
||
| 55 | |||
| 56 | # Draw each line group filled |
||
| 57 | for point_set in points: |
||
| 58 | if len(point_set) > 2: |
||
| 59 | pygame.draw.polygon(surface, self.__fill, point_set) |
||
| 60 | |||
| 61 | # Draw each line group outline |
||
| 62 | for point_set in points: |
||
| 63 | if len(point_set) > 1: |
||
| 64 | pygame.draw.lines(surface, self.__outline, True, point_set, pen) |
||
| 65 | |||
| 66 | # Resize |
||
| 67 | """max_size = self.__size |
||
| 68 | x, y = surface.get_size() |
||
| 69 | if x > y: |
||
| 70 | y = y * (max_size / x) |
||
| 71 | x = max_size |
||
| 72 | else: |
||
| 73 | x = x * (max_size / y) |
||
| 74 | y = max_size |
||
| 75 | x, y = int(x), int(y) |
||
| 76 | surface = pygame.transform.scale(surface, (x * screen.block_size, y * screen.block_size))""" |
||
| 77 | x, y = surface.get_size() |
||
| 78 | surface = pygame.transform.scale(surface, ( |
||
| 79 | int(x * self.__size * screen.block_size), int(y * self.__size * screen.block_size))) |
||
| 80 | |||
| 81 | # Rotate |
||
| 82 | surface = pygame.transform.rotate(surface, self.__rotation) |
||
| 83 | |||
| 84 | # Calc pos |
||
| 85 | x, y = surface.get_size() |
||
| 86 | x = int((self._x * screen.block_size) - floor(x / 2)) |
||
| 87 | y = int((self._y * screen.block_size) - floor(y / 2)) |
||
| 88 | |||
| 89 | # Text label |
||
| 90 | if self.__label is not None: |
||
| 91 | # Generate text |
||
| 92 | text = self.__label.design_render(screen)[2] |
||
| 93 | |||
| 94 | # Add to full |
||
| 95 | tx, ty = text.get_size() |
||
| 96 | fx, fy = surface.get_size() |
||
| 97 | new_surface = pygame.Surface((tx + fx + 3, max(ty, fy + ty / 2)), pygame.SRCALPHA, 32) |
||
| 98 | new_surface = new_surface.convert_alpha() |
||
| 99 | new_surface.blit(surface, (0, new_surface.get_height() - fy)) |
||
| 100 | new_surface.blit(text, (fx + 3, 0)) |
||
| 101 | |||
| 102 | # Update pos |
||
| 103 | y -= (new_surface.get_height() - fy) |
||
| 104 | else: |
||
| 105 | new_surface = surface |
||
| 106 | |||
| 107 | # Render |
||
| 108 | return x, y, new_surface |
||
| 109 |