Browse Source

troops in map for placement

Bastien Sevajol 5 years ago
parent
commit
c88bc1655c

+ 1 - 1
README.md View File

33
 
33
 
34
 Start troops selection GUI with:
34
 Start troops selection GUI with:
35
 
35
 
36
-    python select_troops.py --country URSS --country DE
36
+    python select_troops.py --country USSR --country DE
37
 
37
 
38
 Select troops for every countries then generate s troops file.
38
 Select troops for every countries then generate s troops file.
39
 
39
 

+ 3 - 3
maps/001/state1.xml View File

16
                 </item>
16
                 </item>
17
                 <item>
17
                 <item>
18
                     <key>FLAG</key>
18
                     <key>FLAG</key>
19
-                    <value>FLAG_URSS</value>
19
+                    <value>FLAG_USSR</value>
20
                 </item>
20
                 </item>
21
                 <item>
21
                 <item>
22
                     <key>SIDE</key>
22
                     <key>SIDE</key>
36
                 </item>
36
                 </item>
37
                 <item>
37
                 <item>
38
                     <key>FLAG</key>
38
                     <key>FLAG</key>
39
-                    <value>FLAG_URSS</value>
39
+                    <value>FLAG_USSR</value>
40
                 </item>
40
                 </item>
41
                 <item>
41
                 <item>
42
                     <key>SIDE</key>
42
                     <key>SIDE</key>
56
                 </item>
56
                 </item>
57
                 <item>
57
                 <item>
58
                     <key>FLAG</key>
58
                     <key>FLAG</key>
59
-                    <value>FLAG_URSS</value>
59
+                    <value>FLAG_USSR</value>
60
                 </item>
60
                 </item>
61
                 <item>
61
                 <item>
62
                     <key>SIDE</key>
62
                     <key>SIDE</key>

+ 11 - 2
opencombat/const.py View File

2
 
2
 
3
 COLLECTION_ALIVE = 'ALIVE'
3
 COLLECTION_ALIVE = 'ALIVE'
4
 
4
 
5
+SELECTION_COLOR_RGB = 'SELECTION_COLOR_RGB'
6
+
5
 FLAG = 'FLAG'
7
 FLAG = 'FLAG'
6
 FLAG_DE = 'FLAG_DE'
8
 FLAG_DE = 'FLAG_DE'
7
-FLAG_URSS = 'FLAG_URSS'
9
+FLAG_USSR = 'FLAG_USSR'
8
 
10
 
9
 SIDE = 'SIDE'
11
 SIDE = 'SIDE'
12
+SIDE_ALLIES = 'SIDE_ALLIES'
13
+SIDE_AXIS = 'SIDE_ALLIES'
14
+
15
+COUNTRY = 'COUNTRY'
16
+COUNTRY_USSR = 'USSR'
17
+COUNTRY_DE = 'DE'
18
+
10
 COMBAT_MODE = 'COMBAT_MODE'
19
 COMBAT_MODE = 'COMBAT_MODE'
11
 COMBAT_MODE_DEFEND = 'COMBAT_MODE_DEFEND'
20
 COMBAT_MODE_DEFEND = 'COMBAT_MODE_DEFEND'
12
 COMBAT_MODE_HIDE = 'COMBAT_MODE_HIDE'
21
 COMBAT_MODE_HIDE = 'COMBAT_MODE_HIDE'
13
 
22
 
14
 DE_COLOR = (0, 81, 211)
23
 DE_COLOR = (0, 81, 211)
15
-URSS_COLOR = (204, 0, 0)
24
+USSR_COLOR = (204, 0, 0)

+ 1 - 1
opencombat/game/const.py View File

6
 FLAG_COLORS = {
6
 FLAG_COLORS = {
7
     FLAG_DE
7
     FLAG_DE
8
 }
8
 }
9
-FLAG_URSS = 'URSS'
9
+FLAG_USSR = 'USSR'

+ 26 - 0
opencombat/simulation/base.py View File

1
 # coding: utf-8
1
 # coding: utf-8
2
 from opencombat.const import COLLECTION_ALIVE
2
 from opencombat.const import COLLECTION_ALIVE
3
+from opencombat.const import COUNTRY_USSR
4
+from opencombat.const import FLAG_USSR
5
+from opencombat.const import SIDE_ALLIES
6
+from opencombat.const import COUNTRY_DE
7
+from opencombat.const import USSR_COLOR
8
+from opencombat.const import DE_COLOR
9
+from opencombat.const import SIDE
10
+from opencombat.const import FLAG
11
+from opencombat.const import SELECTION_COLOR_RGB
3
 from opencombat.simulation.physics import TilePhysics
