38 lines
1.5 KiB
Python
38 lines
1.5 KiB
Python
import json
|
|
|
|
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 = [
|
|
{"percent": 0, "props": {"opacity": "0"}},
|
|
{"percent": 100, "props": {"opacity": "1"}},
|
|
]
|
|
|
|
|
|
def add_animation_clip(slug, screen_id, element_id, kind="animate_css", animate_name=None,
|
|
custom_keyframes=None, start_time=0, duration=1, delay=0,
|
|
easing="ease", iteration_count="1"):
|
|
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 = conn.execute("SELECT last_insert_rowid() AS id").fetchone()["id"]
|
|
conn.commit()
|
|
conn.close()
|
|
return clip_id
|