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
|
// Perform this code on a GET request
|
||||||
.map(|state: Arc<Mutex<DataToSend>>, tx_handle: Sender<(bool,usize)>|
|
.map(|state: Arc<Mutex<DataToSend>>, tx_handle: Sender<(bool,usize)>|
|
||||||
{
|
{
|
||||||
info!("GET: {:?}", state);
|
debug!("GET: {:?}", state);
|
||||||
let reply = state.as_ref();
|
let reply = state.as_ref();
|
||||||
let _ = tx_handle.send((true,0));
|
let _ = tx_handle.send((true,0));
|
||||||
warp::reply::json(&reply) // Send the reply data (data_to_send formatted as JSON)
|
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 config;
|
||||||
mod api;
|
mod api;
|
||||||
|
|
||||||
|
#[warn(clippy::all, clippy::pedantic)]
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main()
|
async fn main()
|
||||||
{
|
{
|
||||||
@@ -42,7 +43,7 @@ async fn main()
|
|||||||
error!("No filename specified");
|
error!("No filename specified");
|
||||||
std::process::exit(5);
|
std::process::exit(5);
|
||||||
});
|
});
|
||||||
let file = File::open(format!("stories/{}",file_name))
|
let file = File::open(format!("../stories/{}",file_name))
|
||||||
.unwrap_or_else
|
.unwrap_or_else
|
||||||
(|err| {
|
(|err| {
|
||||||
error!("Failed to open file: {}", err);
|
error!("Failed to open file: {}", err);
|
||||||
@@ -59,7 +60,7 @@ async fn main()
|
|||||||
{
|
{
|
||||||
Ok(result) =>
|
Ok(result) =>
|
||||||
{
|
{
|
||||||
info!("{:?}", result);
|
debug!("{:?}", result);
|
||||||
result
|
result
|
||||||
},
|
},
|
||||||
Err(error) =>
|
Err(error) =>
|
||||||
@@ -72,8 +73,8 @@ async fn main()
|
|||||||
let data_to_send = Arc::new(Mutex::new(api::DataToSend
|
let data_to_send = Arc::new(Mutex::new(api::DataToSend
|
||||||
{
|
{
|
||||||
action_type: "begin".to_string(),
|
action_type: "begin".to_string(),
|
||||||
content: "".to_string(),
|
content: String::new(),
|
||||||
character: "".to_string(),
|
character: String::new(),
|
||||||
choices: vec![],
|
choices: vec![],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
+20
-4
@@ -25,12 +25,14 @@ pub async fn token_parse(
|
|||||||
rx: &Receiver<(bool,usize)>,
|
rx: &Receiver<(bool,usize)>,
|
||||||
) -> Result<(),String>
|
) -> Result<(),String>
|
||||||
{
|
{
|
||||||
|
info!("DSL parsing begun");
|
||||||
let mut index: usize = 0;
|
let mut index: usize = 0;
|
||||||
if rx.recv().is_err()
|
if rx.recv().is_err()
|
||||||
{
|
{
|
||||||
warn!("Some issue with api");
|
warn!("Some issue with api");
|
||||||
// TOD eh?
|
// TOD eh?
|
||||||
};
|
};
|
||||||
|
info!("Client has connected");
|
||||||
// Run an infinite loop
|
// Run an infinite loop
|
||||||
'parse_loop: loop
|
'parse_loop: loop
|
||||||
{
|
{
|
||||||
@@ -43,7 +45,7 @@ pub async fn token_parse(
|
|||||||
if token.starts_with('@')
|
if token.starts_with('@')
|
||||||
{
|
{
|
||||||
let character_name: String = token.chars().skip(1).collect();
|
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
|
// The index is incremented to after the character's instructions
|
||||||
index = match character_parse(index+1, tokens, character_name, &characters, &data_to_send).await
|
index = match character_parse(index+1, tokens, character_name, &characters, &data_to_send).await
|
||||||
{
|
{
|
||||||
@@ -59,7 +61,7 @@ pub async fn token_parse(
|
|||||||
"end" =>
|
"end" =>
|
||||||
{
|
{
|
||||||
info!("END command, exiting");
|
info!("END command, exiting");
|
||||||
return Ok(()) // quit
|
return Ok(()) // quit successfully
|
||||||
},
|
},
|
||||||
"choice" =>
|
"choice" =>
|
||||||
{
|
{
|
||||||
@@ -69,14 +71,28 @@ pub async fn token_parse(
|
|||||||
Err(error) => return Err(error),
|
Err(error) => return Err(error),
|
||||||
};
|
};
|
||||||
if rx.recv().is_err() { warn!("Error sending choices to client"); };
|
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];
|
index = jump_points[choice];
|
||||||
|
info!("CHOICE command with {} choices", jump_points.len());
|
||||||
debug!("{:?} {} {}",jump_points, choice, index);
|
debug!("{:?} {} {}",jump_points, choice, index);
|
||||||
continue 'parse_loop
|
continue 'parse_loop
|
||||||
},
|
},
|
||||||
"or" =>
|
"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
|
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