mirror of
https://github.com/ArchipelagoMW/Archipelago.git
synced 2026-08-04 23:26:14 -07:00
WebHost: Validation for webworld themes (#5083)
This commit is contained in:
+19
-3
@@ -1,5 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
import warnings
|
||||||
|
from enum import StrEnum
|
||||||
from typing import Any, IO, Dict, Iterator, List, Tuple, Union
|
from typing import Any, IO, Dict, Iterator, List, Tuple, Union
|
||||||
|
|
||||||
import jinja2.exceptions
|
import jinja2.exceptions
|
||||||
@@ -13,11 +15,25 @@ from .markdown import render_markdown
|
|||||||
from .models import Seed, Room, Command, UUID, uuid4
|
from .models import Seed, Room, Command, UUID, uuid4
|
||||||
from Utils import title_sorted
|
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:
|
def get_world_theme(game_name: str) -> str:
|
||||||
if game_name in AutoWorldRegister.world_types:
|
if game_name not in AutoWorldRegister.world_types:
|
||||||
return AutoWorldRegister.world_types[game_name].web.theme
|
return "grass"
|
||||||
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)]:
|
def get_visible_worlds() -> dict[str, type(World)]:
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from Utils import local_path
|
|||||||
from worlds.AutoWorld import AutoWorldRegister
|
from worlds.AutoWorld import AutoWorldRegister
|
||||||
from . import app, cache
|
from . import app, cache
|
||||||
from .generate import get_meta
|
from .generate import get_meta
|
||||||
|
from .misc import get_world_theme
|
||||||
|
|
||||||
|
|
||||||
def create() -> None:
|
def create() -> None:
|
||||||
@@ -22,12 +23,6 @@ def create() -> None:
|
|||||||
Options.generate_yaml_templates(yaml_folder)
|
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]:
|
def render_options_page(template: str, world_name: str, is_complex: bool = False) -> Union[Response, str]:
|
||||||
world = AutoWorldRegister.world_types[world_name]
|
world = AutoWorldRegister.world_types[world_name]
|
||||||
if world.hidden or world.web.options_page is False:
|
if world.hidden or world.web.options_page is False:
|
||||||
|
|||||||
+1
-1
@@ -224,7 +224,7 @@ class WebWorld(metaclass=WebWorldRegister):
|
|||||||
tutorials: List["Tutorial"]
|
tutorials: List["Tutorial"]
|
||||||
"""docs folder will also be scanned for tutorial guides. Each Tutorial class is to be used for one guide."""
|
"""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.
|
"""Choose a theme for you /game/* pages.
|
||||||
Available: dirt, grass, grassFlowers, ice, jungle, ocean, partyTime, stone"""
|
Available: dirt, grass, grassFlowers, ice, jungle, ocean, partyTime, stone"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user