added CHANGE command

This commit is contained in:
2026-05-14 21:24:28 +01:00
parent a55053dc97
commit a18928c673
11 changed files with 82 additions and 11 deletions
+29 -3
View File
@@ -165,7 +165,7 @@ fn character_parse
// Ensure the index is valid (the index is not beyond the vector)
let token = tokens
.get(sum_index)
.ok_or_else(|| "File reached termination point".to_string())?;
.ok_or_else(|| "File unexpectedly reached termination point".to_string())?;
match token.to_lowercase().as_str()
{
// The character is saying something, so grab the text and pass it
@@ -173,7 +173,7 @@ fn character_parse
"says" =>
{
info!("SAYS command with character {character_name}");
match strings::extract_quoted(&tokens[sum_index+1..]) // TODO increment to after the string
match strings::extract_quoted(&tokens[sum_index+1..])
{
Some((output_string, counter)) =>
{
@@ -185,9 +185,35 @@ fn character_parse
data.character = character_name;
data.choices = vec![];
},
None => return Err(String::from("Unable to read string")),
None => return Err("Unable to read output string".to_string()),
}
},
// 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
"change" =>
{
sum_index += 1;
let feature = tokens
.get(sum_index)
.ok_or_else(|| "File unexpectedly reached termination point".to_string())?;
let output_string: String;
(output_string, sum_index) = match strings::extract_quoted(&tokens[sum_index+1..])
{
Some((string,counter)) => (string,sum_index+counter),
None => return Err("Unable to parse property to change character".to_string()),
};
info!("CHANGE command with character {character_name} feature {feature}");
let mut characters = characters.lock().expect("Data cannot be unlocked");
if let Some(character) = characters.get_mut(&character_name)
{
if character.set_field(feature, &output_string)
.is_err() { warn!("Feature {feature} does not exist") };
}
let mut data = data_to_send.lock().unwrap();
data.action_type = String::from("change");
data.content = String::new();
data.character = character_name;
},
// Catch all condition, if the instruction is unrecognised as a
// character command
_ => return Err(format!("Invalid command: {token}")),