12
 from opencombat.simulation.physics import TilePhysics
4
 from synergine2.config import Config
13
 from synergine2.config import Config
5
 from synergine2.simulation import SubjectBehaviour
14
 from synergine2.simulation import SubjectBehaviour
14
 
23
 
15
     ]
24
     ]
16
 
25
 
26
+    @classmethod
27
+    def get_default_properties_for_country(cls, country: str) -> dict:
28
+        if country == COUNTRY_USSR:
29
+            return {
30
+                SELECTION_COLOR_RGB: USSR_COLOR,
31
+                FLAG: FLAG_USSR,
32
+                SIDE: SIDE_ALLIES,
33
+            }
34
+        elif country == COUNTRY_DE:
35
+            return {
36
+                SELECTION_COLOR_RGB: DE_COLOR,
37
+                FLAG: FLAG_USSR,
38
+                SIDE: SIDE_ALLIES,
39
+            }
40
+
41
+        raise NotImplementedError('Unknown country "{}"'.format(country))
42
+
17
     def __init__(
43
     def __init__(
18
         self,
44
         self,
19
         config: Config,
45
         config: Config,

+ 9 - 6
opencombat/state.py View File

14
 from opencombat.util import pretty_xml
14
 from opencombat.util import pretty_xml
15
 from opencombat.util import get_text_xml_element
15
 from opencombat.util import get_text_xml_element
16
 from opencombat.xml import XmlValidator
16
 from opencombat.xml import XmlValidator
17
+from opencombat.const import SIDE
18
+from opencombat.const import FLAG
19
+from opencombat.const import SELECTION_COLOR_RGB
17
 
20
 
18
 
21
 
19
 class State(object):
22
 class State(object):
93
 
96
 
94
     def _get_decode_properties_map(self) -> typing.Dict[str, typing.Callable[[str], typing.Any]]:  # nopep8
97
     def _get_decode_properties_map(self) -> typing.Dict[str, typing.Callable[[str], typing.Any]]:  # nopep8
95
         return {
98
         return {
96
-            'SELECTION_COLOR_RGB': lambda v: tuple(map(int, v.split(','))),
97
-            'FLAG': str,
98
-            'SIDE': str,
99
+            SELECTION_COLOR_RGB: lambda v: tuple(map(int, v.split(','))),
100
+            FLAG: str,
101
+            SIDE: str,
99
         }
102
         }
100
 
103
 
101
 
104
 
179
 
182
 
180
     def _get_encode_properties_map(self) -> typing.Dict[str, typing.Callable[[typing.Any], str]]:  # nopep8:
183
     def _get_encode_properties_map(self) -> typing.Dict[str, typing.Callable[[typing.Any], str]]:  # nopep8:
181
         return {
184
         return {
182
-            'SELECTION_COLOR_RGB': lambda v: ','.join(map(str, v)),
183
-            'FLAG': str,
184
-            'SIDE': str,
185
+            SELECTION_COLOR_RGB: lambda v: ','.join(map(str, v)),
186
+            FLAG: str,
187
+            SIDE: str,
185
         }
188
         }
186
 
189
 
187
 
190
 

+ 2 - 2
opencombat/strategy/teams.xml View File

1
 <?xml version="1.0" encoding="UTF-8"?>
1
 <?xml version="1.0" encoding="UTF-8"?>
2
 <teams>
2
 <teams>
3
-    <team id="std_team" country="URSS">
4
-        <name>Standard URSS team</name>
3
+    <team id="std_team" country="USSR">
4
+        <name>Standard USSR team</name>
5
         <units>
5
         <units>
6
             <unit>
6
             <unit>
7
                 <id>std_soldier</id>
7
                 <id>std_soldier</id>

+ 5 - 1
opencombat/strategy/troops.py View File

60
 
60
 
61
             for unit in team.units:
61
             for unit in team.units:
62
                 subject = unit.class_(self._config, self._simulation)
62
                 subject = unit.class_(self._config, self._simulation)
63
+                properties = \
64
+                    self._simulation.get_default_properties_for_country(
65
+                        country,
66
+                    )
67
+                subject.properties.update(properties)
63
                 subjects.append(subject)
68
                 subjects.append(subject)
64
 
69
 
65
-        # TODO BS 2018-06-25: place subjects on map, set side, color, etc
66
         return subjects
70
         return subjects
67
 
71
 
68
 
72
 

+ 1 - 1
opencombat/strategy/units.xml View File

1
 <?xml version="1.0" encoding="UTF-8"?>
1
 <?xml version="1.0" encoding="UTF-8"?>
2
 <units>
2
 <units>
3
-    <unit id="std_soldier" country="URSS">
3
+    <unit id="std_soldier" country="USSR">
4
         <name>Standard soldier</name>
4
         <name>Standard soldier</name>
5
         <type>opencombat.simulation.subject.ManSubject</type>
5
         <type>opencombat.simulation.subject.ManSubject</type>
6
     </unit>
6
     </unit>

+ 9 - 0
select_troops.py View File

1
 # coding: utf-8
1
 # coding: utf-8
2
 import argparse
2
 import argparse
3
+import sys
3
 import typing
4
 import typing
4
 from tkinter import Tk
5
 from tkinter import Tk
5
 
6
 
62
     )
63
     )
