diff --git a/.pylintrc b/.pylintrc index 67f5f08..17c65f2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -26,4 +26,5 @@ disable=raw-checker-failed, attribute-defined-outside-init, unused-argument, consider-using-from-import, - line-too-long + line-too-long, + import-outside-toplevel diff --git a/maps4fs/generator/map.py b/maps4fs/generator/map.py index b54f42b..54a8c9b 100644 --- a/maps4fs/generator/map.py +++ b/maps4fs/generator/map.py @@ -87,6 +87,7 @@ def __init__( "rotation": rotation, "dtm_provider": dtm_provider.name(), "custom_osm": bool(custom_osm), + "is_public": self.is_session_public(), } send_main_settings(main_settings) except Exception as e: @@ -347,3 +348,18 @@ def get_country_by_coordinates(self) -> str: self.logger.error("Error getting country name by coordinates: %s", e) return "Unknown" return "Unknown" + + def is_session_public(self) -> bool | str: + """Check if the session is public. + + Returns: + bool: True if the session is public, False otherwise. + If an error occurs, returns "Unknown". + """ + try: + from webui.config import is_public + + return is_public() + except Exception as e: + self.logger.error("Error checking if the session is public: %s", e) + return "Unknown" diff --git a/webui/config.py b/webui/config.py index 0f1cf96..25e24a2 100644 --- a/webui/config.py +++ b/webui/config.py @@ -1,3 +1,4 @@ +import json import os import platform import shutil @@ -15,6 +16,11 @@ INPUT_DIRECTORY = os.path.join(TEMP_DIRECTORY, "input") TILES_DIRECTORY = os.path.join(TEMP_DIRECTORY, "tiles") +VIDEO_TUTORIALS_PATH = os.path.join(WORKING_DIRECTORY, "webui", "videos.json") + +with open(VIDEO_TUTORIALS_PATH, "r", encoding="utf-8") as f: + video_tutorials_json = json.load(f) + FS25_TEXTURE_SCHEMA_PATH = os.path.join(DATA_DIRECTORY, "fs25-texture-schema.json") FS25_TREE_SCHEMA_PATH = os.path.join(DATA_DIRECTORY, "fs25-tree-schema.json") if not os.path.exists(FS25_TEXTURE_SCHEMA_PATH): @@ -119,7 +125,7 @@ def get_versions() -> tuple[str, str] | None: return latest_version, current_version except Exception: - return + return None def get_package_version(package_name: str) -> str: diff --git a/webui/templates.py b/webui/templates.py index ab47f51..55c12b1 100644 --- a/webui/templates.py +++ b/webui/templates.py @@ -1,3 +1,8 @@ +from typing import NamedTuple + +from config import video_tutorials_json + + class Messages: TITLE = "maps4FS" MAIN_PAGE_DESCRIPTION = ( @@ -353,3 +358,16 @@ class Settings: "download time. \n" "ℹ️ **Units:** integer value, maximum recommended value is 18." ) + + +class VideoTutorial(NamedTuple): + """Represents a video tutorial object.""" + + episode: int + title: str + description: str + link: str + image: str + + +video_tutorials: list[VideoTutorial] = [VideoTutorial(**video) for video in video_tutorials_json] diff --git a/webui/videos.json b/webui/videos.json new file mode 100644 index 0000000..da0cfeb --- /dev/null +++ b/webui/videos.json @@ -0,0 +1,16 @@ +[ + { + "episode": 0, + "title": "Where the data come from?", + "description": "Where the object data (roads, rivers, buildings, fields, etc.) and the terrain data come from.", + "link": "https://www.youtube.com/watch?v=hPbJZ0HoiDE", + "image": "https://github.com/user-attachments/assets/ae489726-2301-445c-b193-290faf5b5b29" + }, + { + "episode": 1, + "title": "How to edit OSM data and how to use custom OSM files?", + "description": "How to edit data on the public version of OpenStreetMap and how to use custom OSM files.", + "link": "https://www.youtube.com/watch?v=duTXvkIiECY", + "image": "https://github.com/user-attachments/assets/6d0d0f8b-ff68-4d2e-8e3f-924e1c6afeb8" + } +] diff --git a/webui/webui.py b/webui/webui.py index 4097072..ccd337e 100644 --- a/webui/webui.py +++ b/webui/webui.py @@ -4,24 +4,31 @@ import streamlit.components.v1 as components from config import DOCS_DIRECTORY, FAQ_MD, get_mds from generator.generator import GeneratorUI -from templates import Messages +from templates import Messages, video_tutorials from toolbox import ToolboxUI class WebUI: def __init__(self): st.set_page_config(page_title="maps4FS", page_icon="🚜", layout="wide") - generator_tab, statistics_tab, step_by_step_tab, toolbox_tab, knowledge_tab, faq_tab = ( - st.tabs( - [ - "πŸ—ΊοΈ Map Generator", - "πŸ“Š Statistics", - "πŸ”’ Step by step", - "🧰 Modder Toolbox", - "πŸ“– Knowledge base", - "πŸ“ FAQ", - ] - ) + ( + generator_tab, + statistics_tab, + step_by_step_tab, + video_tutorials_tab, + toolbox_tab, + knowledge_tab, + faq_tab, + ) = st.tabs( + [ + "πŸ—ΊοΈ Map Generator", + "πŸ“Š Statistics", + "πŸ”’ Step by step", + "πŸ“Ή Video Tutorials", + "🧰 Modder Toolbox", + "πŸ“– Knowledge base", + "πŸ“ FAQ", + ] ) with generator_tab: @@ -39,6 +46,18 @@ def __init__(self): step_by_step_tab_path = os.path.join(DOCS_DIRECTORY, "step_by_step.md") st.write(open(step_by_step_tab_path, "r", encoding="utf-8").read()) + with video_tutorials_tab: + COLUMNS_PER_ROW = 3 + for i in range(0, len(video_tutorials), COLUMNS_PER_ROW): + row = st.columns(COLUMNS_PER_ROW) + for j, video_tutorial in enumerate(video_tutorials[i : i + COLUMNS_PER_ROW]): + with row[j]: + st.markdown( + f"[![]({video_tutorial.image})]({video_tutorial.link}) \n" + f"**Episode {video_tutorial.episode}:** {video_tutorial.title} \n" + f"*{video_tutorial.description}*" + ) + with toolbox_tab: self.toolbox = ToolboxUI()