feat: ship title screen media and map

This commit is contained in:
Christophe Del Vecchio committed 2026-10-01 13:28:44 +02:00
1 parent 98e852c980
commit 1d5988bc03
8 files changed
+140 -1

No files matched your search

+79
View File
@@ -0,0 +1,79 @@
"""Import title-screen audio and create the title map.
Idempotent. Run headless with the editor closed:
UnrealEditor-Cmd pogo.uproject -run=pythonscript -script=Scripts/setup_title_screen.py -nullrhi -unattended -FullStdOutLogOutput
"""
from pathlib import Path
import unreal
AUDIO_DIRECTORY = "/Game/Pogo/Audio"
AUDIO_ASSET = "/Game/Pogo/Audio/S_PogoTitleMusic"
MAP_DIRECTORY = "/Game/Pogo/Maps"
TITLE_MAP = "/Game/Pogo/Maps/Lvl_TitleScreen"
def log(message):
unreal.log(f"POGO_TITLE_SETUP {message}")
def require(condition, message):
if not condition:
raise RuntimeError(message)
eal = unreal.EditorAssetLibrary
registry = unreal.AssetRegistryHelpers.get_asset_registry()
registry.search_all_assets(True)
registry.wait_for_completion()
for directory in (AUDIO_DIRECTORY, MAP_DIRECTORY):
if not eal.does_directory_exist(directory):
require(eal.make_directory(directory), f"Could not create {directory}")
log(f"created directory {directory}")
wav_source = Path(unreal.Paths.project_dir()) / "SourceArt/Audio/pogo.wav"
require(wav_source.is_file(), f"Missing source audio: {wav_source}")
if not eal.does_asset_exist(AUDIO_ASSET):
task = unreal.AssetImportTask()
task.set_editor_property("filename", str(wav_source))
task.set_editor_property("destination_path", AUDIO_DIRECTORY)
task.set_editor_property("destination_name", "S_PogoTitleMusic")
task.set_editor_property("automated", True)
task.set_editor_property("save", False)
task.set_editor_property("replace_existing", False)
unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])
log(f"imported audio paths={task.get_editor_property('imported_object_paths')}")
else:
log(f"audio already exists {AUDIO_ASSET}")
sound = eal.load_asset(AUDIO_ASSET)
require(sound is not None, f"Could not load {AUDIO_ASSET}")
sound.set_editor_property("looping", True)
require(
eal.save_loaded_asset(sound, only_if_is_dirty=False),
f"Could not save {AUDIO_ASSET}",
)
log(f"audio looping={sound.get_editor_property('looping')}")
if eal.does_asset_exist(TITLE_MAP):
require(unreal.EditorLevelLibrary.load_level(TITLE_MAP), f"Could not load {TITLE_MAP}")
log(f"loaded existing map {TITLE_MAP}")
else:
require(unreal.EditorLevelLibrary.new_level(TITLE_MAP), f"Could not create {TITLE_MAP}")
log(f"created map {TITLE_MAP}")
world = unreal.EditorLevelLibrary.get_editor_world()
require(world is not None, "No editor world after loading title map")
settings = world.get_world_settings()
require(settings is not None, "Title map has no WorldSettings")
title_game_mode = unreal.PogoTitleScreenGameMode.static_class()
settings.set_editor_property("default_game_mode", title_game_mode)
require(
settings.get_editor_property("default_game_mode") == title_game_mode,
"Title map GameMode assignment did not stick",
)
require(unreal.EditorLevelLibrary.save_current_level(), f"Could not save {TITLE_MAP}")
log(f"map={TITLE_MAP} game_mode={settings.get_editor_property('default_game_mode')}")
log("PASS")
+22
View File
@@ -53,6 +53,28 @@ class TitleScreenSourceTests(unittest.TestCase):
before_request = source[: source.index("void UPogoTitleScreenWidget::RequestPlay")]
self.assertNotIn("PlayButton->SetIsEnabled(false)", before_request)
def test_packaged_media_sources_exist(self):
self.assertTrue(path("Content/Movies/pogo.mp4").is_file())
self.assertTrue(path("SourceArt/Audio/pogo.wav").is_file())
def test_title_map_is_the_runtime_default(self):
config = read("Config/DefaultEngine.ini")
self.assertIn(
"GameDefaultMap=/Game/Pogo/Maps/Lvl_TitleScreen.Lvl_TitleScreen",
config,
)
self.assertIn(
"EditorStartupMap=/Game/ThirdPerson/Lvl_ThirdPerson.Lvl_ThirdPerson",
config,
)
def test_setup_script_creates_required_assets(self):
setup = read("Scripts/setup_title_screen.py")
self.assertIn('"/Game/Pogo/Audio/S_PogoTitleMusic"', setup)
self.assertIn('"/Game/Pogo/Maps/Lvl_TitleScreen"', setup)
self.assertIn('set_editor_property("looping", True)', setup)
self.assertIn("unreal.PogoTitleScreenGameMode", setup)
if __name__ == "__main__":
unittest.main()
+26
View File
@@ -0,0 +1,26 @@
"""Validate generated title-screen assets in an Unreal Python commandlet."""
from pathlib import Path
import unreal
AUDIO_ASSET = "/Game/Pogo/Audio/S_PogoTitleMusic"
TITLE_MAP = "/Game/Pogo/Maps/Lvl_TitleScreen"
movie = Path(unreal.Paths.project_content_dir()) / "Movies/pogo.mp4"
assert movie.is_file(), f"Missing packaged movie: {movie}"
sound = unreal.EditorAssetLibrary.load_asset(AUDIO_ASSET)
assert sound, f"Missing sound asset: {AUDIO_ASSET}"
assert sound.get_editor_property("looping") is True, "Title music is not looping"
assert unreal.EditorLevelLibrary.load_level(TITLE_MAP), f"Could not load {TITLE_MAP}"
world = unreal.EditorLevelLibrary.get_editor_world()
assert world, "No editor world after loading title map"
settings = world.get_world_settings()
assert settings, "Title map has no WorldSettings"
assert (
settings.get_editor_property("default_game_mode")
== unreal.PogoTitleScreenGameMode.static_class()
), "Title map does not use PogoTitleScreenGameMode"
unreal.log("POGO_TITLE_VERIFY PASS")