import unreal


def apply_playtex_texture_settings():
    textures = [
        asset
        for asset in unreal.EditorUtilityLibrary.get_selected_assets()
        if isinstance(asset, unreal.Texture2D)
    ]

    for texture in textures:
        name = texture.get_name().lower()
        is_normal = "normal" in name
        is_mask = any(token in name for token in ("rough", "metal", "ao", "occlusion", "orm"))

        texture.set_editor_property("srgb", not (is_normal or is_mask))
        if is_normal:
            texture.set_editor_property(
                "compression_settings",
                unreal.TextureCompressionSettings.TC_NORMALMAP,
            )
        elif is_mask:
            texture.set_editor_property(
                "compression_settings",
                unreal.TextureCompressionSettings.TC_MASKS,
            )

        texture.post_edit_change()
        unreal.EditorAssetLibrary.save_loaded_asset(texture)


apply_playtex_texture_settings()

