From a85a49c15667e2067d786408bca642516b5fd84b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 26 Jun 2020 22:14:34 +0100 Subject: [PATCH] initial move - jerky --- src/bin/server.rs | 19 ++++++++++++++++--- templates/script.js | 5 +++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index 3c0df0f3..d2736c78 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -114,10 +114,22 @@ struct ApiGrab { t : String, p : VisiblePieceId, } - #[post("/_/api/grab", format="json", data="
")] #[throws(RE)] -fn api(form : Json) -> impl response::Responder<'static> { +fn api_grab(form : Json) -> impl response::Responder<'static> { + eprintln!("API {:?}", &form); + "" +} + +#[derive(Debug,Serialize,Deserialize)] +struct ApiMove { + t : String, + p : VisiblePieceId, + l : Pos, +} +#[post("/_/api/m", format="json", data="")] +#[throws(RE)] +fn api_move(form : Json) -> impl response::Responder<'static> { eprintln!("API {:?}", &form); "" } @@ -193,7 +205,8 @@ fn main() { session, resource, updates, - api, + api_grab, + api_move, ]) .launch(); } diff --git a/templates/script.js b/templates/script.js index 17d3b381..6f0f123e 100644 --- a/templates/script.js +++ b/templates/script.js @@ -69,6 +69,11 @@ function drag_mousemove(e) { delt.setAttributeNS(null, "x", x); delt.setAttributeNS(null, "y", y); console.log(delt); + xhr_post_then('/_/api/m',JSON.stringify({ + t : token, + p : delt.dataset.p, + l : [Math.round(x),Math.round(y)], + }), function(){}); } } -- 2.30.2