Added a character route for requesting character data from the server

This commit is contained in:
2026-04-30 14:53:04 +01:00
parent 800bee13da
commit 93c09290cd
11 changed files with 139 additions and 23 deletions
+21 -5
View File
@@ -10,6 +10,8 @@ use log::
warn,
debug,
};
use serde_json::from_str;
use serde::{Deserialize, Serialize};
mod parsing;
mod character;
@@ -30,24 +32,33 @@ async fn main()
content: "".to_string(),
character: "".to_string(),
}));
// Setup the characters hashmap which will store each character in it as a Character struct
let mut characters: Arc<Mutex<HashMap::<String, character::Character>>> = Default::default();
match character::character_parse().await
{
Ok(result) => characters = result, //let mut characters = character,
Err(error) =>
{
eprintln!("{}",error);
std::process::exit(3);
},
};
// setup the api stuff //
// Make clones of the data Arc for the two processes
let data_clone1 = Arc::clone(&data_to_send);
let characters_clone1 = Arc::clone(&characters);
let tx_clone = tx.clone();
// Spawn a thread for warp api server
tokio::spawn(
async move {
api::api_process(data_clone1, tx_clone).await;
api::api_process(data_clone1, characters_clone1, tx_clone).await;
});
// setup the parsing stuff //
// Setup the characters hashmap which will store each character in it as a Character struct
let mut characters = HashMap::<String, character::Character>::new();
// Read the file and split it into tokens
let file_contents: String = fs::read_to_string("stories/story.ha") // TODO make this a command line argument
.unwrap_or_else(|err|
@@ -58,10 +69,15 @@ async fn main()
let tokens: Vec<&str> = file_contents
.split_whitespace()
.collect();
if ! tokens.contains(&"END")
{
warn!("No END statement, story may exit unexpectedly");
}
let data_clone2 = Arc::clone(&data_to_send);
let characters_clone2 = Arc::clone(&characters);
// Run the parsing process
match parsing::token_parse(&tokens, &mut characters, data_clone2, &rx).await
match parsing::token_parse(&tokens, characters_clone2, data_clone2, &rx).await
{
// Exit with error or success
Ok(()) =>