Skip to content

Commit

Permalink
style: 🚨 black + isort
Browse files Browse the repository at this point in the history
  • Loading branch information
qthequartermasterman committed Dec 29, 2023
1 parent 470339a commit 609e7a6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 112 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[tool.semantic_release]
major_on_zero = false
major_on_zero = false

[tool.black]
line-length = 120
4 changes: 1 addition & 3 deletions render_map/auto_populate/auto_populate_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def on_page_markdown(
latitude, longitude = config.extra["auto_populate"]["center"]
radius = config.extra["auto_populate"]["population_radius"]

geolinks, markdown = auto_populate_map.find_auto_populate_geotags(
markdown, latitude, longitude, radius
)
geolinks, markdown = auto_populate_map.find_auto_populate_geotags(markdown, latitude, longitude, radius)

return markdown
58 changes: 12 additions & 46 deletions render_map/auto_populate/auto_populate_map.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Automatically populate the map with supermarkets and other landmarks using the Overpass (Open Street Map) API."""
from __future__ import annotations

from typing import TypeVar, Sequence, Hashable, Callable, TypeAlias
from typing import Callable, Hashable, Sequence, TypeAlias, TypeVar

import bs4
import mkdocs.plugins
Expand All @@ -13,9 +13,7 @@
LOGGER = mkdocs.plugins.get_plugin_logger(__name__)

T = TypeVar("T")
NameZoomIcon: TypeAlias = tuple[
str | None, mapping.ZoomLevel, mapping.map_icons.MapIcon
]
NameZoomIcon: TypeAlias = tuple[str | None, mapping.ZoomLevel, mapping.map_icons.MapIcon]


SUPER_MARKET_QUERY = """[out:json];
Expand Down Expand Up @@ -122,7 +120,7 @@ def find_auto_populate_geotags(
geotag_config = AutoPopulateConfig.from_dict(result)
populate_geotags_configs.append(geotag_config)

# Replace the geotag with a the list of supermarkets
# Replace the geotag with a list of supermarkets
bulleted_list = soup.new_tag("div")
if geotag_config.supermarket:
populate_tags(
Expand Down Expand Up @@ -172,9 +170,7 @@ def populate_tags(
Returns:
A string of geotags for the supermarkets.
"""
tags = populate_features(
query, feature_type_name, choose_name_function, radius, latitude, longitude
)
tags = populate_features(query, feature_type_name, choose_name_function, radius, latitude, longitude)
for tag in tags:
# Convert a geotag to a bulleted list, modifying the `parent_tag` in place.
parent_tag.append("- ")
Expand All @@ -196,33 +192,15 @@ def choose_supermarket_name_zoom_icon(node: overpy.Node) -> NameZoomIcon:
name_from_node = node.tags.get("name", None)
# If the supermarket is not named in OpenStreetMap, we'll (unfairly) assume it's not a very important supermarket.
if name_from_node is None:
return (
None,
mapping.ZoomLevel.WASTELAND,
mapping.map_icons.MapIcon.SUPER_DUPER_MART,
)
return None, mapping.ZoomLevel.WASTELAND, mapping.map_icons.MapIcon.SUPER_DUPER_MART
# Super-Duper Mart is implied to be a chain of very large supermarkets, likely wholesale. In the video games, there
# is only one Super-Duper Mart in its corresponding city metro-area.
if (
"walmart" in name_from_node.lower()
or "sam's" in name_from_node.lower()
or "costco" in name_from_node.lower()
):
if "walmart" in name_from_node.lower() or "sam's" in name_from_node.lower() or "costco" in name_from_node.lower():
# Only a quarter of the supermarkets should be visible from the large wasteland map.
zoom_level = (
mapping.ZoomLevel.TOWN if node.id % 4 else mapping.ZoomLevel.WASTELAND
)
return (
"Super-Duper Mart",
zoom_level,
mapping.map_icons.MapIcon.SUPER_DUPER_MART,
)
zoom_level = mapping.ZoomLevel.TOWN if node.id % 4 else mapping.ZoomLevel.WASTELAND
return "Super-Duper Mart", zoom_level, mapping.map_icons.MapIcon.SUPER_DUPER_MART
# TODO: Provide more plausible and generic names for super markets.
return (
"Supermarket",
mapping.ZoomLevel.TOWN,
mapping.map_icons.MapIcon.SUPER_DUPER_MART,
)
return "Supermarket", mapping.ZoomLevel.TOWN, mapping.map_icons.MapIcon.SUPER_DUPER_MART


def choose_gas_station_name_zoom_icon(node: overpy.Node | overpy.Way) -> NameZoomIcon:
Expand All @@ -240,11 +218,7 @@ def choose_gas_station_name_zoom_icon(node: overpy.Node | overpy.Way) -> NameZoo
# Womb-ee's is a fictional gas station chain in the Fallout: Houston campaign.
# It is a parody of Buc-ee's, a real gas station chain in Texas.
if "buc-ee" in name_from_node.lower() or "buc-ee" in brand_from_node.lower():
return (
"Womb-ee's",
mapping.ZoomLevel.WASTELAND,
mapping.map_icons.MapIcon.BEAVER,
)
return "Womb-ee's", mapping.ZoomLevel.WASTELAND, mapping.map_icons.MapIcon.BEAVER
# If the gas station is not named in OpenStreetMap, we'll (unfairly) assume it's not very important.
if name_from_node is None:
return None, mapping.ZoomLevel.WASTELAND, mapping.map_icons.MapIcon.GAS_STATION
Expand Down Expand Up @@ -292,11 +266,7 @@ def populate_features(
continue
latitude = way.center_lat or way.nodes[0].lat
longitude = way.center_lon or way.nodes[0].lon
geotags.append(
mapping.GeoLink(
name=name, latitude=latitude, longitude=longitude, zoom=zoom, icon=icon
)
)
geotags.append(mapping.GeoLink(name=name, latitude=latitude, longitude=longitude, zoom=zoom, icon=icon))

for node in features.nodes:
if node.id in node_ids_to_ignore:
Expand All @@ -305,10 +275,6 @@ def populate_features(
# Skip over unnamed features (they're likely not important enough to show up on the game map).
if name is None:
continue
geotags.append(
mapping.GeoLink(
name=name, latitude=node.lat, longitude=node.lon, zoom=zoom, icon=icon
)
)
geotags.append(mapping.GeoLink(name=name, latitude=node.lat, longitude=node.lon, zoom=zoom, icon=icon))
LOGGER.info(f"Added {len(geotags)} {feature_type_name}.")
return [geotag.get_tag() for geotag in geotags]
56 changes: 14 additions & 42 deletions render_map/map_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@


class MapIcon(enum.Enum):
SETTLEMENT = (
"https://static.wikia.nocookie.net/fallout_gamepedia/images/f/f9/163.svg"
)
SETTLEMENT = "https://static.wikia.nocookie.net/fallout_gamepedia/images/f/f9/163.svg"
FARM = "https://static.wikia.nocookie.net/fallout_gamepedia/images/3/32/156.svg"
LARGE_SETTLEMENT = (
"https://static.wikia.nocookie.net/fallout_gamepedia/images/8/8a/38.svg"
)
LARGE_SETTLEMENT = "https://static.wikia.nocookie.net/fallout_gamepedia/images/8/8a/38.svg"

ROCKET = "https://static.wikia.nocookie.net/fallout_gamepedia/images/c/ce/153.svg"
GAS_STATION = (
"https://game-icons.net/icons/ffffff/000000/1x1/delapouite/gas-pump.png"
)
GAS_STATION = "https://game-icons.net/icons/ffffff/000000/1x1/delapouite/gas-pump.png"
POSEIDON = "https://game-icons.net/icons/ffffff/000000/1x1/lorc/trident.png"
SOMBRERO = "https://game-icons.net/icons/ffffff/000000/1x1/delapouite/sombrero.png"
BEAVER = "https://game-icons.net/icons/ffffff/000000/1x1/delapouite/beaver.png"
Expand All @@ -27,37 +21,27 @@ class MapIcon(enum.Enum):
WAREHOUSE = "https://static.wikia.nocookie.net/fallout_gamepedia/images/0/03/99.svg"

MONUMENT = "https://static.wikia.nocookie.net/fallout_gamepedia/images/6/6a/209.svg"
CLOCK_TOWER = (
"https://static.wikia.nocookie.net/fallout_gamepedia/images/2/21/182.svg"
)
CLOCK_TOWER = "https://static.wikia.nocookie.net/fallout_gamepedia/images/2/21/182.svg"

BASEBALL = "https://static.wikia.nocookie.net/fallout_gamepedia/images/b/bd/176.svg"

BROTHERHOOD_OF_STEEL = (
"https://static.wikia.nocookie.net/fallout_gamepedia/images/0/01/215.svg"
)
BROTHERHOOD_OF_STEEL = "https://static.wikia.nocookie.net/fallout_gamepedia/images/0/01/215.svg"

AIRPORT = "https://static.wikia.nocookie.net/fallout_gamepedia/images/e/eb/218.svg"

VAULT = "https://static.wikia.nocookie.net/fallout_gamepedia/images/1/12/8.svg"

TREE = "https://static.wikia.nocookie.net/fallout_gamepedia/images/4/41/Tree.svg/"

RADIATION = (
"https://static.wikia.nocookie.net/fallout_gamepedia/images/5/5c/65.svg/"
)
RADIATION = "https://static.wikia.nocookie.net/fallout_gamepedia/images/5/5c/65.svg/"

GOVERNMENT = (
"https://static.wikia.nocookie.net/fallout_gamepedia/images/2/2e/105.svg"
)
GOVERNMENT = "https://static.wikia.nocookie.net/fallout_gamepedia/images/2/2e/105.svg"
MILITARY = "https://static.wikia.nocookie.net/fallout_gamepedia/images/5/50/111.svg"
CHURCH = "https://static.wikia.nocookie.net/fallout_gamepedia/images/2/2c/191.svg"
CITY = "https://static.wikia.nocookie.net/fallout_gamepedia/images/e/ee/188.svg"
HOSPITAL = "https://static.wikia.nocookie.net/fallout_gamepedia/images/4/40/141.svg"
FACTORY = "https://static.wikia.nocookie.net/fallout_gamepedia/images/3/3e/135.svg"
WATER_TREATMENT = (
"https://static.wikia.nocookie.net/fallout_gamepedia/images/a/a7/138.svg"
)
WATER_TREATMENT = "https://static.wikia.nocookie.net/fallout_gamepedia/images/a/a7/138.svg"
SCIENCE = FACTORY

SWAMP = "https://static.wikia.nocookie.net/fallout_gamepedia/images/f/fe/85.svg"
Expand All @@ -66,23 +50,17 @@ class MapIcon(enum.Enum):
LIGHT = "https://static.wikia.nocookie.net/fallout_gamepedia/images/e/ed/59.svg"
RADIO = "https://static.wikia.nocookie.net/fallout_gamepedia/images/6/64/62.svg"

DOOR_TARGET = (
"https://static.wikia.nocookie.net/fallout_gamepedia/images/0/03/68.svg"
)
DOOR_TARGET = "https://static.wikia.nocookie.net/fallout_gamepedia/images/0/03/68.svg"
FOOD = SETTLEMENT
WATER = "https://static.wikia.nocookie.net/fallout_gamepedia/images/b/bd/35.svg"
POWER = RADIATION
DEFENSE = "https://static.wikia.nocookie.net/fallout_gamepedia/images/e/e4/197.svg"
CARAVAN = WAREHOUSE
INN = DOOR_TARGET

SUPER_DUPER_MART = (
"https://static.wikia.nocookie.net/fallout_gamepedia/images/e/e9/14.svg"
)
SUPER_DUPER_MART = "https://static.wikia.nocookie.net/fallout_gamepedia/images/e/e9/14.svg"
CEMETARY = "https://static.wikia.nocookie.net/fallout_gamepedia/images/d/df/144.svg"
RICE_VILLAGE = (
"https://static.wikia.nocookie.net/fallout_gamepedia/images/c/c8/147.svg"
)
RICE_VILLAGE = "https://static.wikia.nocookie.net/fallout_gamepedia/images/c/c8/147.svg"

DRIVE_IN = "https://static.wikia.nocookie.net/fallout_gamepedia/images/5/51/169.svg"
CAR = "https://static.wikia.nocookie.net/fallout_gamepedia/images/3/31/200.svg"
Expand All @@ -91,21 +69,15 @@ class MapIcon(enum.Enum):

MINE = "https://static.wikia.nocookie.net/fallout_gamepedia/images/0/0f/76.svg"
BUNKER = "https://static.wikia.nocookie.net/fallout_gamepedia/images/f/f3/206.svg"
TRAILER_PARK = (
"https://static.wikia.nocookie.net/fallout_gamepedia/images/b/b4/203.svg"
)
TRAILER_PARK = "https://static.wikia.nocookie.net/fallout_gamepedia/images/b/b4/203.svg"

STATUE = "https://static.wikia.nocookie.net/fallout_gamepedia/images/b/be/50.svg/"
POLICE = "https://static.wikia.nocookie.net/fallout_gamepedia/images/3/3d/88.svg"
AMUSEMENT_PARK = (
"https://static.wikia.nocookie.net/fallout_gamepedia/images/8/84/185.svg"
)
AMUSEMENT_PARK = "https://static.wikia.nocookie.net/fallout_gamepedia/images/8/84/185.svg"

SQUARE = "https://static.wikia.nocookie.net/fallout_gamepedia/images/e/eb/173.svg"

OVERPASS = "https://static.wikia.nocookie.net/fallout_gamepedia/images/a/a1/166.svg"

BEACH = "https://static.wikia.nocookie.net/fallout_gamepedia/images/f/fa/123.svg"
PLANETARIUM = (
"https://static.wikia.nocookie.net/fallout_gamepedia/images/1/14/102.svg"
)
PLANETARIUM = "https://static.wikia.nocookie.net/fallout_gamepedia/images/1/14/102.svg"
28 changes: 8 additions & 20 deletions render_map/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import pathlib
import re
import uuid
from typing import Type, TypeVar

import bs4
import mkdocs.plugins
import pydantic
import bs4
from typing import TypeVar, Type

from render_map import map_icons, map_style

Expand All @@ -30,9 +30,7 @@
/>"""

MAP_STYLE_JSON = map_style.green_style
MAP_TEMPLATE = (pathlib.Path(__file__).parent / "map_template.html").read_text(
encoding="utf-8"
)
MAP_TEMPLATE = (pathlib.Path(__file__).parent / "map_template.html").read_text(encoding="utf-8")
MAP_TEMPLATE = MAP_TEMPLATE.replace("{{STYLE}}", json.dumps(MAP_STYLE_JSON))


Expand All @@ -49,9 +47,7 @@ class GeoLink(pydantic.BaseModel):
name: str
latitude: float
longitude: float
icon: map_icons.MapIcon = pydantic.Field(
default=map_icons.MapIcon.SETTLEMENT, validate_default=True
)
icon: map_icons.MapIcon = pydantic.Field(default=map_icons.MapIcon.SETTLEMENT, validate_default=True)
zoom: ZoomLevel = pydantic.Field(default=ZoomLevel.WASTELAND, validate_default=True)
uuid: str = pydantic.Field(default_factory=lambda: str(uuid.uuid4()))

Expand Down Expand Up @@ -80,9 +76,7 @@ def get_tag(self, include_uuid: bool = False) -> bs4.Tag:
GEO_LINKS: list[GeoLink] = []


def resolve_enum(
result: dict[str, str], enum_type: Type[EnumType], enum_key: str
) -> None:
def resolve_enum(result: dict[str, str], enum_type: Type[EnumType], enum_key: str) -> None:
"""Resolve an enum from a string.
If the enum key is in the result, then the enum is resolved. If the value of the enum key is empty, then the enum is removed from the result.
Expand Down Expand Up @@ -139,15 +133,9 @@ def create_map_template(config: mkdocs.plugins.MkDocsConfig) -> str:
The map template.
"""
map_source = MAP_TEMPLATE
map_source = map_source.replace(
"{{MAP_CENTER}}", json.dumps(config.extra["global_map"]["center"])
)
map_source = map_source.replace(
"{{MAP_ZOOM}}", json.dumps(config.extra["global_map"]["zoom"])
)
map_source = map_source.replace(
"{{GOOGLE_MAPS_API_KEY}}", str(config.extra["GOOGLE_MAPS_API_KEY"])
)
map_source = map_source.replace("{{MAP_CENTER}}", json.dumps(config.extra["global_map"]["center"]))
map_source = map_source.replace("{{MAP_ZOOM}}", json.dumps(config.extra["global_map"]["zoom"]))
map_source = map_source.replace("{{GOOGLE_MAPS_API_KEY}}", str(config.extra["GOOGLE_MAPS_API_KEY"]))
markers = [geo_link.model_dump() for geo_link in GEO_LINKS]
map_source = map_source.replace("{{MARKERS}}", json.dumps(markers))

Expand Down

0 comments on commit 609e7a6

Please sign in to comment.