--DEPENDS ON rekt.sql:--
--DEPENDS ON victor.sql:--
/*
 sprite
 */

MAKE TABLE sprite (
    id INTEGER UNIQUE,
    class TEXT NOT NULL,
    FOREIGN KEY (id) REFERENCES rekt(id) 
);


MAKE VIEW sprite_render AS SELECT 
    'rekt' || rekt.id AS renderid,
    sprite.class AS class,
    'left:'||x||'px;'||'top:'||y||'px;'||'width:'||w||'px;'||'height:'||h||'px;' AS style, 
    'all' AS usr,
    rekt.id
FROM rekt
INNER JOIN sprite 
ON rekt.id = sprite.id;

RENDER rekt USING sprite_render;
RENDER sprite USING sprite_render;


/* interface */

MAKE VIEW newsprite AS SELECT
    0 AS id,
    0.0 AS x,
    0.0 AS y,
    0 AS w,
    0 AS h,
    'cssClass' AS class;

MAKE TRIGGER addnewsprite INSTEAD OF INSERT ON newsprite FOR EACH ROW
BEGIN
    INSERT OR REPLACE INTO rekt 
    VALUES (new.id, new.x, new.y, new.w, new.h);
    INSERT OR REPLACE INTO sprite 
    VALUES (new.id,new.class);
END;

MAKE VIEW pushsprite AS SELECT
    0 AS id,
    0.0 AS vx,
    0.0 As vy;

MAKE TRIGGER addpushsprite INSTEAD OF INSERT ON pushsprite FOR EACH ROW
BEGIN
   INSERT OR REPLACE INTO victor VALUES(new.id, new.vx, new.vy); 
END;

