dillanthumous / dungeondrafttagmaker

A simple python script bodged together to turn folders containing pngs into a Tags file for DungeonDraft
MIT License
1 stars 1 forks source link

Images are not sorted alphabetically #2

Open Noggin01 opened 4 years ago

Noggin01 commented 4 years ago

DungeonDraft displays images based on the order in which they're found in the JSON data. If images are named logically within the folder structure, sorting them alphabetically would help in the case that a tag contains dozens of images. This would make the "Lighting" tag keep candle_1.png next to candle_2.png without putting lantern_17.png between them. The following code will achieve this:

    # Recursively collect all files from folders which contain pngs and creates name in a dict
    for file in glob.iglob(os.path.join(base_path, '*/*.png'), recursive=True):
        imagesList[os.path.basename(os.path.dirname(file))].append(filePathStruct + os.path.basename(file))

    # Sort each list of assets alphabetically so that they appear in DD in a logical order
    [imagesList[each].sort() for each in imagesList]

    # Check for usable user input and call the prepend/append function to add to tag names
    if prepend_input != None or append_input != None:
        prepend_append_to_dict_keys(prepend_input, append_input, imagesList)

[imagesList[each].sort() for each in imagesList]

can be more clearly written as

for each in imagesList:
    imagesList[each].sort()
dillanthumous commented 4 years ago

Good idea - I hadn't realised Dungeon Draft sorted based on the file - assumed it would do so alphabetically inside the program.

Will have a look at implementing in the code and testing.