maps4fs 0.6.8__py3-none-any.whl → 0.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,3 +53,11 @@ class Component:
53
53
  NotImplementedError: If the method is not implemented in the child class.
54
54
  """
55
55
  raise NotImplementedError
56
+
57
+ def previews(self) -> list[str]:
58
+ """Returns a list of paths to the preview images. Must be implemented in the child class.
59
+
60
+ Raises:
61
+ NotImplementedError: If the method is not implemented in the child class.
62
+ """
63
+ raise NotImplementedError
@@ -42,3 +42,12 @@ class Config(Component):
42
42
  self.logger.debug("Map size set to %sx%s in Map XML file.", width, height)
43
43
  tree.write(self._map_xml_path)
44
44
  self.logger.debug("Map XML file saved to: %s.", self._map_xml_path)
45
+
46
+ def previews(self) -> list[str]:
47
+ """Returns a list of paths to the preview images (empty list).
48
+ The component does not generate any preview images so it returns an empty list.
49
+
50
+ Returns:
51
+ list[str]: An empty list.
52
+ """
53
+ return []
maps4fs/generator/dem.py CHANGED
@@ -205,3 +205,43 @@ class DEM(Component):
205
205
  f"DEM data was normalized to {normalized_data.min()} - {normalized_data.max()}."
206
206
  )
207
207
  return normalized_data
208
+
209
+ def grayscale_preview(self) -> str:
210
+ """Converts DEM image to grayscale RGB image and saves it to the map directory.
211
+ Returns path to the preview image.
212
+
213
+ Returns:
214
+ str: Path to the preview image.
215
+ """
216
+ rgb_dem_path = self._dem_path.replace(".png", "_grayscale.png")
217
+ dem_data = cv2.imread(self._dem_path, cv2.IMREAD_GRAYSCALE)
218
+ dem_data_rgb = cv2.cvtColor(dem_data, cv2.COLOR_GRAY2RGB)
219
+ cv2.imwrite(rgb_dem_path, dem_data_rgb)
220
+ return rgb_dem_path
221
+
222
+ def colored_preview(self) -> str:
223
+ """Converts DEM image to colored RGB image and saves it to the map directory.
224
+ Returns path to the preview image.
225
+
226
+ Returns:
227
+ list[str]: List with a single path to the DEM file
228
+ """
229
+
230
+ colored_dem_path = self._dem_path.replace(".png", "_colored.png")
231
+ dem_data = cv2.imread(self._dem_path, cv2.IMREAD_GRAYSCALE)
232
+
233
+ # Normalize the DEM data to the range [0, 255]
234
+ # dem_data_normalized = cv2.normalize(dem_data, None, 0, 255, cv2.NORM_MINMAX)
235
+
236
+ dem_data_colored = cv2.applyColorMap(dem_data, cv2.COLORMAP_JET)
237
+
238
+ cv2.imwrite(colored_dem_path, dem_data_colored)
239
+ return colored_dem_path
240
+
241
+ def previews(self) -> list[str]:
242
+ """Get list of preview images.
243
+
244
+ Returns:
245
+ list[str]: List of preview images.
246
+ """
247
+ return [self.grayscale_preview(), self.colored_preview()]
maps4fs/generator/map.py CHANGED
@@ -6,11 +6,12 @@ from typing import Any
6
6
 
7
7
  from tqdm import tqdm
8
8
 
9
+ from maps4fs.generator.component import Component
9
10
  from maps4fs.generator.game import Game
10
11
  from maps4fs.logger import Logger
11
12
 
12
13
 
13
- # pylint: disable=R0913
14
+ # pylint: disable=R0913, R0902
14
15
  class Map:
15
16
  """Class used to generate map using all components.
16
17
 
@@ -35,6 +36,7 @@ class Map:
35
36
  logger: Any = None,
36
37
  ):
37
38
  self.game = game
39
+ self.components: list[Component] = []
38
40
  self.coordinates = coordinates
39
41
  self.distance = distance
40
42
  self.map_directory = map_directory
@@ -84,7 +86,8 @@ class Map:
84
86
  e,
85
87
  )
86
88
  raise e
87
- setattr(self, game_component.__name__.lower(), component)
89
+ # setattr(self, game_component.__name__.lower(), component)
90
+ self.components.append(component)
88
91
 
89
92
  pbar.update(1)
90
93
 
@@ -94,7 +97,13 @@ class Map:
94
97
  Returns:
95
98
  list[str]: List of preview images.
96
99
  """
97
- return self.texture.previews() # type: ignore # pylint: disable=no-member
100
+ # texture_previews = self.texture.previews() # type: ignore # pylint: disable=no-member
101
+ # dem_previews = self.dem.previews() # type: ignore # pylint: disable=no-member
102
+ # return texture_previews + dem_previews
103
+ previews = []
104
+ for component in self.components:
105
+ previews.extend(component.previews())
106
+ return previews
98
107
 
99
108
  def pack(self, archive_name: str) -> str:
100
109
  """Pack map directory to zip archive.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maps4fs
3
- Version: 0.6.8
3
+ Version: 0.7.0
4
4
  Summary: Generate map templates for Farming Simulator from real places.
5
5
  Author-email: iwatkot <iwatkot@gmail.com>
6
6
  License: MIT License
@@ -80,6 +80,24 @@ So, if you're new to map making, here's a quick overview of the process:
80
80
  3. Open the map template in the Giants Editor.
81
81
  4. Now you can start creating your map (adding roads, fields, buildings, etc.).
82
82
 
