Skip to content

Commit

Permalink
BE/WebSockets: 'initialised: false' sends random initial coords
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanie-flower committed Mar 3, 2024
1 parent f793744 commit bc4c69c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ warp = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
futures = { version = "0.3", default-features=false}
serde_repr = "0.1"
serde_repr = "0.1"
rand = "0.8.5"
1 change: 0 additions & 1 deletion backend/src/websocketstructs.rs

This file was deleted.

19 changes: 15 additions & 4 deletions backend/src/ws/gen_json.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use core::fmt;
use cosmic_kube::kube::Kube;
use serde::{Deserialize, Serialize};
use serde_json::json;
use serde_json::{json, Value};
use serde_repr::{Serialize_repr, Deserialize_repr};
use rand::Rng;

// this is the data we expect to recieve from the player
#[derive(Serialize, Deserialize)]
pub struct PlayerInfo {
initialised: bool,
player: String, //Player, //the player requesting the data
coordinates: [u64; 2], //current player coordinates
action: Option<Action>, // 0, block picked up 1, block placed
Expand Down Expand Up @@ -43,10 +45,19 @@ fn recalculate_game(state: PlayerInfo) -> String {
}

//send action to database to get result !!!<----
let resp: Value;

let resp = json!({
"grid" : "edited grid"
});
if state.initialised {
resp = json!({
"grid" : "edited grid"
});
} else {
let mut rng = rand::thread_rng();
resp = json!({
"coordinates" : [rng.gen_range(0..2048), rng.gen_range(0..2048)]
});
}


resp.to_string()
}
Expand Down

0 comments on commit bc4c69c

Please sign in to comment.