From ef291f56e551744cb276bc02db1f7eeea9d1da46 Mon Sep 17 00:00:00 2001 From: qthequartermasterman Date: Fri, 15 Dec 2023 16:17:37 -0600 Subject: [PATCH] docs: add geotags to Scarsdale locations --- docs/Background/geography/neighborhoods.md | 41 +++++---------- render_map/map_icons.py | 4 +- render_map/render_map.py | 59 +++++++++++++++------- 3 files changed, 55 insertions(+), 49 deletions(-) diff --git a/docs/Background/geography/neighborhoods.md b/docs/Background/geography/neighborhoods.md index 13ea23e..2994c10 100644 --- a/docs/Background/geography/neighborhoods.md +++ b/docs/Background/geography/neighborhoods.md @@ -671,35 +671,17 @@ The PC with the highest Charisma makes a settlement reputation test **(CHA + Rep - The residents keep an eye on the ghouls that inhabit the nearby Ellington Field ruins, but they have not had any major conflicts with them. ### Establishments -- Pipes Bar and Grill: A popular bar and restaurant where traders and travelers gather to exchange information and stories. The bar is owned by Lena "Pipes" Santos. -- Scarsdale Market: A bustling marketplace where traders from various factions converge to exchange goods and information. The market is overseen by the settlement's council of traders, with Trader Councilor Jenna Redwood overseeing day-to-day operations. -- Medical Clinic: A medical clinic run by Doctor Abigail Sterling who treats the settlement's residents and visitors. -- Scarsdale Outfitters: A general store that sells a variety of goods, including weapons, armor, and survival supplies. The store is run by a merchant Elias Cross who has connections with various factions. -- Scarsdale Caravan Company: A caravan company that provides transportation and security for traders and travelers. The company is run by the Caravan Master Barrett Stone who oversees the settlement's caravan operations. -- Motel: A motel that provides lodging for travelers and traders passing through the settlement. The motel is run by its manager Lily Harper who oversees the settlement's hospitality operations. -- Apartment Complexes: Scarsdale is the home of several apartment complexes, where residents and visitors can find shelter and rest. The apartment complexes are managed by a superintendent Felix Mitchell who oversees the settlement's housing operations. -- Houses: On the southern edge of the settlement, there are several houses where wealthier residents live. - - - +- : A popular bar and restaurant where traders and travelers gather to exchange information and stories. The bar is owned by Lena "Pipes" Santos. +- : A bustling marketplace where traders from various factions converge to exchange goods and information. The market is overseen by the settlement's council of traders, with Trader Councilor Jenna Redwood overseeing day-to-day operations. +- : A medical clinic run by Doctor Abigail Sterling who treats the settlement's residents and visitors. +- : A general store that sells a variety of goods, including weapons, armor, and survival supplies. The store is run by a merchant Elias Cross who has connections with various factions. +- : A caravan company that provides transportation and security for traders and travelers. The company is run by the Caravan Master Barrett Stone who oversees the settlement's caravan operations. +- : A motel that provides lodging for travelers and traders passing through the settlement. The motel is run by its manager Lily Harper who oversees the settlement's hospitality operations. +- : Scarsdale is the home of several apartment complexes, where residents and visitors can find shelter and rest. The apartment complexes are managed by a superintendent Felix Mitchell who oversees the settlement's housing operations. +- : On the southern edge of the settlement, there are several houses where wealthier residents live. +- : A Red Rocket gas station that provides fuel and vehicle maintenance services for travelers and traders passing through the settlement. The gas station is run by a mechanic named Red who oversees the settlement's vehicle maintenance operations. + + ### NPCs - Rumormonger Wilkins: A chatty and inquisitive local resident. Wilkins can be found at any of the settlement's gathering area, but most frequently at Pipes, eager to share information, for those that will buy him a drink. @@ -710,6 +692,7 @@ The PC with the highest Charisma makes a settlement reputation test **(CHA + Rep - Barrett Stone: Barrett Stone is a grizzled caravan master who ensures the safety of Scarsdale's caravans, navigating the wasteland's dangers with expertise. - Lily Harper: Lily Harper, the motel manager, offers travelers a warm and comfortable place to rest, making her a welcoming presence in the settlement. - Felix Mitchel: Felix Mitchel, the superintendent of the apartment complexes, was originally a handyman before the Great War. He became a ghoul after the bombs fell, and simply continued to do what he did before the war, fixing things and keeping the apartment complexes in good shape. He is a friendly and helpful ghoul, who is well-liked by the settlement's residents. +- Red: Red is a mechanic who runs the Red Rocket gas station. He is a former caravan guard who settled in Scarsdale. ### Quests #### Side Quest: Lost Caravan diff --git a/render_map/map_icons.py b/render_map/map_icons.py index 14c2e60..b5cebdf 100644 --- a/render_map/map_icons.py +++ b/render_map/map_icons.py @@ -61,4 +61,6 @@ class MapIcon(enum.Enum): FOOD = SETTLEMENT WATER = SETTLEMENT POWER = SETTLEMENT - DEFENSE = SETTLEMENT \ No newline at end of file + DEFENSE = SETTLEMENT + CARAVAN = WAREHOUSE + INN = SETTLEMENT \ No newline at end of file diff --git a/render_map/render_map.py b/render_map/render_map.py index 5e51374..9c27da3 100644 --- a/render_map/render_map.py +++ b/render_map/render_map.py @@ -4,13 +4,17 @@ import json import pathlib import re +import uuid import mkdocs.plugins import pydantic -from bs4 import BeautifulSoup +import bs4 +from typing import TypeVar, Type from render_map import map_icons, map_style +EnumType = TypeVar("EnumType", bound=enum.Enum) + # Sample Deprecated Geo links # [Foo Place](geo:-100.392,90) # [Foo Place](geo:90.100, 93.00) @@ -48,39 +52,55 @@ class GeoLink(pydantic.BaseModel): 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())) GEO_LINKS: list[GeoLink] = [] +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. + + Args: + result: The result dict. + enum_type: The enum type. + enum_key: The enum key. + """ + if enum_key in result: + if result[enum_key]: + result[enum_key] = getattr(enum_type, result[enum_key]) + else: + result.pop(enum_key) -def find_geo_links(markdown: str) -> list[GeoLink]: +def find_geo_links(markdown: str) -> tuple[list[GeoLink], str]: """Find all geotags in the markdown and process them into a list of GeoLink objects. Args: markdown: The markdown to search for geotags. Returns: - A list of GeoLink objects. + A list of GeoLink objects and the markdown with the geotags replaced. """ - soup = BeautifulSoup(markdown, "html.parser") - results = [x.attrs for x in soup.find_all("geotag")] + soup = bs4.BeautifulSoup(markdown, "html.parser") + geo_tags = soup.find_all("geotag") geo_links = [] - for result in results: - if "icon" in result: - if result["icon"]: - result["icon"] = getattr(map_icons.MapIcon, result["icon"]) - else: - result.pop("icon") + for geo_tag in geo_tags: + result = geo_tag.attrs + resolve_enum(result, map_icons.MapIcon, "icon") + resolve_enum(result, ZoomLevel, "zoom") - if "zoom" in result: - if result["zoom"]: - result["zoom"] = getattr(ZoomLevel, result["zoom"]) - else: - result.pop("zoom") + # Generate a GeoLink object from the result + geo_link = GeoLink(**result) + geo_links.append(geo_link) - geo_links.append(GeoLink(**result)) - return geo_links + # Replace the geotag with a span tag with the uuid as the id and the name as the text + new_tag = soup.new_tag("span") + new_tag.string = geo_link.name + new_tag['id'] = geo_link.uuid + geo_tag.replace_with(new_tag) + return geo_links, str(soup) def create_map_template(config: mkdocs.plugins.MkDocsConfig) -> str: @@ -129,7 +149,8 @@ def on_page_markdown( if page.file.inclusion.is_excluded(): return - GEO_LINKS.extend(find_geo_links(markdown)) + geolinks, markdown = find_geo_links(markdown) + GEO_LINKS.extend(geolinks) return markdown