Skip to content

Commit

Permalink
Video Tutorials tab
Browse files Browse the repository at this point in the history
* Video Tutorials tab.

* Is public stats.

* Linter updates.
  • Loading branch information
iwatkot authored Feb 15, 2025
1 parent 2d1b8f9 commit 7142043
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions maps4fs/generator/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
8 changes: 7 additions & 1 deletion webui/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import platform
import shutil
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions webui/templates.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from typing import NamedTuple

from config import video_tutorials_json


class Messages:
TITLE = "maps4FS"
MAIN_PAGE_DESCRIPTION = (
Expand Down Expand Up @@ -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]
16 changes: 16 additions & 0 deletions webui/videos.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
43 changes: 31 additions & 12 deletions webui/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()

Expand Down

0 comments on commit 7142043

Please sign in to comment.