diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index fac1bd1..6e26a56 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -1,7 +1,7 @@ [/Script/EngineSettings.GameMapsSettings] -GameDefaultMap=/Game/ThirdPerson/Lvl_ThirdPerson.Lvl_ThirdPerson +GameDefaultMap=/Game/Pogo/Maps/Lvl_TitleScreen.Lvl_TitleScreen EditorStartupMap=/Game/ThirdPerson/Lvl_ThirdPerson.Lvl_ThirdPerson GlobalDefaultGameMode=/Game/Pogo/Blueprints/BP_PogoGameMode.BP_PogoGameMode_C diff --git a/Content/Movies/pogo.mp4 b/Content/Movies/pogo.mp4 new file mode 100644 index 0000000..1ccccee --- /dev/null +++ b/Content/Movies/pogo.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:24c73f79c0823e2e7d3c3b6ca7cdf5059199ff8434e3b359619c5f06e30c8ca0 +size 13087705 diff --git a/Content/Pogo/Audio/S_PogoTitleMusic.uasset b/Content/Pogo/Audio/S_PogoTitleMusic.uasset new file mode 100644 index 0000000..1a5f1bd --- /dev/null +++ b/Content/Pogo/Audio/S_PogoTitleMusic.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10b18d377a45188c2ed6e41a07b3c81e69bce993966938ee7b4aabb5b96f1b8d +size 23948839 diff --git a/Content/Pogo/Maps/Lvl_TitleScreen.umap b/Content/Pogo/Maps/Lvl_TitleScreen.umap new file mode 100644 index 0000000..00e3272 --- /dev/null +++ b/Content/Pogo/Maps/Lvl_TitleScreen.umap @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:49cd75ed1e214b955f7a855ba2c9f4f8b9cd431f774184987ba2ab7adc0fe6d8 +size 8684 diff --git a/Scripts/setup_title_screen.py b/Scripts/setup_title_screen.py new file mode 100644 index 0000000..9069bf4 --- /dev/null +++ b/Scripts/setup_title_screen.py @@ -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") diff --git a/Scripts/tests/test_title_screen.py b/Scripts/tests/test_title_screen.py index 40d82ab..c9a8360 100644 --- a/Scripts/tests/test_title_screen.py +++ b/Scripts/tests/test_title_screen.py @@ -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() diff --git a/Scripts/verify_title_screen_assets.py b/Scripts/verify_title_screen_assets.py new file mode 100644 index 0000000..74c8669 --- /dev/null +++ b/Scripts/verify_title_screen_assets.py @@ -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") diff --git a/SourceArt/Audio/pogo.wav b/SourceArt/Audio/pogo.wav new file mode 100644 index 0000000..538ec42 --- /dev/null +++ b/SourceArt/Audio/pogo.wav @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3371b7a63b940660f8c93996a7974fa7743da8f3de23d469f5ba8f30795ebcec +size 39857680