started implementing server side choice mechanics
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
|||||||
,deadvey,linux-pc,30.04.2026 12:49,file:///home/deadvey/.config/libreoffice/4;
|
,deadvey,linux-pc,03.05.2026 02:13,file:///home/deadvey/.config/libreoffice/4;
|
||||||
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
+40
-6
@@ -12,6 +12,7 @@ use crate::
|
|||||||
Mutex,
|
Mutex,
|
||||||
info,
|
info,
|
||||||
debug,
|
debug,
|
||||||
|
warn,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -19,7 +20,7 @@ use crate::
|
|||||||
// Returns success or an error string
|
// Returns success or an error string
|
||||||
pub async fn token_parse(
|
pub async fn token_parse(
|
||||||
tokens: &Vec<&str>,
|
tokens: &Vec<&str>,
|
||||||
mut characters: Arc<Mutex<HashMap::<String, character::Character>>>,
|
characters: Arc<Mutex<HashMap::<String, character::Character>>>,
|
||||||
data_to_send: Arc<Mutex<api::DataToSend>>,
|
data_to_send: Arc<Mutex<api::DataToSend>>,
|
||||||
rx: &Receiver<u8>,
|
rx: &Receiver<u8>,
|
||||||
) -> Result<(),String>
|
) -> Result<(),String>
|
||||||
@@ -44,7 +45,7 @@ pub async fn token_parse(
|
|||||||
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);
|
info!("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, &rx).await
|
index += match character_parse(index+1, &tokens, character_name, &characters, &data_to_send).await
|
||||||
{
|
{
|
||||||
Ok(increment) => increment,
|
Ok(increment) => increment,
|
||||||
Err(error) => return Err(error),
|
Err(error) => return Err(error),
|
||||||
@@ -52,14 +53,48 @@ pub async fn token_parse(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Miscelleneous instructions
|
// Miscelleneous instructions
|
||||||
if token.to_lowercase() == "end"
|
match token.to_lowercase().as_str()
|
||||||
{
|
{
|
||||||
info!("END command, exiting");
|
"end" =>
|
||||||
return Ok(()) // quit
|
{
|
||||||
|
info!("END command, exiting");
|
||||||
|
return Ok(()) // quit
|
||||||
|
},
|
||||||
|
"choice" =>
|
||||||
|
{
|
||||||
|
index += match choice_parse(index+1, &tokens).await
|
||||||
|
{
|
||||||
|
Ok(increment) => increment,
|
||||||
|
Err(error) => return Err(error),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ =>
|
||||||
|
{
|
||||||
|
warn!("Invalid command: {}", token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
index += 1;
|
index += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO underdev
|
||||||
|
async fn choice_parse
|
||||||
|
(
|
||||||
|
index: usize,
|
||||||
|
tokens: &Vec<&str>,
|
||||||
|
) -> Result<usize, String>
|
||||||
|
{
|
||||||
|
let mut sum_index: usize = index;
|
||||||
|
let mut choices: Vec<String> = Vec::new();
|
||||||
|
// Ensure the index is valid (the index is not beyond the vector)
|
||||||
|
let (choice_string, counter) = strings::extract_quoted(&tokens[sum_index..])
|
||||||
|
.ok_or_else(|| "No choice string".to_string())?;
|
||||||
|
sum_index += counter;
|
||||||
|
choices.append(choice_string);
|
||||||
|
sum_index += strings::closing_char(&tokens[sum_index..], '{','}').unwrap(); //TODO eh
|
||||||
|
Ok(sum_index + 1)
|
||||||
|
}
|
||||||
|
|
||||||
// Parsing character related instructions
|
// Parsing character related instructions
|
||||||
async fn character_parse
|
async fn character_parse
|
||||||
(
|
(
|
||||||
@@ -68,7 +103,6 @@ async fn character_parse
|
|||||||
character_name: String,
|
character_name: String,
|
||||||
characters: &Arc<Mutex<HashMap::<String, character::Character>>>,
|
characters: &Arc<Mutex<HashMap::<String, character::Character>>>,
|
||||||
data_to_send: &Arc<Mutex<api::DataToSend>>,
|
data_to_send: &Arc<Mutex<api::DataToSend>>,
|
||||||
rx: &Receiver<u8>,
|
|
||||||
) -> Result<usize,String>
|
) -> Result<usize,String>
|
||||||
{
|
{
|
||||||
let mut sum_index: usize = index;
|
let mut sum_index: usize = index;
|
||||||
|
|||||||
+15
-1
@@ -1,4 +1,18 @@
|
|||||||
pub fn extract_quoted(parts: &[&str]) -> Option<(String, usize)> {
|
pub fn closing_char(parts: &[&str], open: char, close: char)
|
||||||
|
-> Result<usize,()>
|
||||||
|
{
|
||||||
|
let mut indentation: usize = 0;
|
||||||
|
for (index, part) in parts.into_iter().enumerate()
|
||||||
|
{
|
||||||
|
if part.contains(open) { indentation += 1; }
|
||||||
|
if part.contains(close) { indentation -= 1; }
|
||||||
|
if indentation == 0 { return Ok(index); }
|
||||||
|
}
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
pub fn extract_quoted(parts: &[&str])
|
||||||
|
-> Option<(String, usize)>
|
||||||
|
{
|
||||||
let mut vec_string = Vec::new();
|
let mut vec_string = Vec::new();
|
||||||
let mut counter: usize = 0;
|
let mut counter: usize = 0;
|
||||||
for part in parts
|
for part in parts
|
||||||
|
|||||||
@@ -1,2 +1,8 @@
|
|||||||
@tim says "hello world, it's a good day"
|
@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
|
END
|
||||||
|
|||||||
Reference in New Issue
Block a user