moved default sories location and added some proper error handling
This commit is contained in:
+1
-1
@@ -49,7 +49,7 @@ pub async fn api_process
|
||||
// Perform this code on a GET request
|
||||
.map(|state: Arc<Mutex<DataToSend>>, tx_handle: Sender<(bool,usize)>|
|
||||
{
|
||||
info!("GET: {:?}", state);
|
||||
debug!("GET: {:?}", state);
|
||||
let reply = state.as_ref();
|
||||
let _ = tx_handle.send((true,0));
|
||||
warp::reply::json(&reply) // Send the reply data (data_to_send formatted as JSON)
|
||||
|
||||
+5
-4
@@ -28,6 +28,7 @@ mod character;
|
||||
mod config;
|
||||
mod api;
|
||||
|
||||
#[warn(clippy::all, clippy::pedantic)]
|
||||
#[tokio::main]
|
||||
async fn main()
|
||||
{
|
||||
@@ -42,7 +43,7 @@ async fn main()
|
||||
error!("No filename specified");
|
||||
std::process::exit(5);
|
||||
});
|
||||
let file = File::open(format!("stories/{}",file_name))
|
||||
let file = File::open(format!("../stories/{}",file_name))
|
||||
.unwrap_or_else
|
||||
(|err| {
|
||||
error!("Failed to open file: {}", err);
|
||||
@@ -59,7 +60,7 @@ async fn main()
|
||||
{
|
||||
Ok(result) =>
|
||||
{
|
||||
info!("{:?}", result);
|
||||
debug!("{:?}", result);
|
||||
result
|
||||
},
|
||||
Err(error) =>
|
||||
@@ -72,8 +73,8 @@ async fn main()
|
||||
let data_to_send = Arc::new(Mutex::new(api::DataToSend
|
||||
{
|
||||
action_type: "begin".to_string(),
|
||||
content: "".to_string(),
|
||||
character: "".to_string(),
|
||||
content: String::new(),
|
||||
character: String::new(),
|
||||
choices: vec![],
|
||||
}));
|
||||
|
||||
|
||||
+20
-4
@@ -25,12 +25,14 @@ pub async fn token_parse(
|
||||
rx: &Receiver<(bool,usize)>,
|
||||
) -> Result<(),String>
|
||||
{
|
||||
info!("DSL parsing begun");
|
||||
let mut index: usize = 0;
|
||||
if rx.recv().is_err()
|
||||
{
|
||||
warn!("Some issue with api");
|
||||
// TOD eh?
|
||||
};
|
||||
info!("Client has connected");
|
||||
// Run an infinite loop
|
||||
'parse_loop: loop
|
||||
{
|
||||
@@ -43,7 +45,7 @@ pub async fn token_parse(
|
||||
if token.starts_with('@')
|
||||
{
|
||||
let character_name: String = token.chars().skip(1).collect();
|
||||
info!("Doing something with a character: {}", character_name);
|
||||
debug!("Doing something with a character: {}", character_name);
|
||||
// The index is incremented to after the character's instructions
|
||||
index = match character_parse(index+1, tokens, character_name, &characters, &data_to_send).await
|
||||
{
|
||||
@@ -59,7 +61,7 @@ pub async fn token_parse(
|
||||
"end" =>
|
||||
{
|
||||
info!("END command, exiting");
|
||||
return Ok(()) // quit
|
||||
return Ok(()) // quit successfully
|
||||
},
|
||||
"choice" =>
|
||||
{
|
||||
@@ -69,14 +71,28 @@ pub async fn token_parse(
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
if rx.recv().is_err() { warn!("Error sending choices to client"); };
|
||||
let (_, choice) = rx.recv().unwrap(); // TODO eh
|
||||
let (_, choice) = match rx.recv()
|
||||
{
|
||||
Ok((_,choice)) => (None::<bool>, choice),
|
||||
Err(err) =>
|
||||
{
|
||||
warn!("Error receiving choice from client, defaulting to choice 0 {}", err);
|
||||
(None::<bool>, 0)
|
||||
}
|
||||
};
|
||||
index = jump_points[choice];
|
||||
info!("CHOICE command with {} choices", jump_points.len());
|
||||
debug!("{:?} {} {}",jump_points, choice, index);
|
||||
continue 'parse_loop
|
||||
},
|
||||
"or" =>
|
||||
{
|
||||
index += strings::closing_char(&tokens[index..], '{','}').unwrap(); // TODO eh
|
||||
info!("OR command, jumping over");
|
||||
index += match strings::closing_char(&tokens[index..], '{','}') // TODO eh
|
||||
{
|
||||
Ok(index) => index,
|
||||
Err(_) => return Err(String::from("Unable to find closing brace to OR command")),
|
||||
};
|
||||
continue
|
||||
},
|
||||
"}" =>
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"tim": {
|
||||
"name": "Timothy Sharpshooter",
|
||||
"gender": "",
|
||||
"skin_color": "",
|
||||
"eye_color": "",
|
||||
"pronoun_subject": "",
|
||||
"pronoun_object": "",
|
||||
"pronoun_deppos": "",
|
||||
"pronoun_indpos": "",
|
||||
"pronoun_reflex": "",
|
||||
"animation": "",
|
||||
"head": "",
|
||||
"hair": "",
|
||||
"torso": "",
|
||||
"arm": "",
|
||||
"leg": "",
|
||||
"hair_color": "",
|
||||
"top_clothing": "",
|
||||
"bottom_clothing": "",
|
||||
"shoes": ""
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,8 +0,0 @@
|
||||
@tim says "hello world, it's a good day"
|
||||
choice "choice numero uno" {
|
||||
@tim says "super sad"
|
||||
}
|
||||
or "choice numero duo" {
|
||||
@tim says "super unsad"
|
||||
}
|
||||
END
|
||||
Binary file not shown.
Reference in New Issue
Block a user