From 24aa4af7c2f811c7bdefea7eb54bf6869dc0fcd3 Mon Sep 17 00:00:00 2001 From: josephwhite <22449090+josephwhite@users.noreply.github.com> Date: Sat, 15 Nov 2025 10:55:13 -0500 Subject: [PATCH] WebHost: Validation for webworld themes (#5083) --- WebHostLib/misc.py | 22 +++++++++++++++++++--- WebHostLib/options.py | 7 +------ worlds/AutoWorld.py | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/WebHostLib/misc.py b/WebHostLib/misc.py index 44e81a5983..82faaf2b16 100644 --- a/WebHostLib/misc.py +++ b/WebHostLib/misc.py @@ -1,5 +1,7 @@ import datetime import os +import warnings +from enum import StrEnum from typing import Any, IO, Dict, Iterator, List, Tuple, Union import jinja2.exceptions @@ -13,11 +15,25 @@ from .markdown import render_markdown from .models import Seed, Room, Command, UUID, uuid4 from Utils import title_sorted +class WebWorldTheme(StrEnum): + DIRT = "dirt" + GRASS = "grass" + GRASS_FLOWERS = "grassFlowers" + ICE = "ice" + JUNGLE = "jungle" + OCEAN = "ocean" + PARTY_TIME = "partyTime" + STONE = "stone" def get_world_theme(game_name: str) -> str: - if game_name in AutoWorldRegister.world_types: - return AutoWorldRegister.world_types[game_name].web.theme - return 'grass' + if game_name not in AutoWorldRegister.world_types: + return "grass" + chosen_theme = AutoWorldRegister.world_types[game_name].web.theme + available_themes = [theme.value for theme in WebWorldTheme] + if chosen_theme not in available_themes: + warnings.warn(f"Theme '{chosen_theme}' for {game_name} not valid, switching to default 'grass' theme.") + return "grass" + return chosen_theme def get_visible_worlds() -> dict[str, type(World)]: diff --git a/WebHostLib/options.py b/WebHostLib/options.py index c2f1619f9f..e3d2745855 100644 --- a/WebHostLib/options.py +++ b/WebHostLib/options.py @@ -13,6 +13,7 @@ from Utils import local_path from worlds.AutoWorld import AutoWorldRegister from . import app, cache from .generate import get_meta +from .misc import get_world_theme def create() -> None: @@ -22,12 +23,6 @@ def create() -> None: Options.generate_yaml_templates(yaml_folder) -def get_world_theme(game_name: str) -> str: - if game_name in AutoWorldRegister.world_types: - return AutoWorldRegister.world_types[game_name].web.theme - return 'grass' - - def render_options_page(template: str, world_name: str, is_complex: bool = False) -> Union[Response, str]: world = AutoWorldRegister.world_types[world_name] if world.hidden or world.web.options_page is False: diff --git a/worlds/AutoWorld.py b/worlds/AutoWorld.py index 1805b11a09..8bd6ffaf3c 100644 --- a/worlds/AutoWorld.py +++ b/worlds/AutoWorld.py @@ -224,7 +224,7 @@ class WebWorld(metaclass=WebWorldRegister): tutorials: List["Tutorial"] """docs folder will also be scanned for tutorial guides. Each Tutorial class is to be used for one guide.""" - theme = "grass" + theme: str = "grass" """Choose a theme for you /game/* pages. Available: dirt, grass, grassFlowers, ice, jungle, ocean, partyTime, stone"""