소스 검색

Update middleware.py

Bastien Sevajol 6 년 전
부모
커밋
fd02270ed8
No account linked to committer's email
1개의 변경된 파일15개의 추가작업 그리고 8개의 파일을 삭제
  1. 15 8
      synergine2_cocos2d/middleware.py

+ 15 - 8
synergine2_cocos2d/middleware.py 파일 보기

@@ -1,11 +1,14 @@
1 1
 # coding: utf-8
2 2
 import os
3
+import typing
3 4
 
4
-import cocos
5 5
 from synergine2.config import Config
6 6
 from synergine2.log import get_logger
7 7
 from synergine2_cocos2d.util import get_map_file_path_from_dir
8 8
 
9
+if typing.TYPE_CHECKING:
10
+    import cocos
11
+
9 12
 
10 13
 class MapMiddleware(object):
11 14
     def __init__(
@@ -22,16 +25,20 @@ class MapMiddleware(object):
22 25
         return get_map_file_path_from_dir(self.map_dir_path)
23 26
 
24 27
     def init(self) -> None:
28
+        # import cocos here for prevent test crash when no X server is
29
+        # present
30
+        import cocos
31
+
25 32
         map_file_path = self.get_map_file_path()
26 33
         self.tmx = cocos.tiles.load(map_file_path)
27 34
 
28
-    def get_background_sprite(self) -> cocos.sprite.Sprite:
35
+    def get_background_sprite(self) -> 'cocos.sprite.Sprite':
29 36
         raise NotImplementedError()
30 37
 
31
-    def get_ground_layer(self) -> cocos.tiles.RectMapLayer:
38
+    def get_ground_layer(self) -> 'cocos.tiles.RectMapLayer':
32 39
         raise NotImplementedError()
33 40
 
34
-    def get_top_layer(self) -> cocos.tiles.RectMapLayer:
41
+    def get_top_layer(self) -> 'cocos.tiles.RectMapLayer':
35 42
         raise NotImplementedError()
36 43
 
37 44
     def get_world_height(self) -> int:
@@ -48,25 +55,25 @@ class MapMiddleware(object):
48 55
 
49 56
 
50 57
 class TMXMiddleware(MapMiddleware):
51
-    def get_background_sprite(self) -> cocos.sprite.Sprite:
58
+    def get_background_sprite(self) -> 'cocos.sprite.Sprite':
52 59
         # TODO: Extract it from tmx
53 60
         return cocos.sprite.Sprite(os.path.join(
54 61
             self.map_dir_path,
55 62
             'background.png',
56 63
         ))
57 64
 
58
-    def get_interior_sprite(self) -> cocos.sprite.Sprite:
65
+    def get_interior_sprite(self) -> 'cocos.sprite.Sprite':
59 66
         # TODO: Extract it from tmx
60 67
         return cocos.sprite.Sprite(os.path.join(
61 68
             self.map_dir_path,
62 69
             'background_interiors.png',
63 70
         ))
64 71
 
65
-    def get_ground_layer(self) -> cocos.tiles.RectMapLayer:
72
+    def get_ground_layer(self) -> 'cocos.tiles.RectMapLayer':
66 73
         assert self.tmx
67 74
         return self.tmx['ground']
68 75
 
69
-    def get_top_layer(self) -> cocos.tiles.RectMapLayer:
76
+    def get_top_layer(self) -> 'cocos.tiles.RectMapLayer':
70 77
         assert self.tmx
71 78
         return self.tmx['top']
72 79