Bläddra i källkod

state: include properties

Bastien Sevajol 6 år sedan
förälder
incheckning
2d3b426968
5 ändrade filer med 61 tillägg och 61 borttagningar
  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 Visa fil

@@ -29,7 +29,7 @@ You also need a running redis server (used db number is `0`, soon configurable).
29 29
 
30 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 34
 # Actual keys
35 35
 

+ 2 - 2
maps/001/001.tmx Visa fil

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

+ 30 - 2
maps/001/state1.xml Visa fil

@@ -6,14 +6,42 @@
6 6
     <subjects>
7 7
         <subject>
8 8
             <type>opencombat.simulation.subject.ManSubject</type>
9
-            <position>1,1</position>
9
+            <position>72,7</position>
10 10
             <direction>90</direction>
11 11
             <mode>standup</mode>
12 12
             <side>URSS</side>
13 13
         </subject>
14 14
         <subject>
15 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 45
             <direction>270</direction>
18 46
             <mode>hiding</mode>
19 47
             <side>DE</side>

+ 26 - 8
opencombat/state.py Visa fil

@@ -6,12 +6,18 @@ from lxml import etree
6 6
 
7 7
 from synergine2.config import Config
8 8
 from synergine2.log import get_logger
9
+from synergine2_cocos2d.const import SELECTION_COLOR_RGB
9 10
 
10 11
 from opencombat.exception import StateLoadError
11 12
 from opencombat.simulation.base import TileStrategySimulation
12 13
 from opencombat.simulation.subject import TileSubject
13 14
 from opencombat.util import get_class_from_string_path
14 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 23
 class State(object):
@@ -56,6 +62,8 @@ class State(object):
56 62
         subject: TileSubject,
57 63
         subject_element: Element,
58 64
     ) -> None:
65
+        subject_properties = {}
66
+
59 67
         subject.position = tuple(
60 68
             map(
61 69
                 int,
@@ -66,15 +74,25 @@ class State(object):
66 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 98
 class StateLoader(object):

+ 2 - 48
run.py Visa fil

@@ -5,19 +5,11 @@ from random import seed
5 5
 
6 6
 from synergine2.log import get_default_logger
7 7
 from synergine2.config import Config
8
-from synergine2_cocos2d.const import SELECTION_COLOR_RGB
9 8
 from synergine2_cocos2d.util import get_map_file_path_from_dir
10 9
 from synergine2.core import Core
11 10
 from synergine2.cycle import CycleManager
12 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 13
 from opencombat.simulation.base import TileStrategySimulation
22 14
 from opencombat.simulation.base import TileStrategySubjects
23 15
 from opencombat.state import StateLoaderBuilder
@@ -48,45 +40,6 @@ def main(
48 40
         state = state_loader.get_state(state_file_path)
49 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 43
     simulation.subjects = subjects
91 44
 
92 45
     core = Core(
@@ -112,7 +65,8 @@ if __name__ == '__main__':
112 65
     parser = argparse.ArgumentParser(description='Run TileStrategy')
113 66
     parser.add_argument('map_dir_path', help='map directory path')
114 67
     parser.add_argument('--seed', dest='seed', default=None)
68
+    parser.add_argument('--state', dest='state', default=None)
115 69
 
116 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)