You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
o3de/Assets/Editor/Scripts/export_all_project_levels.py

79 lines
2.4 KiB
Python

#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
"""
This script loads every level in a game project and exports them. You will be prompted with the standard
Check-Out/Overwrite/Cancel dialog for each level.
This is useful when there is a version update to a file that requires re-exporting.
"""
import sys, os
import azlmbr.legacy.general as general
import azlmbr.legacy.checkout_dialog as checkout_dialog
class CheckOutDialogEnableAll:
"""
Helper class to wrap enabling the "Apply to all" checkbox in the CheckOutDialog.
Guarantees that the old setting will be restored.
To use, do:
with CheckOutDialogEnableAll():
# your code here
"""
def __init__(self):
self.old_setting = False
def __enter__(self):
self.old_setting = checkout_dialog.enable_for_all(True)
print(self.old_setting)
def __exit__(self, type, value, traceback):
checkout_dialog.enable_for_all(self.old_setting)
level_list = []
def is_in_special_folder(file_full_path):
if file_full_path.find("_savebackup") >= 0:
return True
if file_full_path.find("_autobackup") >= 0:
return True
if file_full_path.find("_hold") >= 0:
return True
if file_full_path.find("_tmpresize") >= 0:
return True
return False
game_folder = general.get_game_folder()
# Recursively search every directory in the game project for files ending with .cry and .ly
for root, dirs, files in os.walk(game_folder):
for file in files:
if file.endswith(".cry") or file.endswith(".ly"):
# The engine expects the full path of the .cry file
file_full_path = os.path.abspath(os.path.join(root, file))
# Exclude files in special directories
if not is_in_special_folder(file_full_path):
level_list.append(file_full_path)
# make the checkout dialog enable the 'Apply to all' checkbox
with CheckOutDialogEnableAll():
# For each valid .cry file found, open it in the editor and export it
for level in level_list:
if not isinstance(level, str):
# general.open_level_no_prompt expects the file path in utf8 format
level = level.encode("utf-8")
general.open_level_no_prompt(level)
general.export_to_engine()