浏览代码

state: include properties

Bastien Sevajol 7 年前
父节点
当前提交
2d3b426968
共有 5 个文件被更改,包括 61 次插入61 次删除
  1. 1 1
      README.md
  2. 2 2
      maps/001/001.tmx
  3. 30 2
      maps/001/state1.xml
  4. 26 8
      opencombat/state.py
  5. 2 48
      run.py

+ 1 - 1
README.md 查看文件

29
 
29
 
30
 Example run:
30
 Example run:
31
 
31
 
32
-    python run.py maps/003
32
+    python run.py maps/001 --state maps/001/state1.xml
33
 
33
 
34
 # Actual keys
34
 # Actual keys
35
 
35
 

+ 2 - 2
maps/001/001.tmx 查看文件

4
  <tileset firstgid="82" source="../shared/tilesets/terrain.tsx"/>
4
  <tileset firstgid="82" source="../shared/tilesets/terrain.tsx"/>
5
  <tileset firstgid="131" source="../shared/tilesets/interiors.tsx"/>
5
  <tileset firstgid="131" source="../shared/tilesets/interiors.tsx"/>
6
  <imagelayer name="interior">
6
  <imagelayer name="interior">
7
-  <image source="001i.png" width="1024" height="512"/>
7
+  <image source="background_interior.png" width="1024" height="512"/>
8
  </imagelayer>
8
  </imagelayer>
9
  <imagelayer name="background" visible="0">
9
  <imagelayer name="background" visible="0">
10
-  <image source="001.png" width="1024" height="512"/>
10
+  <image source="background.png" width="1024" height="512"/>
11
  </imagelayer>
11
  </imagelayer>
12
  <layer name="top" width="128" height="64">
12
  <layer name="top" width="128" height="64">
13
   <data encoding="csv">
13
   <data encoding="csv">

+ 30 - 2
maps/001/state1.xml 查看文件

6
     <subjects>
6
     <subjects>
7
         <subject>
7
         <subject>
8
             <type>opencombat.simulation.subject.ManSubject</type>
8
             <type>opencombat.simulation.subject.ManSubject</type>
9
-            <position>1,1</position>
9
+            <position>72,7</position>
10
             <direction>90</direction>
10
             <direction>90</direction>
11
             <mode>standup</mode>
11
             <mode>standup</mode>
12
             <side>URSS</side>
12
             <side>URSS</side>
13
         </subject>
13
         </subject>
14
         <subject>
14
         <subject>
15
             <type>opencombat.simulation.subject.ManSubject</type>
15
             <type>opencombat.simulation.subject.ManSubject</type>
16
-            <position>10,10</position>
16
+            <position>72,9</position>
17
+            <direction>90</direction>
18
+            <mode>standup</mode>
19
+            <side>URSS</side>
20
+        </subject>
21
+        <subject>
22
+            <type>opencombat.simulation.subject.ManSubject</type>
23
+            <position>72,11</position>
24
+            <direction>90</direction>
25
+            <mode>standup</mode>
26
+            <side>URSS</side>
27
+        </subject>
28
+        <subject>
29
+            <type>opencombat.simulation.subject.ManSubject</type>
30
+            <position>58,54</position>
31
+            <direction>270</direction>
32
+            <mode>hiding</mode>
33
+            <side>DE</side>
34
+        </subject>
35
+        <subject>
36
+            <type>opencombat.simulation.subject.ManSubject</type>
37
+            <position>58,56</position>
38
+            <direction>270</direction>
39
+            <mode>hiding</mode>
40
+            <side>DE</side>
41
+        </subject>
42
+        <subject>
43
+            <type>opencombat.simulation.subject.ManSubject</type>
44
+            <position>58,58</position>
17
             <direction>270</direction>
45
             <direction>270</direction>
18
             <mode>hiding</mode>
46
             <mode>hiding</mode>
19
             <side>DE</side>
47
             <side>DE</side>

+ 26 - 8
opencombat/state.py 查看文件

6
 
6
 
7
 from synergine2.config import Config
7
 from synergine2.config import Config
8
 from synergine2.log import get_logger
8
 from synergine2.log import get_logger
9
+from synergine2_cocos2d.const import SELECTION_COLOR_RGB
9
 
10
 
10
 from opencombat.exception import StateLoadError
11
 from opencombat.exception import StateLoadError
11
 from opencombat.simulation.base import TileStrategySimulation
12
 from opencombat.simulation.base import TileStrategySimulation
12
 from opencombat.simulation.subject import TileSubject
13
 from opencombat.simulation.subject import TileSubject
13
 from opencombat.util import get_class_from_string_path
14
 from opencombat.util import get_class_from_string_path
14
 from opencombat.util import get_text_xml_element
15
 from opencombat.util import get_text_xml_element
16
+from opencombat.const import FLAG, SIDE
17
+from opencombat.const import FLAG_DE
18
+from opencombat.const import DE_COLOR
19
+from opencombat.const import URSS_COLOR
20
+from opencombat.const import FLAG_URSS
15
 
21
 
16
 
22
 
17
 class State(object):
23
 class State(object):
56
         subject: TileSubject,
62
         subject: TileSubject,
57
         subject_element: Element,
63
         subject_element: Element,
58
     ) -> None:
64
     ) -> None:
