|
1 | | -from enum import IntEnum |
| 1 | +from enum import IntEnum, IntFlag |
2 | 2 |
|
3 | 3 | from PIL import Image, ImageDraw |
4 | 4 |
|
5 | 5 | from .Texture2DConverter import get_image_from_texture2d |
6 | | -from ..enums import ClassIDType |
| 6 | +from ..enums import ClassIDType, SpritePackingMode, SpritePackingRotation |
7 | 7 | from ..streams import EndianBinaryReader |
8 | 8 |
|
9 | 9 |
|
10 | | -# should be imported from Sprite, but too lazy to fix the import issues caused by that |
11 | | -class SpritePackingRotation(IntEnum): |
12 | | - kSPRNone = (0,) |
13 | | - kSPRFlipHorizontal = (1,) |
14 | | - kSPRFlipVertical = (2,) |
15 | | - kSPRRotate180 = (3,) |
16 | | - kSPRRotate90 = 4 |
17 | | - |
18 | | - |
19 | | -class SpritePackingMode(IntEnum): |
20 | | - kSPMTight = (0,) |
21 | | - kSPMRectangle = 1 |
22 | | - |
23 | | - |
24 | 10 | def get_image(sprite, texture, alpha_texture) -> Image: |
25 | | - if alpha_texture and getattr(alpha_texture, "type", ClassIDType.UnknownType) == ClassIDType.Texture2D: |
| 11 | + if ( |
| 12 | + alpha_texture |
| 13 | + and getattr(alpha_texture, "type", ClassIDType.UnknownType) |
| 14 | + == ClassIDType.Texture2D |
| 15 | + ): |
26 | 16 | cache_id = (texture.path_id, alpha_texture.path_id) |
27 | 17 | if cache_id not in sprite.assets_file._cache: |
28 | 18 | original_image = get_image_from_texture2d(texture.read(), False) |
@@ -65,7 +55,12 @@ def get_image_from_sprite(m_Sprite) -> Image: |
65 | 55 | original_image = get_image(m_Sprite, m_Texture2D, alpha_texture) |
66 | 56 |
|
67 | 57 | sprite_image = original_image.crop( |
68 | | - (texture_rect.x, texture_rect.y, texture_rect.x + texture_rect.width, texture_rect.y + texture_rect.height) |
| 58 | + ( |
| 59 | + texture_rect.x, |
| 60 | + texture_rect.y, |
| 61 | + texture_rect.x + texture_rect.width, |
| 62 | + texture_rect.y + texture_rect.height, |
| 63 | + ) |
69 | 64 | ) |
70 | 65 |
|
71 | 66 | if settings_raw.packed == 1: |
|
0 commit comments