Passed
Push — master ( 0fb205...8fdecd )
by Oleksandr
56s
created

BelligerentConstant.to_primitive()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
from typing import Optional
2
3
from candv import Values
4
from candv import VerboseValueConstant
5
from candv import with_constant_class
6
7
from ._translations import gettext_lazy as _
8
from ._utils import export
9
10
11
@export
12
class BelligerentConstant(VerboseValueConstant):
13
14
  def __init__(
15
    self,
16
    value:        int,
17
    color:        str,
18
    verbose_name: Optional[str]=None,
19
    help_text:    Optional[str]=None,
20
  ):
21
    super().__init__(
22
      value=value,
23
      verbose_name=verbose_name,
24
      help_text=help_text,
25
    )
26
    self.color = color
27
28
  def merge_into_group(self, group):
29
    super().merge_into_group(group)
30
    group.color = self.color
31
32
  def to_primitive(self, context=None):
33
    primitive = super().to_primitive(context)
34
    primitive['color'] = self.color
35
    return primitive
36
37
38
@export
39
class BELLIGERENT(with_constant_class(BelligerentConstant), Values):
40
  """
41
  Definitions of belligerents (a.k.a "armies").
42
43
  Extracted from "com.maddox.il2.ai.Army" with colors decoded.
44
45
  """
46
  NONE      = BelligerentConstant(value=0,  color="FFFFFF", verbose_name=_("none"))
47
  RED       = BelligerentConstant(value=1,  color="C00000", verbose_name=_("red"))
48
  BLUE      = BelligerentConstant(value=2,  color="0000C0", verbose_name=_("blue"))
49
  GREEN     = BelligerentConstant(value=3,  color="00C000", verbose_name=_("green"))
50
  GOLD      = BelligerentConstant(value=4,  color="C0C000", verbose_name=_("gold"))
51
  PURPLE    = BelligerentConstant(value=5,  color="C000C0", verbose_name=_("purple"))
52
  AQUA      = BelligerentConstant(value=6,  color="00C0C0", verbose_name=_("aqua"))
53
  MAROON    = BelligerentConstant(value=7,  color="800000", verbose_name=_("maroon"))
54
  NAVY      = BelligerentConstant(value=8,  color="000080", verbose_name=_("navy"))
55
  EMERALD   = BelligerentConstant(value=9,  color="004000", verbose_name=_("emerald"))
56
  OLIVE     = BelligerentConstant(value=10, color="59800C", verbose_name=_("olive"))
57
  MAGENTA   = BelligerentConstant(value=11, color="800080", verbose_name=_("magenta"))
58
  TEAL      = BelligerentConstant(value=12, color="008080", verbose_name=_("teal"))
59
  ORANGE    = BelligerentConstant(value=13, color="E7651A", verbose_name=_("orange"))
60
  TURQUOISE = BelligerentConstant(value=14, color="00A49E", verbose_name=_("turquoise"))
61
  BROWN     = BelligerentConstant(value=15, color="8C6636", verbose_name=_("brown"))
62
  SALAD     = BelligerentConstant(value=16, color="408040", verbose_name=_("salad"))
63