# Generates Transition Classes

import glob

code_imports = """
# THIS FILE IS GENERATED USING utils.py
# IF YOU'RE ADDING/REMOVING SOME SHADER, DO NOT EDIT THIS FILE DIRECTLY
# INSTEAD DO WHATEVER YOU WANT WITH THE SHADERS AND RUN utils.py

from .base import CustomTransition
from kivy.properties import StringProperty

available_transitions = [{}]
__all__ = available_transitions
"""

code_classes = """
class {}(CustomTransition):
    glsl_file = StringProperty("{}.glsl")


"""

shader_list = sorted(glob.glob("transitions/*.glsl"))
code_file = "transitions/__init__.py"


classes = ""
class_str = '"{}",'
list_classes = ""
for each in shader_list:
    class_name = each.split("/")[-1].split(".")[0]
    classes += code_classes.format(class_name, class_name)
    list_classes += class_str.format(class_name)

final_code = code_imports.format(list_classes) + classes

try:
    with open(code_file, "w") as f:
        f.write(final_code)
    print("Classes generated.")
except Exception as e:
    print("Error generating classes: {}".format(e))
