Changed the data_to_send to be a stack so many lines of code can

be pre-processed before the user interacts.
When the /happening api is called it just dequeues the front item
This commit is contained in:
2026-05-19 19:23:19 +01:00
parent 019f1088a3
commit ee34493895
6 changed files with 180 additions and 148 deletions
+5 -4
View File
@@ -9,6 +9,7 @@ use crate::
Mutex,
Arc,
HashMap,
VecDeque,
info,
warn,
debug,
@@ -23,7 +24,7 @@ pub fn character_parse
tokens: &[tokenise::Token],
character_name: String,
characters: &Arc<Mutex<HashMap::<String, character::Character>>>,
data_to_send: &Arc<Mutex<api::DataToSend>>,
happening_queue: &Arc<Mutex<VecDeque<api::DataToSend>>>,
) -> Result<usize,(String,usize)>
{
let mut sum_index: usize = index;
@@ -47,7 +48,7 @@ pub fn character_parse
let output = tokenise::get_string_token(tokens, sum_index)
.map_err(|err| (err, index))?;
debug!("Saying {output}");
api::modify_data(data_to_send, "output".to_string(), output, character_name, vec![]);
api::modify_data(happening_queue, "output".to_string(), output, character_name, vec![]);
},
// Change the property of the selected character eg @tim CHANGE name "Bill Buffins"
// will change the character with ID tim to "Bill Buffins"; a character's ID cannot change
@@ -65,7 +66,7 @@ pub fn character_parse
&& character.set_field(&feature, &string)
.is_err() { warn!("Feature {feature} does not exist") }
drop(characters);
api::modify_data(data_to_send, "change".to_string(), String::new(), character_name, vec![]);
api::modify_data(happening_queue, "change".to_string(), String::new(), character_name, vec![]);
},
// These two are mainly just actions performed by the frontend client, so just tell the client to move/animate
// the character and not much other processing needed on the serverside
@@ -74,7 +75,7 @@ pub fn character_parse
sum_index += 1;
let content = tokenise::get_keyword_token(tokens, sum_index)
.map_err(|err| (err, index))?;
api::modify_data(data_to_send, keyword.to_lowercase(), content, character_name, vec![]);
api::modify_data(happening_queue, keyword.to_lowercase(), content, character_name, vec![]);
},
// Catch all condition, if the instruction is unrecognised as a
// character command