feat: ship title screen media and map
This commit is contained in:
1 parent
98e852c980
commit
1d5988bc03
8 files changed
+140
-1
No files matched your search
@@ -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")
|
||||
Reference in new issue
Block a user