From 005fb13e218dea0c238d77dcb589f8df01440ccf Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Thu, 18 Jan 2024 18:01:39 -0700 Subject: [PATCH] Added Event struct which can be modified by callbacks --- src/main.rs | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8ceb171..af37ac4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -166,9 +166,9 @@ fn get_game_score(scores: tm::MatchScore) -> Option { return Some(out); } -fn on_score_change(notice: tm::Notice) -> Vec { +fn on_score_change(notice: tm::Notice, event: Event) -> (Vec, Event) { match notice.match_score { - None => return Vec::new(), + None => return (Vec::new(), event), Some(game_scores) => { match get_game_score(game_scores) { Some(score_json) => { @@ -179,9 +179,9 @@ fn on_score_change(notice: tm::Notice) -> Vec { topic: arena_topic, payload: serialized, }); - return out; + return (out, event); }, - None => return Vec::new(), + None => return (Vec::new(), event), } }, } @@ -192,9 +192,38 @@ fn get_next_notice() -> tm::Notice { return tm::Notice::default(); } -type NoticeCallback = fn(tm::Notice) -> Vec; +struct Event<'a> { + name: String, + divisions: Vec>, +} + +type NoticeCallback = fn(tm::Notice, Event) -> (Vec, Event); + +struct Division<'a> { + name: String, + matches: Vec, + field_set: FieldSet<'a>, +} + +struct FieldSet<'a> { + fields: Vec>, +} + +struct Field<'a> { + name: String, + current_match: &'a Match, +} + +struct Match { + name: String, +} fn main() { + let mut event = Event{ + name: String::from(""), + divisions: Vec::new(), + }; + let mut callbacks: HashMap = HashMap::new(); callbacks.insert(tm::NoticeId::NoticeRealtimeScoreChanged, on_score_change); @@ -229,7 +258,8 @@ fn main() { } }, Some(callback) => { - let messages = callback(notice); + let (messages, next_event) = callback(notice, event); + event = next_event; for message in messages { let result = client.publish(message.topic, QoS::AtMostOnce, true, message.payload); match result {