Changed to use game topic for score, need to add arena topic still

master
noah metz 2024-01-21 14:01:28 -07:00
parent fdcdd59629
commit 0642a9980a
1 changed files with 6 additions and 21 deletions

@ -18,12 +18,11 @@ use std::net::TcpStream;
use std::sync::mpsc; use std::sync::mpsc;
// MQTT Topics: // MQTT Topics:
// - division/{division_id} // - division/{division_id}/{round}/{match}/score
// - division/{division_id}/ranking // - division/{division_id}/ranking
// - arena/{arena_id}/score // - arena/{arena_id}/score
// - arena/{arena_id}/state // - arena/{arena_id}/state
// - arena/{arena_id} // - arena/{arena_id}
// - game/{division_id}/{game_id}/score
// - team/{team_string} // - team/{team_string}
pub mod tm { pub mod tm {
@ -712,14 +711,16 @@ fn on_score_change(notice: tm::Notice, event: Event, _connection: &TMConnection)
match get_affected_match(&notice) { match get_affected_match(&notice) {
None => (Vec::new(), event), None => (Vec::new(), event),
Some(tuple) => { Some(tuple) => {
// Use `event` to figure out which arena topic to publish to
// Also add the match score topic based on the tuple
match get_game_score(&notice) { match get_game_score(&notice) {
None => (Vec::new(), event), None => (Vec::new(), event),
Some(score) => { Some(score) => {
let serialized = serde_json::to_string(&score).unwrap(); let serialized = serde_json::to_string(&score).unwrap();
let arena_topic = String::from("arena/TEST/score"); let game_topic = format!("division/{}/{:?}/{}/score", tuple.division, tuple.round, tuple.match_num);
let mut out = Vec::new(); let mut out = Vec::new();
out.push(MQTTMessage{ out.push(MQTTMessage{
topic: arena_topic, topic: game_topic,
payload: serialized, payload: serialized,
}); });
return (out, event); return (out, event);
@ -796,28 +797,12 @@ fn on_match_list_update(_notice: tm::Notice, _event: Event, connection: &TMConne
return _on_match_list_update(connection); return _on_match_list_update(connection);
} }
fn on_match_score_update(notice: tm::Notice, event: Event, _connection: &TMConnection) -> (Vec<MQTTMessage>, Event) {
match get_game_score(&notice) {
None => (Vec::new(), event),
Some(score) => {
let serialized = serde_json::to_string(&score).unwrap();
let arena_topic = String::from("arena/TEST/score");
let mut out = Vec::new();
out.push(MQTTMessage{
topic: arena_topic,
payload: serialized,
});
return (out, event);
},
}
}
fn main() { fn main() {
env_logger::init(); env_logger::init();
let mut callbacks: HashMap<tm::NoticeId, NoticeCallback> = HashMap::new(); let mut callbacks: HashMap<tm::NoticeId, NoticeCallback> = HashMap::new();
callbacks.insert(tm::NoticeId::NoticeRealtimeScoreChanged, on_score_change); callbacks.insert(tm::NoticeId::NoticeRealtimeScoreChanged, on_score_change);
callbacks.insert(tm::NoticeId::NoticeMatchScoreUpdated, on_match_score_update); callbacks.insert(tm::NoticeId::NoticeMatchScoreUpdated, on_score_change);
callbacks.insert(tm::NoticeId::NoticeFieldTimerStarted, on_match_start); callbacks.insert(tm::NoticeId::NoticeFieldTimerStarted, on_match_start);
callbacks.insert(tm::NoticeId::NoticeFieldTimerStopped, on_match_cancel); callbacks.insert(tm::NoticeId::NoticeFieldTimerStopped, on_match_cancel);
callbacks.insert(tm::NoticeId::NoticeFieldResetTimer, on_match_reset); callbacks.insert(tm::NoticeId::NoticeFieldResetTimer, on_match_reset);