Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumlamm committed Dec 22, 2023
1 parent 7dfa874 commit adbc0c4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
51 changes: 23 additions & 28 deletions robusta/src/kvv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,20 @@ static ACCESS_TOKEN: OnceLock<String> = OnceLock::new();
async fn kvv_stops() -> Vec<Stop> {
let access_token = ACCESS_TOKEN.get().unwrap();
let api_endpoint = API_ENDPOINT.get().unwrap();
join_all(STOPS
.iter()
.map(|stop| async move {
let name = stop.1.to_string();
let stops = trias::search_stops(name, access_token.clone(), api_endpoint, 1).await.unwrap();

let first_stop = stops.into_iter().next().unwrap();
let stop_point = first_stop.stop_point;
let position = first_stop.geo_position;
Stop {
name: stop_point.stop_point_name.text,
id: stop_point.stop_point_ref,
lat: position.latitude,
lon: position.longitude,
}
})).await
join_all(STOPS.iter().map(|stop| async move {
let name = stop.1.to_string();
let stops = trias::search_stops(name, access_token.clone(), api_endpoint, 1).await.unwrap();

let first_stop = stops.into_iter().next().unwrap();
let stop_point = first_stop.stop_point;
let position = first_stop.geo_position;
Stop {
name: stop_point.stop_point_name.text,
id: stop_point.stop_point_ref,
lat: position.latitude,
lon: position.longitude,
}
})).await
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -205,18 +203,15 @@ pub async fn fetch_departures(stops: &[Stop]) -> LineDepartures {
let access_token = ACCESS_TOKEN.get().unwrap();
let api_endpoint = API_ENDPOINT.get().unwrap();

let stop_results = join_all(stops
.iter()
.map(|stop| {
let name = stop.id.clone();
let access_token = access_token.clone();
async move {
trias::stop_events(name, access_token, 10, api_endpoint)
.await
.unwrap_or_default()
}
})
).await;
let stop_results = join_all(stops.iter().map(|stop| {
let name = stop.id.clone();
let access_token = access_token.clone();
async move {
trias::stop_events(name, access_token, 10, api_endpoint)
.await
.unwrap_or_default()
}
})).await;

let mut journeys = HashMap::new();

Expand Down
23 changes: 14 additions & 9 deletions robusta/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use axum::{
use futures_util::SinkExt;
use kvv::LineDepartures;
use reqwest::StatusCode;
use tokio::sync::mpsc::Sender;
use tokio::sync::mpsc::{Receiver, Sender};
use tower::util::ServiceExt;
use tower_http::{
cors::CorsLayer,
Expand Down Expand Up @@ -54,29 +54,29 @@ enum ServerMessage {

#[derive(Debug)]
struct Client {
recv: tokio::sync::mpsc::Receiver<ws_message::ServerMessage>,
send: tokio::sync::mpsc::Sender<InputMessage>,
recv: Receiver<ws_message::ServerMessage>,
send: Sender<InputMessage>,
id: u32,
}

#[derive(Debug)]
struct ClientConnection {
id: u32,
team_id: u32,
send: tokio::sync::mpsc::Sender<ws_message::ServerMessage>,
send: Sender<ws_message::ServerMessage>,
}

#[derive(Debug)]
struct AppState {
pub teams: Vec<ws_message::TeamState>,
pub game_logic_sender: tokio::sync::mpsc::Sender<InputMessage>,
pub game_logic_sender: Sender<InputMessage>,
pub connections: Vec<ClientConnection>,
pub client_id_gen: UniqueIdGen,
pub team_id_gen: UniqueIdGen,
}

impl AppState {
const fn new(game_logic_sender: tokio::sync::mpsc::Sender<InputMessage>) -> Self {
const fn new(game_logic_sender: Sender<InputMessage>) -> Self {
Self {
teams: Vec::new(),
game_logic_sender,
Expand Down Expand Up @@ -236,7 +236,10 @@ async fn create_team(
color: team.color,
kind: team.kind,
};
state.teams.push(TeamState { team: team.clone(), ..Default::default() });
state.teams.push(TeamState {
team: team.clone(),
..Default::default()
});
Ok(Json(team))
}

Expand Down Expand Up @@ -351,7 +354,7 @@ async fn main() {
.unwrap();
}

async fn run_game_loop(mut recv: tokio::sync::mpsc::Receiver<InputMessage>, state: SharedState) {
async fn run_game_loop(mut recv: Receiver<InputMessage>, state: SharedState) {
let mut departures = HashMap::new();
let mut log_file = fs::OpenOptions::new()
.append(true)
Expand Down Expand Up @@ -448,7 +451,9 @@ async fn run_game_loop(mut recv: tokio::sync::mpsc::Receiver<InputMessage>, stat
teams: game_state
.teams
.iter()
.filter(|ts| ts.team.kind == TeamKind::Detective || ts.team.id == connection.team_id)
.filter(|ts| {
ts.team.kind == TeamKind::Detective || ts.team.id == connection.team_id
})
.cloned()
.collect(),
trains: game_state.trains.clone(),
Expand Down

0 comments on commit adbc0c4

Please sign in to comment.