1
|
|
|
# coding: utf-8 |
2
|
|
|
|
3
|
1 |
|
import zope.interface |
4
|
|
|
|
5
|
1 |
|
from schematics.models import Model |
6
|
1 |
|
from schematics.types import BooleanType |
7
|
1 |
|
from schematics.types.compound import ModelType |
8
|
|
|
|
9
|
1 |
|
from .interfaces import INISerializable, DefaultProvider |
10
|
1 |
|
from .helpers import field_from_ini, field_to_ini |
11
|
|
|
|
12
|
|
|
|
13
|
1 |
View Code Duplication |
@zope.interface.implementer(INISerializable) |
|
|
|
|
14
|
1 |
|
@zope.interface.implementer(DefaultProvider) |
15
|
1 |
|
class Users(Model): |
16
|
1 |
|
show_tail_number = BooleanType( |
17
|
|
|
default=True, |
18
|
|
|
required=True, |
19
|
|
|
) |
20
|
1 |
|
show_ping = BooleanType( |
21
|
|
|
default=True, |
22
|
|
|
required=True, |
23
|
|
|
) |
24
|
1 |
|
show_callsign = BooleanType( |
25
|
|
|
default=True, |
26
|
|
|
required=True, |
27
|
|
|
) |
28
|
1 |
|
show_belligerent = BooleanType( |
29
|
|
|
default=True, |
30
|
|
|
required=True, |
31
|
|
|
) |
32
|
1 |
|
show_aircraft_designation = BooleanType( |
33
|
|
|
default=True, |
34
|
|
|
required=True, |
35
|
|
|
) |
36
|
1 |
|
show_aircraft_type = BooleanType( |
37
|
|
|
default=True, |
38
|
|
|
required=True, |
39
|
|
|
) |
40
|
1 |
|
show_score = BooleanType( |
41
|
|
|
default=True, |
42
|
|
|
required=True, |
43
|
|
|
) |
44
|
|
|
|
45
|
1 |
|
@classmethod |
46
|
|
|
def from_ini(cls, ini): |
47
|
|
|
return cls({ |
48
|
|
|
'show_tail_number': field_from_ini( |
49
|
|
|
cls.show_tail_number, ini, |
50
|
|
|
'NET', 'showPilotNumber', |
51
|
|
|
), |
52
|
|
|
'show_ping': field_from_ini( |
53
|
|
|
cls.show_ping, ini, |
54
|
|
|
'NET', 'showPilotPing', |
55
|
|
|
), |
56
|
|
|
'show_callsign': field_from_ini( |
57
|
|
|
cls.show_callsign, ini, |
58
|
|
|
'NET', 'showPilotName', |
59
|
|
|
), |
60
|
|
|
'show_belligerent': field_from_ini( |
61
|
|
|
cls.show_belligerent, ini, |
62
|
|
|
'NET', 'showPilotArmy', |
63
|
|
|
), |
64
|
|
|
'show_aircraft_designation': field_from_ini( |
65
|
|
|
cls.show_aircraft_designation, ini, |
66
|
|
|
'NET', 'showPilotACDesignation', |
67
|
|
|
), |
68
|
|
|
'show_aircraft_type': field_from_ini( |
69
|
|
|
cls.show_aircraft_type, ini, |
70
|
|
|
'NET', 'showPilotACType', |
71
|
|
|
), |
72
|
|
|
'show_score': field_from_ini( |
73
|
|
|
cls.show_score, ini, |
74
|
|
|
'NET', 'showPilotScore', |
75
|
|
|
), |
76
|
|
|
}) |
77
|
|
|
|
78
|
1 |
|
def to_ini(self, ini): |
79
|
|
|
field_to_ini(self.show_tail_number, ini, 'NET', 'showPilotNumber') |
80
|
|
|
field_to_ini(self.show_ping, ini, 'NET', 'showPilotPing') |
81
|
|
|
field_to_ini(self.show_callsign, ini, 'NET', 'showPilotName') |
82
|
|
|
field_to_ini(self.show_belligerent, ini, 'NET', 'showPilotArmy') |
83
|
|
|
field_to_ini(self.show_aircraft_designation, ini, 'NET', 'showPilotACDesignation') |
84
|
|
|
field_to_ini(self.show_aircraft_type, ini, 'NET', 'showPilotACType') |
85
|
|
|
field_to_ini(self.show_score, ini, 'NET', 'showPilotScore') |
86
|
1 |
|
|
87
|
1 |
|
@classmethod |
88
|
1 |
|
def default(cls): |
89
|
1 |
|
return cls({ |
90
|
|
|
field_name: field.default |
91
|
|
|
for field_name, field in cls.fields.items() |
92
|
|
|
}) |
93
|
1 |
|
|
94
|
|
|
|
95
|
|
View Code Duplication |
@zope.interface.implementer(INISerializable) |
|
|
|
|
96
|
|
|
@zope.interface.implementer(DefaultProvider) |
97
|
|
|
class Belligerents(Model): |
98
|
1 |
|
show_score = BooleanType( |
99
|
|
|
default=False, |
100
|
|
|
required=True, |
101
|
|
|
) |
102
|
|
|
accumulate_score = BooleanType( |
103
|
|
|
default=False, |
104
|
|
|
required=True, |
105
|
|
|
) |
106
|
|
|
|
107
|
|
|
@classmethod |
108
|
|
|
def from_ini(cls, ini): |
109
|
|
|
return cls({ |
110
|
|
|
'show_score': field_from_ini( |
111
|
1 |
|
cls.show_score, ini, |
112
|
|
|
'NET', 'showTeamScore', |
113
|
|
|
), |
114
|
|
|
'accumulate_score': field_from_ini( |
115
|
|
|
cls.accumulate_score, ini, |
116
|
|
|
'NET', 'cumulativeTeamScore', |
117
|
|
|
), |
118
|
|
|
}) |
119
|
1 |
|
|
120
|
1 |
|
def to_ini(self, ini): |
121
|
1 |
|
field_to_ini(self.show_score, ini, 'NET', 'showTeamScore') |
122
|
1 |
|
field_to_ini(self.accumulate_score, ini, 'NET', 'cumulativeTeamScore') |
123
|
|
|
|
124
|
|
|
@classmethod |
125
|
|
|
def default(cls): |
126
|
1 |
|
return cls({ |
127
|
|
|
field_name: field.default |
128
|
|
|
for field_name, field in cls.fields.items() |
129
|
|
|
}) |
130
|
1 |
|
|
131
|
|
|
|
132
|
|
View Code Duplication |
@zope.interface.implementer(INISerializable) |
|
|
|
|
133
|
|
|
@zope.interface.implementer(DefaultProvider) |
134
|
|
|
class Statistics(Model): |
135
|
1 |
|
enabled = BooleanType( |
136
|
|
|
default=True, |
137
|
|
|
required=True, |
138
|
|
|
) |
139
|
|
|
users = ModelType( |
140
|
|
|
model_spec=Users, |
141
|
|
|
required=True, |
142
|
|
|
) |
143
|
|
|
belligerents = ModelType( |
144
|
|
|
model_spec=Belligerents, |
145
|
|
|
required=True, |
146
|
1 |
|
) |
147
|
|
|
|
148
|
|
|
@classmethod |
149
|
|
|
def from_ini(cls, ini): |
150
|
|
|
return cls({ |
151
|
|
|
'enabled': not field_from_ini( |
152
|
|
|
cls.enabled, ini, |
153
|
|
|
'NET', 'disableNetStatStatistics', |
154
|
|
|
False, |
155
|
|
|
), |
156
|
|
|
'users': Users.from_ini(ini), |
157
|
|
|
'belligerents': Belligerents.from_ini(ini), |
158
|
|
|
}) |
159
|
|
|
|
160
|
|
|
def to_ini(self, ini): |
161
|
|
|
field_to_ini(not self.enabled, ini, 'NET', 'disableNetStatStatistics') |
162
|
|
|
self.users.to_ini(ini) |
163
|
|
|
self.belligerents.to_ini(ini) |
164
|
|
|
|
165
|
|
|
@classmethod |
166
|
|
|
def default(cls): |
167
|
|
|
return cls({ |
168
|
|
|
'enabled': cls.enabled.default, |
169
|
|
|
'users': Users.default(), |
170
|
|
|
'belligerents': Belligerents.default(), |
171
|
|
|
}) |
172
|
|
|
|