63
     args = parser.parse_args()
64
     args = parser.parse_args()
64
 
65
 
66
+    if not args.countries:
67
+        print(
68
+            'You must choose one or more countries with parameters '
69
+            '--country, eg. `--country USSR --country DE`',
70
+            file=sys.stderr,
71
+        )
72
+        exit(1)
73
+
65
     main(
74
     main(
66
         units_file_path=args.units_file_path,
75
         units_file_path=args.units_file_path,
67
         teams_file_path=args.teams_file_path,
76
         teams_file_path=args.teams_file_path,

+ 1 - 1
tests/fixtures/state_ok.xml View File

16
                 </item>
16
                 </item>
17
                 <item>
17
                 <item>
18
                     <key>FLAG</key>
18
                     <key>FLAG</key>
19
-                    <value>FLAG_URSS</value>
19
+                    <value>FLAG_USSR</value>
20
                 </item>
20
                 </item>
21
                 <item>
21
                 <item>
22
                     <key>SIDE</key>
22
                     <key>SIDE</key>

+ 2 - 2
tests/fixtures/teams.xml View File

1
 <?xml version="1.0" encoding="UTF-8"?>
1
 <?xml version="1.0" encoding="UTF-8"?>
2
 <teams>
2
 <teams>
3
-    <team id="std_team" country="URSS">
4
-        <name>Standard URSS team</name>
3
+    <team id="std_team" country="USSR">
4
+        <name>Standard USSR team</name>
5
         <units>
5
         <units>
6
             <unit>
6
             <unit>
7
                 <id>std_soldier</id>
7
                 <id>std_soldier</id>

+ 1 - 1
tests/fixtures/units.xml View File

1
 <?xml version="1.0" encoding="UTF-8"?>
1
 <?xml version="1.0" encoding="UTF-8"?>
2
 <units>
2
 <units>
3
-    <unit id="std_soldier" country="URSS">
3
+    <unit id="std_soldier" country="USSR">
4
         <name>Standard soldier</name>
4
         <name>Standard soldier</name>
5
         <type>opencombat.simulation.subject.ManSubject</type>
5
         <type>opencombat.simulation.subject.ManSubject</type>
6
     </unit>
6
     </unit>

+ 3 - 3
tests/strategy/test_teams.py View File

46
 
46
 
47
     assert 'std_team' == stash.teams[0].id
47
     assert 'std_team' == stash.teams[0].id
48
     assert 'Standard team' == stash.teams[0].name
48
     assert 'Standard team' == stash.teams[0].name
49
-    assert 'URSS' == stash.teams[0].country
49
+    assert 'USSR' == stash.teams[0].country
50
     assert stash.teams[0].units
50
     assert stash.teams[0].units
51
     assert 4 == len(stash.teams[0].units)
51
     assert 4 == len(stash.teams[0].units)
52
     assert isinstance(stash.teams[0].units[0], UnitModel)
52
     assert isinstance(stash.teams[0].units[0], UnitModel)
76
         'tests/fixtures/teams.xml',
76
         'tests/fixtures/teams.xml',
77
         unit_stash=unit_stash,
77
         unit_stash=unit_stash,
78
     )
78
     )
79
-    assert stash.get_team('std_team', 'URSS')
79
+    assert stash.get_team('std_team', 'USSR')
80
 
80
 
81
 
81
 
82
 def test_teams_stash__error__get_team_wrong_country(
82
 def test_teams_stash__error__get_team_wrong_country(
104
     )
104
     )
105
 
105
 
106
     with pytest.raises(NotFoundException):
