Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
members = [
"animation-api",
"animation-macros",
"animation-template-native",
"animation-template-wasm",
"animation-template",
"animation-utils",
"animation-wasm-bindings",
"animation-wrapper",
Expand Down
25 changes: 1 addition & 24 deletions animation-api/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::collections::HashMap;

use serde::{Deserialize, Serialize, de::DeserializeOwned};

use crate::schema::{ConfigurationSchema, GetEnumOptions, GetSchema, ParameterValue};
use crate::schema::{ConfigurationSchema, GetEnumOptions, GetSchema};

#[derive(Serialize, Deserialize, Debug, thiserror::Error)]
#[error("animation error: {message}")]
Expand Down Expand Up @@ -50,24 +48,3 @@ pub trait Animation {

fn render(&self) -> lightfx::Frame;
}

#[derive(Serialize, Deserialize)]
#[serde(tag = "method", content = "params")]
pub enum JsonRpcMethod {
Initialize {
points: Vec<(f64, f64, f64)>,
},
ParameterSchema,
SetParameters {
params: HashMap<String, ParameterValue>,
},
GetParameters,
GetFps,
Update {
time_delta: f64,
},
OnEvent {
event: crate::event::Event,
},
Render,
}
9 changes: 1 addition & 8 deletions animation-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
mod api;
pub mod event;
mod msg;
pub mod plugin_config;
pub mod schema;

pub use api::Animation;
pub use api::AnimationError;
pub use api::JsonRpcMethod;

pub use msg::ErrorType;
pub use msg::JsonRpcError;
pub use msg::JsonRpcMessage;
pub use msg::JsonRpcResponse;
pub use msg::JsonRpcResult;
42 changes: 0 additions & 42 deletions animation-api/src/msg.rs

This file was deleted.

25 changes: 25 additions & 0 deletions animation-api/src/plugin_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::path::PathBuf;

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum PluginApiVersion {
#[serde(rename = "0.9")]
V0_9,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginManifest {
pub id: String,
pub display_name: String,
pub author: String,
pub api_version: PluginApiVersion,
pub version: String,
pub tags: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginConfig {
pub manifest: PluginManifest,
pub path: PathBuf,
}
134 changes: 0 additions & 134 deletions animation-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,140 +19,6 @@ fn generate_wasm_plugin(ast: syn::ItemStruct) -> proc_macro2::TokenStream {
}
}

#[proc_macro_attribute]
pub fn plugin(_attr: TokenStream, item: TokenStream) -> TokenStream {
let ast: syn::ItemStruct = syn::parse2(item.into()).unwrap();
generate_native_plugin(ast).into()
}

fn generate_native_plugin(ast: syn::ItemStruct) -> proc_macro2::TokenStream {
let name = &ast.ident;
quote! {
#ast

fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
use std::{
error::Error,
io::{BufRead, BufReader},
};

use animation_api::{JsonRpcMessage, JsonRpcMethod, JsonRpcError, ErrorType, AnimationError};
use serde::Serialize;
use serde_json::json;

fn receive(
reader: &mut impl BufRead,
) -> Result<Option<JsonRpcMessage<JsonRpcMethod>>, Box<dyn Error>> {
let mut buffer = String::new();
if reader.read_line(&mut buffer)? == 0 {
Ok(None)
} else {
Ok(Some(serde_json::from_str(&buffer)?))
}
}

fn respond<T>(id: Option<usize>, payload: T)
where
T: Serialize,
{
let Some(id) = id else { return; };

println!(
"{}",
json!({
"id": id,
"result": payload,
})
);
}

fn error(id: Option<usize>, message: String)
{
let Some(id) = id else { return; };

println!(
"{}",
json!({
"id": id,
"error": JsonRpcError {
code: ErrorType::AnimationError,
message: "Animation Error".into(),
data: AnimationError {
message
}
},
})
);
}

let mut animation = None;
let mut stdin = BufReader::new(std::io::stdin());

loop {
match receive(&mut stdin) {
Ok(Some(message)) => match message.payload {
JsonRpcMethod::Initialize { points } => {
animation = None;
animation = Some(<#name>::new_wrapped(points));
respond(message.id, ());
}
JsonRpcMethod::ParameterSchema => {
if let Some(animation) = animation.as_ref() {
respond(message.id, animation.get_schema());
}
},
JsonRpcMethod::SetParameters { params } => {
if let Some(mut animation) = animation.as_mut() {
match serde_json::from_value(serde_json::json!(params)) {
Ok(params) => {
animation.set_parameters(params);
respond(message.id, ());
}
Err(e) => error(message.id, e.to_string())
}
}
},
JsonRpcMethod::GetParameters => {
if let Some(animation) = animation.as_ref() {
respond(message.id, serde_json::json!(animation.get_parameters()));
}
},
JsonRpcMethod::GetFps => {
if let Some(animation) = animation.as_ref() {
respond(message.id, animation.get_fps());
}
},
JsonRpcMethod::Update { time_delta } => {
if let Some(mut animation) = animation.as_mut() {
animation.update(time_delta);
}
},
JsonRpcMethod::OnEvent { event } => {
if let Some(mut animation) = animation.as_mut() {
animation.on_event(event);
}
respond(message.id, ());
},
JsonRpcMethod::Render => {
if let Some(animation) = animation.as_ref() {
respond(message.id, animation.render());
}
},
},
Ok(None) => {
break;
}
Err(err) => {
eprintln!("Animation error: {:?}", err);
break;
}
}
}
Ok(())
}
}
}

#[derive(Debug, Clone, FromMeta)]
struct Number {
min: f64,
Expand Down
12 changes: 0 additions & 12 deletions animation-template-native/Cargo.toml

This file was deleted.

21 changes: 0 additions & 21 deletions animation-template-native/README.md

This file was deleted.

13 changes: 0 additions & 13 deletions animation-template-native/manifest.json

This file was deleted.

Loading