Skip to content

Commit f0b3d19

Browse files
committed
Support drawing options in scheme.
It is now necessary to enable drawing map features in the scheme file. In the `options` field one should enable the following features in order to have these features on the map, because they are disabled by default: - `draw_nodes`, - `draw_buildings`, - `draw_trees`, - `draw_craters`, - `draw_directions` Related to #140.
1 parent d3c18a3 commit f0b3d19

File tree

4 files changed

+63
-37
lines changed

4 files changed

+63
-37
lines changed

doc/grid.svg

+1-1
Loading

map_machine/mapper.py

+44-36
Original file line numberDiff line numberDiff line change
@@ -87,49 +87,57 @@ def draw(self, constructor: Constructor) -> None:
8787
path.update(figure.line_style.style)
8888
self.svg.add(path)
8989

90-
for tree in constructor.trees:
91-
tree.draw(self.svg, self.flinger, self.scheme)
92-
for crater in constructor.craters:
93-
crater.draw(self.svg, self.flinger)
90+
if self.scheme.draw_trees:
91+
for tree in constructor.trees:
92+
tree.draw(self.svg, self.flinger, self.scheme)
9493

95-
self.draw_buildings(constructor, self.configuration.use_building_colors)
94+
if self.scheme.draw_craters:
95+
for crater in constructor.craters:
96+
crater.draw(self.svg, self.flinger)
9697

97-
for direction_sector in constructor.direction_sectors:
98-
direction_sector.draw(self.svg, self.scheme)
98+
if self.scheme.draw_buildings:
99+
self.draw_buildings(
100+
constructor, self.configuration.use_building_colors
101+
)
99102

100-
# All other points
103+
if self.scheme.draw_directions:
104+
for direction_sector in constructor.direction_sectors:
105+
direction_sector.draw(self.svg, self.scheme)
101106

102-
occupied: Optional[Occupied]
103-
if self.configuration.overlap == 0:
104-
occupied = None
105-
else:
106-
occupied = Occupied(
107-
self.flinger.size[0],
108-
self.flinger.size[1],
109-
self.configuration.overlap,
110-
)
107+
# All other points
111108

112-
nodes: list[Point] = sorted(
113-
constructor.points, key=lambda x: -x.priority
114-
)
115-
logging.info("Drawing main icons...")
116-
for node in nodes:
117-
node.draw_main_shapes(self.svg, occupied)
118-
119-
logging.info("Drawing extra icons...")
120-
for point in nodes:
121-
point.draw_extra_shapes(self.svg, occupied)
122-
123-
logging.info("Drawing texts...")
124-
for point in nodes:
125-
if (
126-
not self.configuration.is_wireframe()
127-
and self.configuration.label_mode != LabelMode.NO
128-
):
129-
point.draw_texts(
130-
self.svg, occupied, self.configuration.label_mode
109+
if self.scheme.draw_nodes:
110+
occupied: Optional[Occupied]
111+
if self.configuration.overlap == 0:
112+
occupied = None
113+
else:
114+
occupied = Occupied(
115+
self.flinger.size[0],
116+
self.flinger.size[1],
117+
self.configuration.overlap,
131118
)
132119

120+
nodes: list[Point] = sorted(
121+
constructor.points, key=lambda x: -x.priority
122+
)
123+
logging.info("Drawing main icons...")
124+
for node in nodes:
125+
node.draw_main_shapes(self.svg, occupied)
126+
127+
logging.info("Drawing extra icons...")
128+
for point in nodes:
129+
point.draw_extra_shapes(self.svg, occupied)
130+
131+
logging.info("Drawing texts...")
132+
for point in nodes:
133+
if (
134+
not self.configuration.is_wireframe()
135+
and self.configuration.label_mode != LabelMode.NO
136+
):
137+
point.draw_texts(
138+
self.svg, occupied, self.configuration.label_mode
139+
)
140+
133141
if self.configuration.show_credit:
134142
self.draw_credits(constructor.flinger.size)
135143

map_machine/scheme.py

+10
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,16 @@ def __init__(self, content: dict[str, Any]) -> None:
321321
for element in group["tags"]:
322322
self.node_matchers.append(NodeMatcher(element, group))
323323

324+
options = content.get("options", {})
325+
326+
self.draw_nodes: bool = options.get("draw_nodes", False)
327+
328+
# Map features.
329+
self.draw_buildings: bool = options.get("draw_buildings", False)
330+
self.draw_trees: bool = options.get("draw_trees", False)
331+
self.draw_craters: bool = options.get("draw_craters", False)
332+
self.draw_directions: bool = options.get("draw_directions", False)
333+
324334
self.colors: dict[str, str] = content.get("colors", {})
325335
self.material_colors: dict[str, str] = content.get(
326336
"material_colors", {}

map_machine/scheme/default.yml

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
options:
2+
3+
draw_nodes: yes
4+
draw_trees: yes
5+
draw_craters: yes
6+
draw_buildings: yes
7+
draw_directions: yes
8+
19
colors:
210

311
# Entity

0 commit comments

Comments
 (0)