Browse Source

Actor image computing

Bastien Sevajol 6 years ago
parent
commit
43eaea355a
3 changed files with 15 additions and 3 deletions
  1. 1 0
      requirements.txt
  2. 1 0
      setup.py
  3. 13 3
      synergine2_cocos2d/actor.py

+ 1 - 0
requirements.txt View File

@@ -15,3 +15,4 @@ redis==2.10.6
15 15
 six==1.11.0
16 16
 tmx==1.9.1
17 17
 pytest-mock==1.6.3
18
+Pillow==5.0.0

+ 1 - 0
setup.py View File

@@ -15,6 +15,7 @@ xyz_require = [
15 15
 ]
16 16
 cocos2d_require = [
17 17
     'cocos2d',
18
+    'Pillow',
18 19
 ] + xyz_require
19 20
 tests_require = [
20 21
     'pytest',

+ 13 - 3
synergine2_cocos2d/actor.py View File

@@ -5,7 +5,7 @@ import typing
5 5
 import ntpath
6 6
 
7 7
 import pyglet
8
-
8
+from PIL import Image
9 9
 import cocos
10 10
 from cocos import collision_model
11 11
 from cocos import euclid
@@ -65,17 +65,27 @@ class Actor(AnimatedInterface, cocos.sprite.Sprite):
65 65
     def build_default_image(self, subject_id: int, base_image_path: str) -> str:
66 66
         cache_dir = self.config.resolve('global.cache_dir_path')
67 67
         with open(base_image_path, 'rb') as base_image_file:
68
+            base_image = Image.open(base_image_file)
69
+
70
+            for default_appliable_image in self.get_default_appliable_images():
71
+                base_image.paste(
72
+                    default_appliable_image,
73
+                    (0, 0),
74
+                    default_appliable_image,
75
+                )
68 76
 
69 77
             final_name = '_'.join([
70 78
                 str(subject_id),
71 79
                 ntpath.basename(base_image_path),
72 80
             ])
73 81
             final_path = os.path.join(cache_dir, final_name)
74
-            with open(final_path, 'wb+') as built_image_file:
75
-                built_image_file.write(base_image_file.read())
82
+            base_image.save(final_path)
76 83
 
77 84
         return final_path
78 85
 
86
+    def get_default_appliable_images(self) -> typing.List[Image.Image]:
87
+        return []
88
+
79 89
     def freeze(self) -> None:
80 90
         """
81 91
         Set object to freeze mode: No visual modification can be done anymore