in PlayAssetDelivery/BundletoolScriptSample/add_packs.py [0:0]
def extract_bundle_config(bundle_folder: str, add_standalone_config: bool,
strip_tcf_suffixes: bool,
compress_install_time_assets: bool) -> str:
"""Extract the BundleConfig contents and optionally add standalone_config."""
bundle_config = config_pb2.BundleConfig()
with open(os.path.join(bundle_folder, "BundleConfig.pb"), mode="rb") as f:
content = f.read()
bundle_config.ParseFromString(content)
if compress_install_time_assets:
json_format.ParseDict(
{
"compression": {
"install_time_asset_module_default_compression": "COMPRESSED"
}
}, bundle_config)
if add_standalone_config:
json_format.ParseDict(
{
"optimizations": {
"standalone_config": {
"split_dimension": [{
"value": "ABI",
"negate": True
}, {
"value": "TEXTURE_COMPRESSION_FORMAT",
"negate": True
}, {
"value": "LANGUAGE",
"negate": True
}, {
"value": "SCREEN_DENSITY",
"negate": True
}],
"strip_64_bit_libraries": True
}
}
}, bundle_config)
# Check if game already defines any split_config dimensions
dimensions = []
try:
dimensions = list(json_format.MessageToDict(bundle_config)["optimizations"]
["splitsConfig"]["splitDimension"])
except KeyError:
print("No existing split dimensions")
tcf_split_dimension = {
"value": "TEXTURE_COMPRESSION_FORMAT",
"negate": False,
"suffix_stripping": {
"enabled": True,
"default_suffix": ""
}
}
# Add the TCF split dimension, if needed
if strip_tcf_suffixes:
dimensions.append(tcf_split_dimension)
if strip_tcf_suffixes:
json_format.ParseDict(
{
"optimizations": {
"splits_config": {
"split_dimension": dimensions
}
}
}, bundle_config)
output_path = os.path.join(bundle_folder, "BundleConfig.pb.json")
with open(output_path, mode="w") as f:
print(json_format.MessageToJson(bundle_config), file=f)
return output_path