sandpypi/src/core/loaders/particle_loader.py
2024-12-28 16:54:21 -06:00

36 lines
1.2 KiB
Python

import os
import json
from typing import Dict, Any
class ParticleLoader:
def __init__(self):
self.base_path = "config/particles"
self.categories = {
"elements": ["basic", "liquids", "gases", "solids"],
"states": ["frozen", "molten", "burning"],
"special": ["effects", "forces"],
}
def load_all_particles(self) -> Dict[str, Any]:
"""Load and merge all particle configurations"""
all_particles = {}
for category, subcategories in self.categories.items():
category_path = os.path.join(self.base_path, category)
for subcat in subcategories:
file_path = os.path.join(category_path, f"{subcat}.json")
particles = self._load_json_file(file_path)
all_particles.update(particles)
return all_particles
def _load_json_file(self, file_path: str) -> Dict[str, Any]:
"""Load a single JSON configuration file"""
try:
with open(file_path, "r") as f:
return json.load(f)
except FileNotFoundError:
print(f"Warning: Configuration file not found: {file_path}")
return {}