import json from typing import Any import db from .ensure_animation_schema import ensure_animation_schema # Point de départ raisonnable pour un nouveau clip "personnalisé" : un # fondu simple de 0 à 1, que le créateur du jeu peut ensuite modifier ou # remplacer entièrement dans l'éditeur de images-clés. _DEFAULT_CUSTOM_KEYFRAMES: list[dict[str, Any]] = [ {"percent": 0, "props": {"opacity": "0"}}, {"percent": 100, "props": {"opacity": "1"}}, ] def add_animation_clip( slug: str, screen_id: int, element_id: int, kind: str = "animate_css", animate_name: str | None = None, custom_keyframes: list[dict[str, Any]] | None = None, start_time: float = 0, duration: float = 1, delay: float = 0, easing: str = "ease", iteration_count: str = "1", ) -> int: ensure_animation_schema(slug) if kind == "custom" and not custom_keyframes: custom_keyframes = _DEFAULT_CUSTOM_KEYFRAMES if kind == "animate_css" and not animate_name: animate_name = "fadeIn" keyframes_json = json.dumps(custom_keyframes) if custom_keyframes else None conn = db.connect(slug) conn.execute( """INSERT INTO _animation_clips (screen_id, element_id, kind, animate_name, custom_keyframes, start_time, duration, delay, easing, iteration_count) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""", ( screen_id, element_id, kind, animate_name, keyframes_json, float(start_time), float(duration), float(delay), easing, str(iteration_count), ), ) clip_id = int(conn.execute("SELECT last_insert_rowid() AS id").fetchone()["id"]) conn.commit() conn.close() return clip_id