From 4a85861d6be944aee0ae037f12825f9e60058d6f Mon Sep 17 00:00:00 2001 From: Stan Soldatov <118521851+iwatkot@users.noreply.github.com> Date: Fri, 20 Dec 2024 15:38:04 +0100 Subject: [PATCH] Hotfix: Docker Exit Code 139 when rotating the map --- maps4fs/generator/component.py | 7 ++++++- maps4fs/generator/grle.py | 11 +++++++++++ maps4fs/generator/i3d.py | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/maps4fs/generator/component.py b/maps4fs/generator/component.py index c256e8b..dce0b02 100644 --- a/maps4fs/generator/component.py +++ b/maps4fs/generator/component.py @@ -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") @@ -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. diff --git a/maps4fs/generator/grle.py b/maps4fs/generator/grle.py index 52a22b7..c48fd1e 100644 --- a/maps4fs/generator/grle.py +++ b/maps4fs/generator/grle.py @@ -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 @@ -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: diff --git a/maps4fs/generator/i3d.py b/maps4fs/generator/i3d.py index dee4271..e87c49c 100644 --- a/maps4fs/generator/i3d.py +++ b/maps4fs/generator/i3d.py @@ -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']")