from BrawlCrate.API import BrawlAPI
from BrawlLib.SSBB.ResourceNodes import *
from System.IO import Directory

not_found = []


def replace_node(node, folder_path):
    new_node_path = Directory.GetFiles(folder_path, node.Name + ".*")
    if new_node_path:
        node.Replace(new_node_path[0])
    else:
        not_found.append(node.Name)


if BrawlAPI.RootNode != None:
    children = BrawlAPI.RootNode.GetChildrenRecursive()
    models = filter(lambda c: isinstance(c, MDL0Node), children)
    folder_path = BrawlAPI.OpenFolderDialog("Open materials/shaders folder")
    for model in models:
        for shader in model.ShaderList:
            replace_node(shader, folder_path)
        for mat in model.MaterialList:
            replace_node(mat, folder_path)
        model.Rebuild(True)  # force rebuild because brawlcrate is shit
    if not_found:
        BrawlAPI.ShowMessage("File not found for: " + ", ".join(not_found), "")
Beispiel #2
0

def tex_search():  # Function to scan for all image nodes in the file
    wrappers = BrawlAPI.NodeWrapperList  # Get the wrapper of every node in the file (export filters are contained in wrappers)
    tex_list = []
    for wrapper in wrappers:
        if ".png" in wrapper.ExportFilter:  # If the node is exportable to png, add it to the list
            tex_list += [wrapper.Resource]
    return tex_list


# Main function
if BrawlAPI.RootNode != None:  # If there is a valid open file
    root = BrawlAPI.RootNode
    folder = BrawlAPI.OpenFolderDialog()
    if folder:
        count = 0  # Set the count
        for item in tex_search():  # Gather the texture list to export
            item.Export(
                folder + "/" + item.Name + ".png"
            )  # We already know everything in this list is exportable to a .png
            count += 1  # Increment the count
        if count:  # If any textures are found, show the user a success message
            BrawlAPI.ShowMessage(
                str(count) + " textures were successfully exported to " +
                folder, "Success")
        else:  # If no textures are found, show an error message
            BrawlAPI.ShowError('No textures were found in the open file',
                               'Error')
else:  # Show an error message if there is no valid file open
    BrawlAPI.ShowError('Cannot find Root Node (is a file open?)', 'Error')
    if preset != None:

        # check if preset already exists
        path = Path.Combine(BrawlAPI.PluginPath, "MKWii Animations", preset)
        if not Directory.Exists(path):

            # prompt for target material
            target = BrawlAPI.UserStringInput("Target Material", "")
            if target != None:

                textures = []
                export_animations()

                # edit and include import and delete script to preset folder
                import_script = File.ReadAllText(Path.Combine(BrawlAPI.PluginPath, "MKWii Animations", "Import Preset.txt"))
                import_script = import_script.Replace("preset_name = \"\"", "preset_name = \"" + preset + "\"")

                delete_script = File.ReadAllText(Path.Combine(BrawlAPI.PluginPath, "MKWii Animations", "Remove Preset.txt"))
                delete_script = delete_script.Replace("preset_name = \"\"", "preset_name = \"" + preset + "\"")

                with StreamWriter(Path.Combine(path, "Import " + preset + ".py")) as writer:
                    writer.Write(import_script)

                with StreamWriter(Path.Combine(path, "Remove " + preset + ".py")) as writer:
                    writer.Write(delete_script)

                BrawlAPI.RootNode._mainForm.reloadPluginsToolStripMenuItem_Click(None, None)
        else:

            BrawlAPI.ShowMessage("Preset name already in use", "")