Skip to content

Commit

Permalink
Hotfix: Docker Exit Code 139 when rotating the map.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot committed Dec 20, 2024
1 parent 173c870 commit e35ee99
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion maps4fs/generator/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def fit_polygon_into_bounds(
offset = (self.map_size / 2) - (self.map_rotated_size / 2)
self.logger.debug("Translating the polygon by %s", offset)
polygon = translate(polygon, xoff=offset, yoff=offset)
self.logger.debug("Rotated and translated polygon.")

if margin:
polygon = polygon.buffer(margin, join_style="mitre")
Expand All @@ -367,12 +368,16 @@ def fit_polygon_into_bounds(

# Intersect the polygon with the bounds to fit it within the map
fitted_polygon = polygon.intersection(bounds)
self.logger.debug("Fitted the polygon into the bounds: %s", bounds)

if not isinstance(fitted_polygon, Polygon):
raise ValueError("The fitted polygon is not a valid polygon.")

# Return the fitted polygon points
return list(fitted_polygon.exterior.coords)
as_list = list(fitted_polygon.exterior.coords)
if not as_list:
raise ValueError("The fitted polygon has no points.")
return as_list

def get_infolayer_path(self, layer_name: str) -> str | None:
"""Returns the path to the info layer file.
Expand Down
11 changes: 11 additions & 0 deletions maps4fs/generator/grle.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def _add_farmlands(self) -> None:
self.game.weights_dir_path(self.map_directory), "infoLayer_farmlands.png"
)

self.logger.info(
"Adding farmlands to the InfoLayer PNG file: %s.", info_layer_farmlands_path
)

if not os.path.isfile(info_layer_farmlands_path):
self.logger.warning("InfoLayer PNG file %s not found.", info_layer_farmlands_path)
return
Expand Down Expand Up @@ -139,12 +143,19 @@ def _add_farmlands(self) -> None:
)
continue

self.logger.debug("Fitted field %s contains %s points.", farmland_id, len(fitted_field))

field_np = np.array(fitted_field, np.int32)
field_np = field_np.reshape((-1, 1, 2))

self.logger.debug(
"Created a numpy array and reshaped it. Number of points: %s", len(field_np)
)

# Infolayer image is 1/2 of the size of the map image, that's why we need to divide
# the coordinates by 2.
field_np = field_np // 2
self.logger.debug("Divided the coordinates by 2.")

# pylint: disable=no-member
try:
Expand Down
1 change: 1 addition & 0 deletions maps4fs/generator/i3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def _add_fields(self) -> None:
return

self.logger.info("Found %s fields in textures info layer.", len(fields))
self.logger.debug("Starging to add fields to the I3D file.")

root = tree.getroot()
gameplay_node = root.find(".//TransformGroup[@name='gameplay']")
Expand Down

0 comments on commit e35ee99

Please sign in to comment.