Datasets:
Tasks:
Text Classification
Modalities:
Image
Formats:
imagefolder
Languages:
English
Size:
1K - 10K
Tags:
art
License:
import json | |
import os | |
def load_metadata(): | |
"""Load metadata from metadata.jsonl""" | |
metadata_path = "metadata.jsonl" | |
metadata = {} | |
if not os.path.exists(metadata_path): | |
print(f"Error: '{metadata_path}' file not found!") | |
return metadata | |
# Parse JSONL file and map descriptions by sprite ID | |
try: | |
with open(metadata_path, 'r') as f: | |
for line in f: | |
if line.strip(): | |
entry = json.loads(line) | |
# Extract sprite ID from file_name (e.g., "images/23.png" -> "23") | |
sprite_id = entry["file_name"].split("/")[1].split(".")[0] | |
metadata[sprite_id] = entry["text"] | |
except Exception as e: | |
print(f"Error reading metadata file: {str(e)}") | |
print(f"Loaded {len(metadata)} entries from metadata file") | |
return metadata | |
def extract_info_safely(description): | |
"""Extract information from description with error handling""" | |
info = { | |
"frames": "unknown", | |
"action": "unknown", | |
"direction": "unknown", | |
"character": "unknown" | |
} | |
try: | |
# Standard format: "X-frame sprite animation of: CHARACTER, that: ACTION, facing: DIRECTION" | |
if "-frame sprite animation of:" in description: | |
# Extract frame count | |
info["frames"] = description.split("-frame")[0].strip() | |
# Extract character | |
if "of:" in description and ", that:" in description: | |
character_part = description.split("of:")[1].split(", that:")[0].strip() | |
info["character"] = character_part | |
# Extract action | |
if ", that:" in description and ", facing:" in description: | |
action_part = description.split(", that:")[1].split(", facing:")[0].strip() | |
info["action"] = action_part | |
elif ", that:" in description: | |
# Handle case where facing might not be present | |
action_part = description.split(", that:")[1].strip() | |
info["action"] = action_part | |
# Extract direction | |
if ", facing:" in description: | |
direction_part = description.split(", facing:")[1].strip() | |
info["direction"] = direction_part | |
except Exception as e: | |
print(f"Warning: Error parsing description: '{description}'") | |
print(f"Error details: {str(e)}") | |
return info | |
def create_sprite_metadata(): | |
"""Create proper sprite metadata from metadata.jsonl""" | |
# Load metadata | |
metadata = load_metadata() | |
if not metadata: | |
print("No metadata entries found. Check if metadata.jsonl exists and has content.") | |
return {} | |
# Create metadata mapping | |
sprite_info = {} | |
# Process each entry in the metadata | |
for sprite_id, description in metadata.items(): | |
# Extract information safely | |
info = extract_info_safely(description) | |
# Create folder name using the sprite ID in the correct format | |
folder_name = f"spritesheet_{sprite_id}" | |
# Create organized structure with folder name | |
sprite_info[sprite_id] = { | |
"frames": info["frames"], | |
"action": info["action"], | |
"direction": info["direction"], | |
"character": info["character"], | |
"folder_name": folder_name, | |
"full_description": description | |
} | |
# Save metadata to JSON file | |
metadata_path = "sprite_metadata.json" | |
with open(metadata_path, "w") as f: | |
json.dump(sprite_info, f, indent=4) | |
print(f"Created sprite metadata for {len(sprite_info)} sprites") | |
return sprite_info | |
if __name__ == "__main__": | |
sprite_info = create_sprite_metadata() |