syntax = "proto3";

package frameserver;

service FrameServer {
    // Returns a serialization of the scene at the specified time.
    rpc GetFrameAtTime (FrameRequest) returns (FrameResponse);

    // Returns a list of the names and durations of all animations in the scene.
    rpc FetchSceneData (EmptyRequest) returns (FetchSceneDataResponse);

    // Returns when the manim script changes
    rpc ScriptUpdated (EmptyRequest) returns (EmptyResponse);
}

message FetchSceneDataResponse {
    Scene scene = 1;
    string path = 2;
}

message Scene {
    string name = 1;
    repeated Animation animations = 2;
    string background_color = 3;
}

message Animation {
    string name = 1;
    float duration = 2;
    string easing_function = 3;

    message AttributeTweenData {
        string attribute = 1;
        repeated float start_data = 2;
        repeated float end_data = 3;
    }
    repeated AttributeTweenData attribute_tween_data = 4;

    message MobjectTweenData {
        string id = 1;
        repeated float root_mobject_offset = 2;
    }
    repeated MobjectTweenData mobject_tween_data = 5;
    repeated string flickered_mobject_ids = 6;
}

message Updater {
    repeated string flickered_mobject_ids = 1;
}

message FrameRequest {
    int32 end_index = 1;
    bool first_request = 2;
    int32 animation_index = 3;
    float animation_offset = 4;
}

message Style {
    string fill_color = 1;
    float fill_opacity = 2;
    string stroke_color = 3;
    float stroke_opacity = 4;
    float stroke_width = 5;
}

message Point {
    float x = 1;
    float y = 2;
    float z = 3;
}

message MobjectData {
    string id = 1;
    Style style = 2;
    enum MobjectType {
        VMOBJECT = 0;
        IMAGE_MOBJECT = 1;
    }
    MobjectType type = 3;
    VMobjectData vectorized_mobject_data = 4;
    ImageMobjectData image_mobject_data = 5;
    repeated float root_mobject_offset = 6;
}

message VMobjectData {
    repeated Point points = 1;
    bool needs_redraw = 2;
}

message ImageMobjectData {
    string path = 1;
    float height = 2;
    float width = 3;
    Point center = 4;
}

message FrameData {
    repeated string remove = 1;
    repeated MobjectData add = 2;
    repeated MobjectData update = 3;
}

message FrameResponse {
    FrameData frame_data = 1;
    bool scene_finished = 2;
    repeated Animation animations = 3;
    repeated Updater updaters = 4;
    int32 animation_index = 5;
    float animation_offset = 6;
    bool all_animations_tweened = 7;
}

message EmptyRequest {}
message EmptyResponse {}