65
+        subject_properties = {}
66
+
59
         subject.position = tuple(
67
         subject.position = tuple(
60
             map(
68
             map(
61
                 int,
69
                 int,
66
             get_text_xml_element(subject_element, 'direction'),
74
             get_text_xml_element(subject_element, 'direction'),
67
         )
75
         )
68
 
76
 
69
-        """
70
-        TODO:
77
+        side = get_text_xml_element(subject_element, 'side')
78
+        if side == 'DE':
79
+            subject_properties.update({
80
+                SELECTION_COLOR_RGB: DE_COLOR,
81
+                FLAG: FLAG_DE,
82
+                SIDE: 'AXIS',
83
+            })
84
+        elif side == 'URSS':
85
+            subject_properties.update({
86
+                SELECTION_COLOR_RGB: URSS_COLOR,
87
+                FLAG: FLAG_URSS,
88
+                SIDE: 'ALLIES',
89
+            })
90
+        else:
91
+            raise NotImplementedError('Don\'t know "{}" side'.format(
92
+                side,
93
+            ))
71
 
94
 
72
-        properties={
73
-                 SELECTION_COLOR_RGB: DE_COLOR,
74
-                 FLAG: FLAG_DE,
75
-                 SIDE: 'AXIS',
76
-             }
77
-        """
95
+        subject.properties = subject_properties
78
 
96
 
79
 
97
 
80
 class StateLoader(object):
98
 class StateLoader(object):

+ 2 - 48
run.py 查看文件

5
 
5
 
6
 from synergine2.log import get_default_logger
6
 from synergine2.log import get_default_logger
7
 from synergine2.config import Config
7
 from synergine2.config import Config
8
-from synergine2_cocos2d.const import SELECTION_COLOR_RGB
9
 from synergine2_cocos2d.util import get_map_file_path_from_dir
8
 from synergine2_cocos2d.util import get_map_file_path_from_dir
10
 from synergine2.core import Core
9
 from synergine2.core import Core
11
 from synergine2.cycle import CycleManager
10
 from synergine2.cycle import CycleManager
12
 from synergine2.terminals import TerminalManager
11
 from synergine2.terminals import TerminalManager
13
 
12
 
14
-from opencombat.const import FLAG, SIDE
15
-from opencombat.const import FLAG_DE
16
-from opencombat.const import DE_COLOR
17
-from opencombat.const import URSS_COLOR
18
-from opencombat.const import FLAG_URSS
19
-from opencombat.simulation.subject import ManSubject
20
-from opencombat.simulation.subject import TankSubject
21
 from opencombat.simulation.base import TileStrategySimulation
13
 from opencombat.simulation.base import TileStrategySimulation
22
 from opencombat.simulation.base import TileStrategySubjects
14
 from opencombat.simulation.base import TileStrategySubjects
23
 from opencombat.state import StateLoaderBuilder
15
 from opencombat.state import StateLoaderBuilder
48
         state = state_loader.get_state(state_file_path)
40
         state = state_loader.get_state(state_file_path)
49
         subjects.extend(state.subjects)
41
         subjects.extend(state.subjects)
50
 
42
 
51
-    # for position in ((10, 2), (11, 3), (11, 4), (12, 5),):
52
-    #     man = ManSubject(
53
-    #         config=config,
54
-    #         simulation=simulation,
55
-    #         position=position,
56
-    #         properties={
57
-    #             SELECTION_COLOR_RGB: DE_COLOR,
58
-    #             FLAG: FLAG_DE,
59
-    #             SIDE: 'AXIS',
60
-    #         }
61
-    #     )
62
-    #     subjects.append(man)
63
-    #
64
-    # for position in ((30, 15), (31, 16), (32, 17), (33, 18),):
65
-    #     man = ManSubject(
66
-    #         config=config,
67
-    #         simulation=simulation,
68
-    #         position=position,
69
-    #         properties={
70
-    #             SELECTION_COLOR_RGB: URSS_COLOR,
71
-    #             FLAG: FLAG_URSS,
72
-    #             SIDE: 'ALLIES',
73
-    #         }
74
-    #     )
75
-    #     subjects.append(man)
76
-    #
77
-    # for position in ((38, 24),):
78
-    #     man = TankSubject(
79
-    #         config=config,
80
-    #         simulation=simulation,
81
-    #         position=position,
82
-    #         properties={
83
-    #             SELECTION_COLOR_RGB: URSS_COLOR,
84
-    #             FLAG: FLAG_URSS,
85
-    #             SIDE: 'ALLIES',
86
-    #         }
87
-    #     )
88
-    #     subjects.append(man)
89
-
90
     simulation.subjects = subjects
43
     simulation.subjects = subjects
91
 
44
 
92
     core = Core(
45
     core = Core(
112
     parser = argparse.ArgumentParser(description='Run TileStrategy')
65
     parser = argparse.ArgumentParser(description='Run TileStrategy')
113
     parser.add_argument('map_dir_path', help='map directory path')
66
     parser.add_argument('map_dir_path', help='map directory path')
114
     parser.add_argument('--seed', dest='seed', default=None)
67
     parser.add_argument('--seed', dest='seed', default=None)
68
+    parser.add_argument('--state', dest='state', default=None)
115
 
69
 
116
     args = parser.parse_args()
70
     args = parser.parse_args()
117
 
71
 
118
-    main(args.map_dir_path, seed_value=args.seed)
72
+    main(args.map_dir_path, seed_value=args.seed, state_file_path=args.state)