106
     with pytest.raises(NotFoundException):
107
-        stash.get_team('unknown', 'URSS')
107
+        stash.get_team('unknown', 'USSR')

+ 3 - 3
tests/strategy/test_units.py View File

31
 
31
 
32
     assert 'std_soldier' == stash.units[0].id
32
     assert 'std_soldier' == stash.units[0].id
33
     assert 'Standard soldier' == stash.units[0].name
33
     assert 'Standard soldier' == stash.units[0].name
34
-    assert 'URSS' == stash.units[0].country
34
+    assert 'USSR' == stash.units[0].country
35
     assert ManSubject == stash.units[0].class_
35
     assert ManSubject == stash.units[0].class_
36
 
36
 
37
     assert 'std_soldier' == stash.units[1].id
37
     assert 'std_soldier' == stash.units[1].id
47
         config,
47
         config,
48
         'tests/fixtures/units.xml',
48
         'tests/fixtures/units.xml',
49
     )
49
     )
50
-    assert stash.get_unit('std_soldier', 'URSS')
50
+    assert stash.get_unit('std_soldier', 'USSR')
51
 
51
 
52
 
52
 
53
 def test_units_stash__error__get_unit_wrong_country(
53
 def test_units_stash__error__get_unit_wrong_country(
71
     )
71
     )
72
 
72
 
73
     with pytest.raises(NotFoundException):
73
     with pytest.raises(NotFoundException):
74
-        stash.get_unit('unknown', 'URSS')
74
+        stash.get_unit('unknown', 'USSR')

+ 10 - 8
tests/test_state.py View File

16
 from opencombat.const import SIDE
16
 from opencombat.const import SIDE
17
 from opencombat.const import FLAG_DE
17
 from opencombat.const import FLAG_DE
18
 from opencombat.const import DE_COLOR
18
 from opencombat.const import DE_COLOR
19
-from opencombat.const import URSS_COLOR
20
-from opencombat.const import FLAG_URSS
19
+from opencombat.const import USSR_COLOR
20
+from opencombat.const import FLAG_USSR
21
+from opencombat.const import SIDE_ALLIES
22
+from opencombat.const import SIDE_AXIS
21
 
23
 
22
 
24
 
23
 class MyStateLoader(StateLoader):
25
 class MyStateLoader(StateLoader):
44
     man1.properties = OrderedDict([
46
     man1.properties = OrderedDict([
45
         (SELECTION_COLOR_RGB, DE_COLOR),
47
         (SELECTION_COLOR_RGB, DE_COLOR),
46
         (FLAG, FLAG_DE),
48
         (FLAG, FLAG_DE),
47
-        (SIDE, 'AXIS'),
49
+        (SIDE, SIDE_AXIS),
48
     ])
50
     ])
49
 
51
 
50
     man2 = ManSubject(config, simulation)
52
     man2 = ManSubject(config, simulation)
51
     man2.position = (16, 8)
53
     man2.position = (16, 8)
52
     man2.direction = 197
54
     man2.direction = 197
53
     man2.properties = OrderedDict([
55
     man2.properties = OrderedDict([
54
-        (SELECTION_COLOR_RGB, URSS_COLOR),
55
-        (FLAG, FLAG_URSS),
56
-        (SIDE, 'ALLIES'),
56
+        (SELECTION_COLOR_RGB, USSR_COLOR),
57
+        (FLAG, FLAG_USSR),
58
+        (SIDE, SIDE_ALLIES),
57
     ])
59
     ])
58
 
60
 
59
     subjects.append(man1)
61
     subjects.append(man1)
116
 
118
 
117
     assert {
119
     assert {
118
                'SELECTION_COLOR_RGB': (204, 0, 0),
120
                'SELECTION_COLOR_RGB': (204, 0, 0),
119
-               'FLAG': 'FLAG_URSS',
121
+               'FLAG': 'FLAG_USSR',
120
                'SIDE': 'ALLIES',
122
                'SIDE': 'ALLIES',
121
            } == state.subjects[0].properties
123
            } == state.subjects[0].properties
122
     assert {
124
     assert {
170
                 </item>
172
                 </item>
171
                 <item>
173
                 <item>
172
                     <key>FLAG</key>
174
                     <key>FLAG</key>
173
-                    <value>FLAG_URSS</value>
175
+                    <value>FLAG_USSR</value>
174
                 </item>
176
                 </item>
175
                 <item>
177
                 <item>
176
                     <key>SIDE</key>
178
                     <key>SIDE</key>