maps4fs 1.5.4__py3-none-any.whl → 1.5.6__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.
maps4fs/__init__.py CHANGED
@@ -1,12 +1,12 @@
1
1
  # pylint: disable=missing-module-docstring
2
2
  from maps4fs.generator.dtm import DTMProvider
3
3
  from maps4fs.generator.game import Game
4
- from maps4fs.generator.map import (
4
+ from maps4fs.generator.map import Map
5
+ from maps4fs.generator.settings import (
5
6
  BackgroundSettings,
6
7
  DEMSettings,
7
8
  GRLESettings,
8
9
  I3DSettings,
9
- Map,
10
10
  SettingsModel,
11
11
  SplineSettings,
12
12
  TextureSettings,
maps4fs/generator/dem.py CHANGED
@@ -61,6 +61,7 @@ class DEM(Component):
61
61
 
62
62
  self.dtm_provider: DTMProvider = self.map.dtm_provider( # type: ignore
63
63
  coordinates=self.coordinates,
64
+ user_settings=self.map.dtm_provider_settings,
64
65
  size=self.map_rotated_size,
65
66
  directory=self.temp_dir,
66
67
  logger=self.logger,
maps4fs/generator/dtm.py CHANGED
@@ -14,10 +14,15 @@ import numpy as np
14
14
  import osmnx as ox # type: ignore
15
15
  import rasterio # type: ignore
16
16
  import requests
17
+ from pydantic import BaseModel
17
18
 
18
19
  from maps4fs.logger import Logger
19
20
 
20
21
 
22
+ class DTMProviderSettings(BaseModel):
23
+ """Base class for DTM provider settings models."""
24
+
25
+
21
26
  class DTMProvider:
22
27
  """Base class for DTM providers."""
23
28
 
@@ -29,8 +34,23 @@ class DTMProvider:
29
34
 
30
35
  _url: str | None = None
31
36
 
32
- def __init__(self, coordinates: tuple[float, float], size: int, directory: str, logger: Logger):
37
+ _author: str | None = None
38
+ _is_community: bool = False
39
+ _settings: Type[DTMProviderSettings] | None = None
40
+
41
+ _instructions: str | None = None
42
+
43
+ # pylint: disable=R0913, R0917
44
+ def __init__(
45
+ self,
46
+ coordinates: tuple[float, float],
47
+ user_settings: DTMProviderSettings | None,
48
+ size: int,
49
+ directory: str,
50
+ logger: Logger,
51
+ ):
33
52
  self._coordinates = coordinates
53
+ self._user_settings = user_settings
34
54
  self._size = size
35
55
 
36
56
  if not self._code:
@@ -69,6 +89,51 @@ class DTMProvider:
69
89
  raise ValueError("URL must be defined.")
70
90
  return self.url.format(**kwargs)
71
91
 
92
+ @classmethod
93
+ def author(cls) -> str | None:
94
+ """Author of the provider.
95
+
96
+ Returns:
97
+ str: Author of the provider.
98
+ """
99
+ return cls._author
100
+
101
+ @classmethod
102
+ def is_community(cls) -> bool:
103
+ """Is the provider a community-driven project.
104
+
105
+ Returns:
106
+ bool: True if the provider is a community-driven project, False otherwise.
107
+ """
108
+ return cls._is_community
109
+
110
+ @classmethod
111
+ def settings(cls) -> Type[DTMProviderSettings] | None:
112
+ """Settings model of the provider.
113
+
114
+ Returns:
115
+ Type[DTMProviderSettings]: Settings model of the provider.
116
+ """
117
+ return cls._settings
118
+
119
+ @classmethod
120
+ def instructions(cls) -> str | None:
121
+ """Instructions for using the provider.
122
+
123
+ Returns:
124
+ str: Instructions for using the provider.
125
+ """
126
+ return cls._instructions
127
+
128
+ @property
129
+ def user_settings(self) -> DTMProviderSettings | None:
130
+ """User settings of the provider.
131
+
132
+ Returns:
133
+ DTMProviderSettings: User settings of the provider.
134
+ """
135
+ return self._user_settings
136
+
72
137
  @classmethod
73
138
  def description(cls) -> str:
74
139
  """Description of the provider.
@@ -211,6 +276,8 @@ class SRTM30Provider(DTMProvider):
211
276
 
212
277
  _url = "https://elevation-tiles-prod.s3.amazonaws.com/skadi/{latitude_band}/{tile_name}.hgt.gz"
213
278
 
279
+ _author = "[iwatkot](https://github.com/iwatkot)"
280
+
214
281
  def __init__(self, *args, **kwargs):
215
282
  super().__init__(*args, **kwargs)
216
283
  self.hgt_directory = os.path.join(self._tile_directory, "hgt")
maps4fs/generator/map.py CHANGED
@@ -7,159 +7,21 @@ import os
7
7
  import shutil
8
8
  from typing import Any, Generator
9
9
 
10
- from pydantic import BaseModel
11
-
12
10
  from maps4fs.generator.component import Component
13
- from maps4fs.generator.dtm import DTMProvider
11
+ from maps4fs.generator.dtm import DTMProvider, DTMProviderSettings
14
12
  from maps4fs.generator.game import Game
13
+ from maps4fs.generator.settings import (
14
+ BackgroundSettings,
15
+ DEMSettings,
16
+ GRLESettings,
17
+ I3DSettings,
18
+ SatelliteSettings,
19
+ SplineSettings,
20
+ TextureSettings,
21
+ )
15
22
  from maps4fs.logger import Logger
16
23
 
17
24
 
18
- class SettingsModel(BaseModel):
19
- """Base class for settings models. It provides methods to convert settings to and from JSON."""
20
-
21
- @classmethod
22
- def all_settings_to_json(cls) -> dict[str, dict[str, Any]]:
23
- """Get all settings of the current class and its subclasses as a dictionary.
24
-
25
- Returns:
26
- dict[str, dict[str, Any]]: Dictionary with settings of the current class and its
27
- subclasses.
28
- """
29
- all_settings = {}
30
- for subclass in cls.__subclasses__():
31
- all_settings[subclass.__name__] = subclass().model_dump()
32
-
33
- return all_settings
34
-
35
- @classmethod
36
- def all_settings_from_json(cls, data: dict) -> dict[str, SettingsModel]:
37
- """Create settings instances from JSON data.
38
-
39
- Arguments:
40
- data (dict): JSON data.
41
-
42
- Returns:
43
- dict[str, Type[SettingsModel]]: Dictionary with settings instances.
44
- """
45
- settings = {}
46
- for subclass in cls.__subclasses__():
47
- settings[subclass.__name__] = subclass(**data[subclass.__name__])
48
-
49
- return settings
50
-
51
- @classmethod
52
- def all_settings(cls) -> list[SettingsModel]:
53
- """Get all settings of the current class and its subclasses.
54
-
55
- Returns:
56
- list[SettingsModel]: List with settings of the current class and its subclasses.
57
- """
58
- settings = []
59
- for subclass in cls.__subclasses__():
60
- settings.append(subclass())
61
-
62
- return settings
63
-
64
-
65
- class DEMSettings(SettingsModel):
66
- """Represents the advanced settings for DEM component.
67
-
68
- Attributes:
69
- auto_process (bool): use the auto preset to change the multiplier.
70
- multiplier (int): multiplier for the heightmap, every pixel will be multiplied by this
71
- value.
72
- blur_radius (int): radius of the blur filter.
73
- plateau (int): plateau height, will be added to each pixel.
74
- water_depth (int): water depth, will be subtracted from each pixel where the water
75
- is present.
76
- """
77
-
78
- auto_process: bool = True
79
- multiplier: int = 1
80
- blur_radius: int = 35
81
- plateau: int = 0
82
- water_depth: int = 0
83
-
84
-
85
- class BackgroundSettings(SettingsModel):
86
- """Represents the advanced settings for background component.
87
-
88
- Attributes:
89
- generate_background (bool): generate obj files for the background terrain.
90
- generate_water (bool): generate obj files for the water.
91
- resize_factor (int): resize factor for the background terrain and water.
92
- It will be used as 1 / resize_factor of the original size.
93
- """
94
-
95
- generate_background: bool = False
96
- generate_water: bool = False
97
- resize_factor: int = 8
98
-
99
-
100
- class GRLESettings(SettingsModel):
101
- """Represents the advanced settings for GRLE component.
102
-
103
- Attributes:
104
- farmland_margin (int): margin around the farmland.
105
- random_plants (bool): generate random plants on the map or use the default one.
106
- add_farmyards (bool): If True, regions of frarmyards will be added to the map
107
- without corresponding fields.
108
- """
109
-
110
- farmland_margin: int = 0
111
- random_plants: bool = True
112
- add_farmyards: bool = False
113
-
114
-
115
- class I3DSettings(SettingsModel):
116
- """Represents the advanced settings for I3D component.
117
-
118
- Attributes:
119
- forest_density (int): density of the forest (distance between trees).
120
- """
121
-
122
- forest_density: int = 10
123
-
124
-
125
- class TextureSettings(SettingsModel):
126
- """Represents the advanced settings for texture component.
127
-
128
- Attributes:
129
- dissolve (bool): dissolve the texture into several images.
130
- fields_padding (int): padding around the fields.
131
- skip_drains (bool): skip drains generation.
132
- """
133
-
134
- dissolve: bool = False
135
- fields_padding: int = 0
136
- skip_drains: bool = False
137
-
138
-
139
- class SplineSettings(SettingsModel):
140
- """Represents the advanced settings for spline component.
141
-
142
- Attributes:
143
- spline_density (int): the number of extra points that will be added between each two
144
- existing points.
145
- """
146
-
147
- spline_density: int = 2
148
-
149
-
150
- class SatelliteSettings(SettingsModel):
151
- """Represents the advanced settings for satellite component.
152
-
153
- Attributes:
154
- download_images (bool): download satellite images.
155
- margin (int): margin around the map.
156
- """
157
-
158
- download_images: bool = False
159
- satellite_margin: int = 100
160
- zoom_level: int = 14
161
-
162
-
163
25
  # pylint: disable=R0913, R0902, R0914
164
26
  class Map:
165
27
  """Class used to generate map using all components.
@@ -176,6 +38,7 @@ class Map:
176
38
  self,
177
39
  game: Game,
178
40
  dtm_provider: DTMProvider,
41
+ dtm_provider_settings: DTMProviderSettings,
179
42
  coordinates: tuple[float, float],
180
43
  size: int,
181
44
  rotation: int,
@@ -206,6 +69,7 @@ class Map:
206
69
 
207
70
  self.game = game
208
71
  self.dtm_provider = dtm_provider
72
+ self.dtm_provider_settings = dtm_provider_settings
209
73
  self.components: list[Component] = []
210
74
  self.coordinates = coordinates
211
75
  self.map_directory = map_directory
@@ -0,0 +1,152 @@
1
+ """This module contains settings models for all components."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from pydantic import BaseModel
8
+
9
+
10
+ class SettingsModel(BaseModel):
11
+ """Base class for settings models. It provides methods to convert settings to and from JSON."""
12
+
13
+ @classmethod
14
+ def all_settings_to_json(cls) -> dict[str, dict[str, Any]]:
15
+ """Get all settings of the current class and its subclasses as a dictionary.
16
+
17
+ Returns:
18
+ dict[str, dict[str, Any]]: Dictionary with settings of the current class and its
19
+ subclasses.
20
+ """
21
+ all_settings = {}
22
+ for subclass in cls.__subclasses__():
23
+ all_settings[subclass.__name__] = subclass().model_dump()
24
+
25
+ return all_settings
26
+
27
+ @classmethod
28
+ def all_settings_from_json(cls, data: dict) -> dict[str, SettingsModel]:
29
+ """Create settings instances from JSON data.
30
+
31
+ Arguments:
32
+ data (dict): JSON data.
33
+
34
+ Returns:
35
+ dict[str, Type[SettingsModel]]: Dictionary with settings instances.
36
+ """
37
+ settings = {}
38
+ for subclass in cls.__subclasses__():
39
+ settings[subclass.__name__] = subclass(**data[subclass.__name__])
40
+
41
+ return settings
42
+
43
+ @classmethod
44
+ def all_settings(cls) -> list[SettingsModel]:
45
+ """Get all settings of the current class and its subclasses.
46
+
47
+ Returns:
48
+ list[SettingsModel]: List with settings of the current class and its subclasses.
49
+ """
50
+ settings = []
51
+ for subclass in cls.__subclasses__():
52
+ settings.append(subclass())
53
+
54
+ return settings
55
+
56
+
57
+ class DEMSettings(SettingsModel):
58
+ """Represents the advanced settings for DEM component.
59
+
60
+ Attributes:
61
+ auto_process (bool): use the auto preset to change the multiplier.
62
+ multiplier (int): multiplier for the heightmap, every pixel will be multiplied by this
63
+ value.
64
+ blur_radius (int): radius of the blur filter.
65
+ plateau (int): plateau height, will be added to each pixel.
66
+ water_depth (int): water depth, will be subtracted from each pixel where the water
67
+ is present.
68
+ """
69
+
70
+ auto_process: bool = True
71
+ multiplier: int = 1
72
+ blur_radius: int = 35
73
+ plateau: int = 0
74
+ water_depth: int = 0
75
+
76
+
77
+ class BackgroundSettings(SettingsModel):
78
+ """Represents the advanced settings for background component.
79
+
80
+ Attributes:
81
+ generate_background (bool): generate obj files for the background terrain.
82
+ generate_water (bool): generate obj files for the water.
83
+ resize_factor (int): resize factor for the background terrain and water.
84
+ It will be used as 1 / resize_factor of the original size.
85
+ """
86
+
87
+ generate_background: bool = False
88
+ generate_water: bool = False
89
+ resize_factor: int = 8
90
+
91
+
92
+ class GRLESettings(SettingsModel):
93
+ """Represents the advanced settings for GRLE component.
94
+
95
+ Attributes:
96
+ farmland_margin (int): margin around the farmland.
97
+ random_plants (bool): generate random plants on the map or use the default one.
98
+ add_farmyards (bool): If True, regions of frarmyards will be added to the map
99
+ without corresponding fields.
100
+ """
101
+
102
+ farmland_margin: int = 0
103
+ random_plants: bool = True
104
+ add_farmyards: bool = False
105
+
106
+
107
+ class I3DSettings(SettingsModel):
108
+ """Represents the advanced settings for I3D component.
109
+
110
+ Attributes:
111
+ forest_density (int): density of the forest (distance between trees).
112
+ """
113
+
114
+ forest_density: int = 10
115
+
116
+
117
+ class TextureSettings(SettingsModel):
118
+ """Represents the advanced settings for texture component.
119
+
120
+ Attributes:
121
+ dissolve (bool): dissolve the texture into several images.
122
+ fields_padding (int): padding around the fields.
123
+ skip_drains (bool): skip drains generation.
124
+ """
125
+
126
+ dissolve: bool = False
127
+ fields_padding: int = 0
128
+ skip_drains: bool = False
129
+
130
+
131
+ class SplineSettings(SettingsModel):
132
+ """Represents the advanced settings for spline component.
133
+
134
+ Attributes:
135
+ spline_density (int): the number of extra points that will be added between each two
136
+ existing points.
137
+ """
138
+
139
+ spline_density: int = 2
140
+
141
+
142
+ class SatelliteSettings(SettingsModel):
143
+ """Represents the advanced settings for satellite component.
144
+
145
+ Attributes:
146
+ download_images (bool): download satellite images.
147
+ margin (int): margin around the map.
148
+ """
149
+
150
+ download_images: bool = False
151
+ satellite_margin: int = 100
152
+ zoom_level: int = 14
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: maps4fs
3
- Version: 1.5.4
3
+ Version: 1.5.6
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
@@ -1,23 +1,24 @@
1
- maps4fs/__init__.py,sha256=wXI0wsgNpS2Pr7GKPw4akJyChQzehMXNuwjF7vG81tA,346
1
+ maps4fs/__init__.py,sha256=EJzbqRrSGltSMUI-dHgONODxKt9YvP_ElwFmXV8M_MA,380
2
2
  maps4fs/logger.py,sha256=B-NEYpMjPAAqlV4VpfTi6nbBFnEABVtQOaYe6nMpidg,1489
3
3
  maps4fs/generator/__init__.py,sha256=zZMLEkGzb4z0xql650gOtGSvcgX58DnJ2yN3vC2daRk,43
4
4
  maps4fs/generator/background.py,sha256=ySABP9HLji8R0aXi1BwjUQtP2uDqZPkrlmugowa9Gkk,22836
5
5
  maps4fs/generator/component.py,sha256=RtXruvT4Fxfr7_xo9Bi-i3IIWcPd5QQOSpYJ_cNC49o,20408
6
6
  maps4fs/generator/config.py,sha256=0QmK052B8bxyHVhg3jzCORLfOBMMmqVfhhbqXKf6OMk,4383
7
- maps4fs/generator/dem.py,sha256=hW9zNKX-MSUI-Cw7-x8tNMGF8NyzdVDLNjsCx4wHfuQ,12563
8
- maps4fs/generator/dtm.py,sha256=DsQsV4t0124-2xdr8L29JX-csD0XNOdCF0MFm1cZQF0,8872
7
+ maps4fs/generator/dem.py,sha256=aJva77k_00SKrqnRLF_BXr8eGR5flifrh72kSBq1saI,12621
8
+ maps4fs/generator/dtm.py,sha256=5_1e-kQcZ7c1Xg3tvuTyumzfTAcUPmDkIyZd5VagyOk,10550
9
9
  maps4fs/generator/game.py,sha256=QHgVnyGYvEnfwGZ84-u-dpbCRr3UeVVqBbrwr5WG8dE,7992
10
10
  maps4fs/generator/grle.py,sha256=u8ZwSs313PIOkH_0B_O2tVTaZ-eYNkc30eKGtBxWzTM,17846
11
11
  maps4fs/generator/i3d.py,sha256=qeZYqfuhbhRPlSAuQHXaq6RmIO7314oMN68Ivebp1YQ,24786
12
- maps4fs/generator/map.py,sha256=wLu8kexBgvHTO_RGnUupWoD-LMsoPXjNuPivgVH3zTw,13420
12
+ maps4fs/generator/map.py,sha256=flU0b2TrVYLxj9o3v_YRvNz9YB3s4w6YFSv4Jka5ojM,9283
13
13
  maps4fs/generator/qgis.py,sha256=Es8hLuqN_KH8lDfnJE6He2rWYbAKJ3RGPn-o87S6CPI,6116
14
14
  maps4fs/generator/satellite.py,sha256=Qnb6XxmXKnHdHKVMb9mJ3vDGtGkDHCOv_81hrrXdx3k,3660
15
+ maps4fs/generator/settings.py,sha256=gBMjXpz0hcUsCAw8MS_SsuFKHaI41RK6dclEEepsx2M,4575
15
16
  maps4fs/generator/texture.py,sha256=sErusfv1AqQfP-veMrZ921Tz8DnGEhfB4ucggMmKrD4,31231
16
17
  maps4fs/toolbox/__init__.py,sha256=zZMLEkGzb4z0xql650gOtGSvcgX58DnJ2yN3vC2daRk,43
17
18
  maps4fs/toolbox/background.py,sha256=9BXWNqs_n3HgqDiPztWylgYk_QM4YgBpe6_ZNQAWtSc,2154
18
19
  maps4fs/toolbox/dem.py,sha256=z9IPFNmYbjiigb3t02ZenI3Mo8odd19c5MZbjDEovTo,3525
19
- maps4fs-1.5.4.dist-info/LICENSE.md,sha256=pTKD_oUexcn-yccFCTrMeLkZy0ifLRa-VNcDLqLZaIw,10749
20
- maps4fs-1.5.4.dist-info/METADATA,sha256=UkTftX1zaae9QM1r7t994hyhk10dOASfocXg8KKbRRA,36012
21
- maps4fs-1.5.4.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
22
- maps4fs-1.5.4.dist-info/top_level.txt,sha256=Ue9DSRlejRQRCaJueB0uLcKrWwsEq9zezfv5dI5mV1M,8
23
- maps4fs-1.5.4.dist-info/RECORD,,
20
+ maps4fs-1.5.6.dist-info/LICENSE.md,sha256=pTKD_oUexcn-yccFCTrMeLkZy0ifLRa-VNcDLqLZaIw,10749
21
+ maps4fs-1.5.6.dist-info/METADATA,sha256=0OuPPRh06Av71q90zEiVokNCHSh7QLCULKjcBNyLoYA,36012
22
+ maps4fs-1.5.6.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
23
+ maps4fs-1.5.6.dist-info/top_level.txt,sha256=Ue9DSRlejRQRCaJueB0uLcKrWwsEq9zezfv5dI5mV1M,8
24
+ maps4fs-1.5.6.dist-info/RECORD,,