mirror of
https://github.com/fluencelabs/fluence-shared-canvas
synced 2025-04-25 07:02:15 +00:00
IT WORKS!!!
This commit is contained in:
parent
81e121c1b9
commit
a3b5765a63
@ -42,14 +42,15 @@ impl Cell {
|
|||||||
|
|
||||||
// ================== CanvasManager ==================
|
// ================== CanvasManager ==================
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct CanvasManager {
|
pub struct CanvasManager {
|
||||||
canvas: HashMap<Cell, String>
|
canvas: HashMap<Cell, String>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CanvasManager {
|
impl CanvasManager {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let x_size = 1000;
|
let x_size = 10;
|
||||||
let y_size = 1000;
|
let y_size = 10;
|
||||||
let white_colour = String::from("#ffafff");
|
let white_colour = String::from("#ffafff");
|
||||||
|
|
||||||
let mut canvas_map: HashMap<Cell, String> = HashMap::new();
|
let mut canvas_map: HashMap<Cell, String> = HashMap::new();
|
||||||
@ -73,11 +74,15 @@ impl CanvasManager {
|
|||||||
|
|
||||||
let json_response: AppResult<Value> = serde_json::to_value(result).map_err(Into::into);
|
let json_response: AppResult<Value> = serde_json::to_value(result).map_err(Into::into);
|
||||||
|
|
||||||
match &json_response {
|
|
||||||
Ok(res) => info!("JSON ok : {}", res.to_string()),
|
|
||||||
Err(err) => info!("JSON error: {}", err.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
json_response
|
json_response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set(&mut self, x_coord: u32, y_coord: u32, colour: String) -> AppResult<Value> {
|
||||||
|
self.canvas.insert(Cell::new(x_coord, y_coord), colour);
|
||||||
|
|
||||||
|
let result = Response::PaintResult {
|
||||||
|
ok: true
|
||||||
|
};
|
||||||
|
serde_json::to_value(result).map_err(Into::into)
|
||||||
|
}
|
||||||
}
|
}
|
@ -37,6 +37,6 @@ fn do_request(req: String) -> AppResult<Value> {
|
|||||||
|
|
||||||
match request {
|
match request {
|
||||||
Request::Get => CANVAS_MANAGER.with(|cm| cm.borrow_mut().to_response()),
|
Request::Get => CANVAS_MANAGER.with(|cm| cm.borrow_mut().to_response()),
|
||||||
Request::Set{x_coord, y_coord, colour} => serde_json::from_str("lala").map_err(Into::into)
|
Request::Set{x_coord, y_coord, colour} => CANVAS_MANAGER.with(|cm| cm.borrow_mut().set(x_coord, y_coord, colour))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ pub enum Request {
|
|||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum Response {
|
pub enum Response {
|
||||||
Matrix { state: Vec<CellStateResponse> },
|
Matrix { state: Vec<CellStateResponse> },
|
||||||
PaintResult { error: Option<String> },
|
PaintResult { ok: bool },
|
||||||
Error { message: String },
|
Error { message: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user