Skip to content

Commit

Permalink
Support drawing options in scheme.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
enzet committed May 28, 2023
1 parent d3c18a3 commit f0b3d19
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 37 deletions.
2 changes: 1 addition & 1 deletion doc/grid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 44 additions & 36 deletions map_machine/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,49 +87,57 @@ def draw(self, constructor: Constructor) -> None:
path.update(figure.line_style.style)
self.svg.add(path)

for tree in constructor.trees:
tree.draw(self.svg, self.flinger, self.scheme)
for crater in constructor.craters:
crater.draw(self.svg, self.flinger)
if self.scheme.draw_trees:
for tree in constructor.trees:
tree.draw(self.svg, self.flinger, self.scheme)

self.draw_buildings(constructor, self.configuration.use_building_colors)
if self.scheme.draw_craters:
for crater in constructor.craters:
crater.draw(self.svg, self.flinger)

for direction_sector in constructor.direction_sectors:
direction_sector.draw(self.svg, self.scheme)
if self.scheme.draw_buildings:
self.draw_buildings(
constructor, self.configuration.use_building_colors
)

# All other points
if self.scheme.draw_directions:
for direction_sector in constructor.direction_sectors:
direction_sector.draw(self.svg, self.scheme)

occupied: Optional[Occupied]
if self.configuration.overlap == 0:
occupied = None
else:
occupied = Occupied(
self.flinger.size[0],
self.flinger.size[1],
self.configuration.overlap,
)
# All other points

nodes: list[Point] = sorted(
constructor.points, key=lambda x: -x.priority
)
logging.info("Drawing main icons...")
for node in nodes:
node.draw_main_shapes(self.svg, occupied)

logging.info("Drawing extra icons...")
for point in nodes:
point.draw_extra_shapes(self.svg, occupied)

logging.info("Drawing texts...")
for point in nodes:
if (
not self.configuration.is_wireframe()
and self.configuration.label_mode != LabelMode.NO
):
point.draw_texts(
self.svg, occupied, self.configuration.label_mode
if self.scheme.draw_nodes:
occupied: Optional[Occupied]
if self.configuration.overlap == 0:
occupied = None
else:
occupied = Occupied(
self.flinger.size[0],
self.flinger.size[1],
self.configuration.overlap,
)

nodes: list[Point] = sorted(
constructor.points, key=lambda x: -x.priority
)
logging.info("Drawing main icons...")
for node in nodes:
node.draw_main_shapes(self.svg, occupied)

logging.info("Drawing extra icons...")
for point in nodes:
point.draw_extra_shapes(self.svg, occupied)

logging.info("Drawing texts...")
for point in nodes:
if (
not self.configuration.is_wireframe()
and self.configuration.label_mode != LabelMode.NO
):
point.draw_texts(
self.svg, occupied, self.configuration.label_mode
)

if self.configuration.show_credit:
self.draw_credits(constructor.flinger.size)

Expand Down
10 changes: 10 additions & 0 deletions map_machine/scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,16 @@ def __init__(self, content: dict[str, Any]) -> None:
for element in group["tags"]:
self.node_matchers.append(NodeMatcher(element, group))

options = content.get("options", {})

self.draw_nodes: bool = options.get("draw_nodes", False)

# Map features.
self.draw_buildings: bool = options.get("draw_buildings", False)
self.draw_trees: bool = options.get("draw_trees", False)
self.draw_craters: bool = options.get("draw_craters", False)
self.draw_directions: bool = options.get("draw_directions", False)

self.colors: dict[str, str] = content.get("colors", {})
self.material_colors: dict[str, str] = content.get(
"material_colors", {}
Expand Down
8 changes: 8 additions & 0 deletions map_machine/scheme/default.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
options:

draw_nodes: yes
draw_trees: yes
draw_craters: yes
draw_buildings: yes
draw_directions: yes

colors:

# Entity
Expand Down

0 comments on commit f0b3d19

Please sign in to comment.