## This is a resource name loader that will import the names of files from certain folders
## Intended as a way to quickly grab file names to use in accessibility.rpy, screens.rpy, and captiontool.rpy
## Remember to add commas to the end of each listed item
## As of RenPy7, basic images do not have to be defined (LayeredImages still need to be set up)
init -1:
    $ redefine_resources = False
    ## When you add, delete or rename an image or music resource, change redefine_resources to True and launch the project

## Sprites:
    # image Texture481 = "images/sprites/Texture481.png"
    # image flandre_base = "images/sprites/flandre_base.png"
    # image flandre_face_happy = "images/sprites/flandre_face_happy.png"
    # image flandre_face_serious = "images/sprites/flandre_face_serious.png"
    # image remilia_base = "images/sprites/remilia_base.png"
    # image remilia_face_angry = "images/sprites/remilia_face_angry.png"
    # image remilia_face_confused = "images/sprites/remilia_face_confused.png"
    # image remilia_face_happy = "images/sprites/remilia_face_happy.png"
    # image remilia_face_serious = "images/sprites/remilia_face_serious.png"
    # image remilia_face_shadow = "images/sprites/remilia_face_shadow.png"
## BGs:
    # image black = "images/BG/black.png"
    # image dawn1 = "images/BG/dawn1.png"
    # image dawn2 = "images/BG/dawn2.png"
    # image dungeon = "images/BG/dungeon.png"
    # image future_office = "images/BG/future_office.jpg"
    # image outside = "images/BG/outside.png"
    # image outside2 = "images/BG/outside2.png"
    # image room = "images/BG/room.jpg"
    # image sky = "images/BG/sky.png"
    # image sort_of_beautiful_beach_day = "images/BG/sort_of_beautiful_beach_day.jpg"
    # image village = "images/BG/village.png"
    # image white = "images/BG/white.png"
## CGs:
    # image cg_locked = "images/CG/cg_locked.jpg"

## Music:
# init -2 python:
    # Brimstone = "audio/music/Brimstone.mp3"
    # Theme of Eastern Story = "audio/music/Theme of Eastern Story.mp3"

## Music Caption:
    # Brimstone: _("")
    # Theme of Eastern Story: _("")

## SFX:
    # Chest-Drawer_Close = "audio/sfx/Chest-Drawer_Close.mp3"
    # Chest-Drawer_Open = "audio/sfx/Chest-Drawer_Open.mp3"
    # Edge-of-Ocean = "audio/sfx/Edge-of-Ocean.mp3"
    # Interior-Door_Close = "audio/sfx/Interior-Door_Close.mp3"

## SFX Caption:
    # Chest-Drawer_Close: _("")
    # Chest-Drawer_Open: _("")
    # Edge-of-Ocean: _("")
    # Interior-Door_Close: _("")

## Script to redefine the images:
## !!! DO NOT CHANGE THE CODE BELOW THIS POINT !!!
init -1 python:

    if redefine_resources:
        with open(renpy.loader.transfn('definitions.rpy'), 'rb') as f:
            s = f.read()
        f.closed
        pos = s.find('## Script to redefine the images')
        if pos>1:
            s=s[pos:]

        with open(renpy.loader.transfn('definitions.rpy'), 'wb') as f:
            f.write('## This is a resource name loader that will import the names of files from certain folders\n## Intended as a way to quickly grab file names to use in accessibility.rpy, screens.rpy, and captiontool.rpy\n## Remember to add commas to the end of each listed item\n## As of RenPy7, basic images do not have to be defined (LayeredImages still need to be set up)\r\ninit -1:\r\n    $ redefine_resources = False\n    ## When you add, delete or rename an image or music resource, change redefine_resources to True and launch the project\r\n\r\n')
            
            f.write('## Sprites:\r\n')
            for file in renpy.list_files():
                if file.startswith('images/sprites') and (file.endswith('.png') or file.endswith('.webp')):
                    name = file.replace('images/sprites/','').replace('/', ' ').replace('.png','').replace('.webp','')
                    img_str = 'image ' + name + ' = "' + file + '"'
                    f.write('    # ' + img_str + '\r\n')

            f.write('## BGs:\r\n')
            for file in renpy.list_files():
                if file.startswith('images/BG/') and (file.endswith('.png') or file.endswith('.webp') or file.endswith('.jpg')):
                    name = file.replace('images/BG/','').replace('/', ' ').replace('.png','').replace('.webp','').replace('.jpg','')
                    img_str = 'image ' + name + ' = "' + file + '"'
                    f.write('    # ' + img_str + '\r\n')

            f.write('## CGs:\r\n')
            for file in renpy.list_files():
                if file.startswith('images/CG/') and (file.endswith('.png') or file.endswith('.webp') or file.endswith('.jpg')):
                    name = file.replace('images/CG/','').replace('/', ' ').replace('.png','').replace('.webp','').replace('.jpg','')
                    img_str = 'image ' + name + ' = "' + file + '"'
                    f.write('    # ' + img_str + '\r\n')
            
            f.write('\r\n## Music:\r\n# init -2 python:\r\n')
            for file in renpy.list_files():
                if file.startswith('audio/music/') and (file.endswith('.ogg') or file.endswith('.wav') or file.endswith('.mp3')):
                    name = file.replace('audio/music/','').replace('/', ' ').replace('.ogg','').replace('.wav','').replace('.mp3','')
                    my_str = name + ' = "' + file + '"'
                    f.write('    # ' + my_str + '\r\n')

            f.write('\r\n## Music Caption:\r\n')
            for file in renpy.list_files():
                if file.startswith('audio/music/') and (file.endswith('.ogg') or file.endswith('.wav') or file.endswith('.mp3')):
                    name = file.replace('audio/music/','').replace('/', ' ').replace('.ogg','').replace('.wav','').replace('.mp3','')
                    my_str = name + ' = "' + file + '"'
                    f.write('    # ' + name + ': _("")' + '\r\n')

            f.write('\r\n## SFX:\r\n')
            for file in renpy.list_files():
                if file.startswith('audio/sfx/') and (file.endswith('.ogg') or file.endswith('.wav') or file.endswith('.mp3')):
                    name = file.replace('audio/sfx/','').replace('/', ' ').replace(' ', '_').replace('.ogg','').replace('.wav','').replace('.mp3','')
                    my_str = name + ' = "' + file + '"'
                    f.write('    # ' + my_str + '\r\n')

            f.write('\r\n## SFX Caption:\r\n')
            for file in renpy.list_files():
                if file.startswith('audio/sfx/') and (file.endswith('.ogg') or file.endswith('.wav') or file.endswith('.mp3')):
                    name = file.replace('audio/sfx/','').replace('/', ' ').replace(' ', '_').replace('.ogg','').replace('.wav','').replace('.mp3','')
                    my_str = name + ' = "' + file + '"'
                    f.write('    # ' + name + ': _("")' + '\r\n')
            f.write('\r\n')
        f.closed
        
        with open(renpy.loader.transfn('definitions.rpy'), 'ab') as f:
            f.write(s)
        f.closed