mirror of
https://github.com/enzet/map-machine.git
synced 2025-08-06 10:09:52 +02:00
Fix walls order.
This commit is contained in:
parent
d634e7e904
commit
2e3959c1d5
2 changed files with 68 additions and 46 deletions
|
@ -141,28 +141,45 @@ class Building(Figure):
|
|||
(0.0, -previous_height * scale * BUILDING_SCALE)
|
||||
)
|
||||
shift_2: np.ndarray = np.array((0.0, -height * scale * BUILDING_SCALE))
|
||||
|
||||
for segment in self.parts:
|
||||
draw_walls(svg, self, segment, height, shift_1, shift_2)
|
||||
|
||||
def draw_roof(self, svg: Drawing, flinger: Flinger, scale: float) -> None:
|
||||
"""Draw building roof."""
|
||||
path: Path = Path(
|
||||
d=self.get_path(
|
||||
flinger, np.array([0.0, -self.height * scale * BUILDING_SCALE])
|
||||
),
|
||||
stroke=self.stroke,
|
||||
fill="none" if self.is_construction else self.fill.hex,
|
||||
stroke_linejoin="round",
|
||||
)
|
||||
svg.add(path)
|
||||
|
||||
|
||||
def draw_walls(svg, building: Building, segment, height, shift_1, shift_2):
|
||||
fill: str
|
||||
if self.is_construction:
|
||||
if building.is_construction:
|
||||
color_part: float = segment.angle * 0.2
|
||||
fill = Color(
|
||||
rgb=(
|
||||
self.wall_color.get_red() + color_part,
|
||||
self.wall_color.get_green() + color_part,
|
||||
self.wall_color.get_blue() + color_part,
|
||||
building.wall_color.get_red() + color_part,
|
||||
building.wall_color.get_green() + color_part,
|
||||
building.wall_color.get_blue() + color_part,
|
||||
)
|
||||
).hex
|
||||
elif height <= 0.25 / BUILDING_SCALE:
|
||||
fill = self.wall_bottom_color_1.hex
|
||||
fill = building.wall_bottom_color_1.hex
|
||||
elif height <= 0.5 / BUILDING_SCALE:
|
||||
fill = self.wall_bottom_color_2.hex
|
||||
fill = building.wall_bottom_color_2.hex
|
||||
else:
|
||||
color_part: float = segment.angle * 0.2
|
||||
color_part: float = segment.angle * 0.2 - 0.1
|
||||
fill = Color(
|
||||
rgb=(
|
||||
self.wall_color.get_red() + color_part,
|
||||
self.wall_color.get_green() + color_part,
|
||||
self.wall_color.get_blue() + color_part,
|
||||
max(min(building.wall_color.get_red() + color_part, 1), 0),
|
||||
max(min(building.wall_color.get_green() + color_part, 1), 0),
|
||||
max(min(building.wall_color.get_blue() + color_part, 1), 0),
|
||||
)
|
||||
).hex
|
||||
|
||||
|
@ -176,7 +193,7 @@ class Building(Figure):
|
|||
segment.point_1 + shift_1,
|
||||
"Z",
|
||||
)
|
||||
path: Path = svg.path(
|
||||
path: Path = Path(
|
||||
d=command,
|
||||
fill=fill,
|
||||
stroke=fill,
|
||||
|
@ -184,15 +201,3 @@ class Building(Figure):
|
|||
stroke_linejoin="round",
|
||||
)
|
||||
svg.add(path)
|
||||
|
||||
def draw_roof(self, svg: Drawing, flinger: Flinger, scale: float) -> None:
|
||||
"""Draw building roof."""
|
||||
path: Path = Path(
|
||||
d=self.get_path(
|
||||
flinger, np.array([0.0, -self.height * scale * BUILDING_SCALE])
|
||||
),
|
||||
stroke=self.stroke,
|
||||
fill="none" if self.is_construction else self.fill,
|
||||
stroke_linejoin="round",
|
||||
)
|
||||
svg.add(path)
|
||||
|
|
|
@ -16,6 +16,7 @@ from svgwrite.shapes import Rect
|
|||
|
||||
from map_machine.constructor import Constructor
|
||||
from map_machine.drawing import draw_text
|
||||
from map_machine.feature.building import Building, draw_walls, BUILDING_SCALE
|
||||
from map_machine.feature.road import Intersection, Road, RoadPart
|
||||
from map_machine.figure import StyledFigure
|
||||
from map_machine.geometry.boundary_box import BoundaryBox
|
||||
|
@ -133,12 +134,28 @@ class Map:
|
|||
building.draw_shade(building_shade, self.flinger)
|
||||
self.svg.add(building_shade)
|
||||
|
||||
walls: dict[Segment, Building] = {}
|
||||
|
||||
for building in constructor.buildings:
|
||||
for part in building.parts:
|
||||
walls[part] = building
|
||||
|
||||
sorted_walls = sorted(walls.keys())
|
||||
|
||||
previous_height: float = 0.0
|
||||
for height in sorted(constructor.heights):
|
||||
for building in constructor.buildings:
|
||||
if building.height < height or building.min_height > height:
|
||||
shift_1: np.ndarray = np.array(
|
||||
(0.0, -previous_height * scale * BUILDING_SCALE)
|
||||
)
|
||||
shift_2: np.ndarray = np.array(
|
||||
(0.0, -height * scale * BUILDING_SCALE)
|
||||
)
|
||||
for wall in sorted_walls:
|
||||
building: Building = walls[wall]
|
||||
if building.height < height or building.min_height >= height:
|
||||
continue
|
||||
building.draw_walls(self.svg, height, previous_height, scale)
|
||||
|
||||
draw_walls(self.svg, building, wall, height, shift_1, shift_2)
|
||||
|
||||
if self.configuration.draw_roofs:
|
||||
for building in constructor.buildings:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue