Browse Source

troops in map for placement

Bastien Sevajol 5 years ago
parent
commit
c88bc1655c

+ 1 - 1
README.md View File

@@ -33,7 +33,7 @@ You also need a running redis server (used db number is `0`, soon configurable).
33 33
 
34 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 38
 Select troops for every countries then generate s troops file.
39 39
 

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

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

+ 11 - 2
opencombat/const.py View File

@@ -2,14 +2,23 @@
2 2
 
3 3
 COLLECTION_ALIVE = 'ALIVE'
4 4
 
5
+SELECTION_COLOR_RGB = 'SELECTION_COLOR_RGB'
6
+
5 7
 FLAG = 'FLAG'
6 8
 FLAG_DE = 'FLAG_DE'
7
-FLAG_URSS = 'FLAG_URSS'
9
+FLAG_USSR = 'FLAG_USSR'
8 10
 
9 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 19
 COMBAT_MODE = 'COMBAT_MODE'
11 20
 COMBAT_MODE_DEFEND = 'COMBAT_MODE_DEFEND'
12 21
 COMBAT_MODE_HIDE = 'COMBAT_MODE_HIDE'
13 22
 
14 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,4 +6,4 @@ FLAG_DE = 'DE'
6 6
 FLAG_COLORS = {
7 7
     FLAG_DE
8 8
 }
9
-FLAG_URSS = 'URSS'
9
+FLAG_USSR = 'USSR'

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

@@ -1,5 +1,14 @@
1 1
 # coding: utf-8
2 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 12
 from opencombat.simulation.physics import TilePhysics
4 13
 from synergine2.config import Config
5 14
 from synergine2.simulation import SubjectBehaviour
@@ -14,6 +23,23 @@ class TileStrategySimulation(XYZSimulation):
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 43
     def __init__(
18 44
         self,
19 45
         config: Config,

+ 9 - 6
opencombat/state.py View File

@@ -14,6 +14,9 @@ from opencombat.util import get_class_from_string_path
14 14
 from opencombat.util import pretty_xml
15 15
 from opencombat.util import get_text_xml_element
16 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 22
 class State(object):
@@ -93,9 +96,9 @@ class State(object):
93 96
 
94 97
     def _get_decode_properties_map(self) -> typing.Dict[str, typing.Callable[[str], typing.Any]]:  # nopep8
95 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,9 +182,9 @@ class StateDumper(object):
179 182
 
180 183
     def _get_encode_properties_map(self) -> typing.Dict[str, typing.Callable[[typing.Any], str]]:  # nopep8:
181 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,7 +1,7 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 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 5
         <units>
6 6
             <unit>
7 7
                 <id>std_soldier</id>

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

@@ -60,9 +60,13 @@ class Troop(object):
60 60
 
61 61
             for unit in team.units:
62 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 68
                 subjects.append(subject)
64 69
 
65
-        # TODO BS 2018-06-25: place subjects on map, set side, color, etc
66 70
         return subjects
67 71
 
68 72
 

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

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

+ 9 - 0
select_troops.py View File

@@ -1,5 +1,6 @@
1 1
 # coding: utf-8
2 2
 import argparse
3
+import sys
3 4
 import typing
4 5
 from tkinter import Tk
5 6
 
@@ -62,6 +63,14 @@ if __name__ == '__main__':
62 63
     )
63 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 74
     main(
66 75
         units_file_path=args.units_file_path,
67 76
         teams_file_path=args.teams_file_path,

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

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

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

@@ -1,7 +1,7 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 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 5
         <units>
6 6
             <unit>
7 7
                 <id>std_soldier</id>

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

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

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

@@ -46,7 +46,7 @@ def test_team_stash__ok__get_teams(
46 46
 
47 47
     assert 'std_team' == stash.teams[0].id
48 48
     assert 'Standard team' == stash.teams[0].name
49
-    assert 'URSS' == stash.teams[0].country
49
+    assert 'USSR' == stash.teams[0].country
50 50
     assert stash.teams[0].units
51 51
     assert 4 == len(stash.teams[0].units)
52 52
     assert isinstance(stash.teams[0].units[0], UnitModel)
@@ -76,7 +76,7 @@ def test_teams_stash__ok__get_unit(
76 76
         'tests/fixtures/teams.xml',
77 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 82
 def test_teams_stash__error__get_team_wrong_country(
@@ -104,4 +104,4 @@ def test_teams_stash__error__get_team_wrong_id(
104 104
     )
105 105
 
106 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,7 +31,7 @@ def test_units_stash__ok__get_units(
31 31
 
32 32
     assert 'std_soldier' == stash.units[0].id
33 33
     assert 'Standard soldier' == stash.units[0].name
34
-    assert 'URSS' == stash.units[0].country
34
+    assert 'USSR' == stash.units[0].country
35 35
     assert ManSubject == stash.units[0].class_
36 36
 
37 37
     assert 'std_soldier' == stash.units[1].id
@@ -47,7 +47,7 @@ def test_units_stash__ok__get_unit(
47 47
         config,
48 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 53
 def test_units_stash__error__get_unit_wrong_country(
@@ -71,4 +71,4 @@ def test_units_stash__error__get_unit_wrong_id(
71 71
     )
72 72
 
73 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,8 +16,10 @@ from opencombat.const import FLAG
16 16
 from opencombat.const import SIDE
17 17
 from opencombat.const import FLAG_DE
18 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 25
 class MyStateLoader(StateLoader):
@@ -44,16 +46,16 @@ def simulation_for_dump(config) -> TileStrategySimulation:
44 46
     man1.properties = OrderedDict([
45 47
         (SELECTION_COLOR_RGB, DE_COLOR),
46 48
         (FLAG, FLAG_DE),
47
-        (SIDE, 'AXIS'),
49
+        (SIDE, SIDE_AXIS),
48 50
     ])
49 51
 
50 52
     man2 = ManSubject(config, simulation)
51 53
     man2.position = (16, 8)
52 54
     man2.direction = 197
53 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 61
     subjects.append(man1)
@@ -116,7 +118,7 @@ def test_state__ok__subjects(
116 118
 
117 119
     assert {
118 120
                'SELECTION_COLOR_RGB': (204, 0, 0),
119
-               'FLAG': 'FLAG_URSS',
121
+               'FLAG': 'FLAG_USSR',
120 122
                'SIDE': 'ALLIES',
121 123
            } == state.subjects[0].properties
122 124
     assert {
@@ -170,7 +172,7 @@ def test_state__ok__dump(
170 172
                 </item>
171 173
                 <item>
172 174
                     <key>FLAG</key>
173
-                    <value>FLAG_URSS</value>
175
+                    <value>FLAG_USSR</value>
174 176
                 </item>
175 177
                 <item>
176 178
                     <key>SIDE</key>