|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
1 |
|
import datetime |
|
4
|
1 |
|
import math |
|
5
|
|
|
|
|
6
|
1 |
|
from il2fb.commons.weather import Conditions |
|
7
|
|
|
|
|
8
|
1 |
|
from ..converters import to_belligerent |
|
9
|
1 |
|
from . import ValuesParser |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
1 |
|
class MainParser(ValuesParser): |
|
13
|
|
|
""" |
|
14
|
|
|
Parses ``MAIN`` section. |
|
15
|
|
|
View :ref:`detailed description <main-section>`. |
|
16
|
|
|
""" |
|
17
|
|
|
|
|
18
|
1 |
|
def check_section_name(self, section_name): |
|
19
|
|
|
""" |
|
20
|
|
|
Implements abstract method. See |
|
21
|
|
|
:meth:`SectionParser.check_section_name` for semantics. |
|
22
|
|
|
""" |
|
23
|
1 |
|
return section_name == "MAIN" |
|
24
|
|
|
|
|
25
|
1 |
|
def clean(self): |
|
26
|
|
|
""" |
|
27
|
|
|
Redefines base method. See :meth:`SectionParser.clean` for |
|
28
|
|
|
semantics. |
|
29
|
|
|
""" |
|
30
|
1 |
|
weather_conditions = int(self.data['CloudType']) |
|
31
|
1 |
|
return { |
|
32
|
|
|
'location_loader': self.data['MAP'], |
|
33
|
|
|
'time': { |
|
34
|
|
|
'value': self._to_time(self.data['TIME']), |
|
35
|
|
|
'is_fixed': 'TIMECONSTANT' in self.data, |
|
36
|
|
|
}, |
|
37
|
|
|
'weather_conditions': Conditions.get_by_value(weather_conditions), |
|
38
|
|
|
'cloud_base': int(float(self.data['CloudHeight'])), |
|
39
|
|
|
'player': { |
|
40
|
|
|
'belligerent': to_belligerent(self.data['army']), |
|
41
|
|
|
'flight_id': self.data.get('player'), |
|
42
|
|
|
'aircraft_index': int(self.data['playerNum']), |
|
43
|
|
|
'fixed_weapons': 'WEAPONSCONSTANT' in self.data, |
|
44
|
|
|
}, |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
def _to_time(self, value): |
|
48
|
1 |
|
time = float(value) |
|
49
|
1 |
|
minutes, hours = math.modf(time) |
|
50
|
|
|
return datetime.time(int(hours), int(minutes * 60)) |
|
51
|
|
|
|