File size: 1,493 Bytes
123cdd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os

assets_dir = './assets'
character = {}

# Step 1: Load character dictionary
for i in os.listdir(assets_dir):
    if i.endswith('.wav'):
        audio_path = f"{assets_dir}/{i}"
        image_path= f"{assets_dir}/{i.replace('.wav', '.png')}"
        sound_name = i.replace('.wav', '').replace('_', ' ').title()
        character[sound_name] = {
            'image_path': image_path,
            'audio_path': audio_path
        }

# Step 2: Define custom priority order
priority_names = [
    'Bombardiro Crocodilo',
    'Tralalero Tralala',
    'Bombombini Gusini',
    'Tung Tung Tung Tung Tung Tung Tung Tung Tung Sahur',
    'Brr Brr Patapim',
    'Cappuccino Assassino',
    'Lirili Larila',
    'Trulimero Trulichina',
    'Boneca Ambalabu',
    'Chimpanzini Bananini'  # Note: Fix spacing issue from original
]

# Normalize keys to fix any mismatch
fixed_character = {}
for name, data in character.items():
    fixed_name = ' '.join(name.split())  # Removes extra spaces
    fixed_character[fixed_name] = data

# Step 3: Sort with custom priority
sorted_keys = (
    priority_names +
    sorted([k for k in fixed_character if k not in priority_names])
)

# Step 4: Create the final sorted dictionary
sorted_character = {k: fixed_character[k] for k in sorted_keys}

import json
json_path = 'character.json'
with open(json_path, 'w', encoding='utf-8') as f:
    json.dump(sorted_character, f, ensure_ascii=False, indent=4)