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