83
+ ### Previews
84
+
85
+ The generator also creates a multiple previews of the map. Here's the list of them:
86
+ 1. General preview - merging all the layers into one image with different colors.
87
+ 2. Grayscale DEM preview - a grayscale image of the height map (as it is).
88
+ 3. Colored DEM preview - a colored image of the height map (from blue to red). The blue color represents the lowest point, and the red color represents the highest point.
89
+
90
+ So the colored DEM preview can be very handy when you're trying to find the best value for the `max_height` parameter. Learn more about it in the [Settings](#settings) section.
91
+
92
+ ![Previews](https://github.com/user-attachments/assets/69609169-834b-4269-ac6a-9a5c56b629dc)<br>
93
+ In the second row of the image you can see the following images:<br>
94
+ 1. DEM preview with `max_height=200`.
95
+ 2. Colored DEM preview with `max_height=200`.
96
+ 3. Colored DEM preview with `max_height=50`.
97
+
98
+ As you can see there's a huge difference between images 2 and 3. The third (with lower `max_height`) will have a higher terrain contrast, and the second one will have lower differences between the terrain heights.<br>
99
+ There's no like "in real world" option, because FS system of coordinates does not work in meters or something like that when talking about DEM. So you need to experiment with the `max_height` parameter to get the desired result. To clarify: in the example above the difference on the platue is about 80 meters, so `max_height=50` made this like super mountainous terrain, and `max_height=200` made it like a plain.
100
+
83
101
  ## How-To-Run
84
102
 
85
103
  You'll find detailed instructions on how to run the project below. But if you prefer video tutorials, here's one for you:
@@ -0,0 +1,14 @@
1
+ maps4fs/__init__.py,sha256=da4jmND2Ths9AffnkAKgzLHNkvKFOc_l21gJisPXqWY,155
2
+ maps4fs/logger.py,sha256=CneeHxQywjNUJXqQrUUSeiDxu95FfrfyK_Si1v0gMZ8,1477
3
+ maps4fs/generator/__init__.py,sha256=zZMLEkGzb4z0xql650gOtGSvcgX58DnJ2yN3vC2daRk,43
4
+ maps4fs/generator/component.py,sha256=Xq5yVFMqG1d1iHTtn2mn5RN-UntsutXIvV5eQYBuFLw,2046
5
+ maps4fs/generator/config.py,sha256=wlGacB69fdcvggfEDvCpx5gzPRKq_4Sh6xuX-z-kwwE,2043
6
+ maps4fs/generator/dem.py,sha256=xOKHvWIMD-7nIWGQNQi6Tan1Ovb1EPfHHVnUfUIC31k,10004
7
+ maps4fs/generator/game.py,sha256=IyXjNEC5epJmDdqjsrl4wKL85T1F23km73pUkBiuDWU,4468
8
+ maps4fs/generator/map.py,sha256=bqog38u2fltYdC1xgfeC0ehboL7Vp7V6nJq0NQOI9lA,4157
9
+ maps4fs/generator/texture.py,sha256=f5dPD5q17CTg8aY6G3i33vFk9ckbpndVb1W3hbT1wL4,15318
10
+ maps4fs-0.7.0.dist-info/LICENSE.md,sha256=-JY0v7p3dwXze61EbYiK7YEJ2aKrjaFZ8y2xYEOrmRY,1068
11
+ maps4fs-0.7.0.dist-info/METADATA,sha256=559aJEFn3HctVKqakqaBoTVA6xLY8WTNQsKTlFG-icE,12187
12
+ maps4fs-0.7.0.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
13
+ maps4fs-0.7.0.dist-info/top_level.txt,sha256=Ue9DSRlejRQRCaJueB0uLcKrWwsEq9zezfv5dI5mV1M,8
14
+ maps4fs-0.7.0.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- maps4fs/__init__.py,sha256=da4jmND2Ths9AffnkAKgzLHNkvKFOc_l21gJisPXqWY,155
2
- maps4fs/logger.py,sha256=CneeHxQywjNUJXqQrUUSeiDxu95FfrfyK_Si1v0gMZ8,1477
3
- maps4fs/generator/__init__.py,sha256=zZMLEkGzb4z0xql650gOtGSvcgX58DnJ2yN3vC2daRk,43
4
- maps4fs/generator/component.py,sha256=UmR6Gbs-uDld7897q_9hOOzqBXaIYD8svmw_a3IgC5g,1761
5
- maps4fs/generator/config.py,sha256=3X9E6luYh0dBlYcGvE4Exzp-ShAMCFjGB_8SK3qPBtM,1760
6
- maps4fs/generator/dem.py,sha256=_1d_TPMOGBgl2-R_CRMbKumzxCbQyb-hcpqsElhYbQ4,8546
7
- maps4fs/generator/game.py,sha256=IyXjNEC5epJmDdqjsrl4wKL85T1F23km73pUkBiuDWU,4468
8
- maps4fs/generator/map.py,sha256=Y7ERUB6ivxJilDAjE9UD0-vl0SKtzj6J2f8QPXM6i48,3712
9
- maps4fs/generator/texture.py,sha256=f5dPD5q17CTg8aY6G3i33vFk9ckbpndVb1W3hbT1wL4,15318
10
- maps4fs-0.6.8.dist-info/LICENSE.md,sha256=-JY0v7p3dwXze61EbYiK7YEJ2aKrjaFZ8y2xYEOrmRY,1068
11
- maps4fs-0.6.8.dist-info/METADATA,sha256=q6HMaXkmT1mkfskzOS9EQrTILUTfAIb_D5BJF4ObMKc,10652
12
- maps4fs-0.6.8.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
13
- maps4fs-0.6.8.dist-info/top_level.txt,sha256=Ue9DSRlejRQRCaJueB0uLcKrWwsEq9zezfv5dI5mV1M,8
14
- maps4fs-0.6.8.dist-info/RECORD,,