1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
1 |
|
from il2fb.commons.spatial import Point2D |
4
|
1 |
|
from il2fb.commons.structures import BaseStructure |
5
|
|
|
|
6
|
1 |
|
from ..converters import to_belligerent |
7
|
1 |
|
from . import CollectingParser |
8
|
|
|
|
9
|
|
|
|
10
|
1 |
|
class Building(BaseStructure): |
11
|
1 |
|
__slots__ = ['id', 'belligerent', 'code', 'pos', 'rotation_angle', ] |
12
|
|
|
|
13
|
1 |
|
def __init__(self, id, belligerent, code, pos, rotation_angle): |
14
|
1 |
|
self.id = id |
15
|
1 |
|
self.belligerent = belligerent |
16
|
1 |
|
self.code = code |
17
|
1 |
|
self.pos = pos |
18
|
1 |
|
self.rotation_angle = rotation_angle |
19
|
|
|
|
20
|
1 |
|
def __repr__(self): |
21
|
1 |
|
return "<Building '{0}'>".format(self.id) |
22
|
|
|
|
23
|
|
|
|
24
|
1 |
|
class BuildingsParser(CollectingParser): |
25
|
|
|
""" |
26
|
|
|
Parses ``Buildings`` section. |
27
|
|
|
View :ref:`detailed description <buildings-section>`. |
28
|
|
|
""" |
29
|
|
|
|
30
|
1 |
|
def check_section_name(self, section_name): |
31
|
1 |
|
return section_name == "Buildings" |
32
|
|
|
|
33
|
1 |
|
def parse_line(self, line): |
34
|
1 |
|
params = line.split() |
35
|
1 |
|
oid, building_object, belligerent = params[:3] |
36
|
1 |
|
pos_x, pos_y, rotation_angle = params[3:] |
37
|
1 |
|
code = building_object.split('$')[1] |
38
|
1 |
|
self.data.append(Building( |
39
|
|
|
id=oid, |
40
|
|
|
belligerent=to_belligerent(belligerent), |
41
|
|
|
code=code, |
42
|
|
|
pos=Point2D(pos_x, pos_y), |
43
|
|
|
rotation_angle=float(rotation_angle), |
44
|
|
|
)) |
45
|
|
|
|
46
|
1 |
|
def clean(self): |
47
|
|
|
return {'buildings': self.data, } |
48
|
|
|
|