fixed a bug with single word strings and multiple choice blocks side by side

This commit is contained in:
2026-05-18 23:05:19 +01:00
parent cba3ec04d7
commit 019f1088a3
10 changed files with 37 additions and 17 deletions
+1
View File
@@ -3,3 +3,4 @@
.venv
.~*
report.odt
examples/
+2
View File
@@ -48,6 +48,8 @@ def output(character, text):
# Get user from the backend
def get_character(character):
if character.lower() == "narrator":
return {"name": "narrator"}
api_url = f"http://localhost:20264/character/{character}"
return requests.get(api_url).json()
+8 -7
View File
@@ -1,12 +1,13 @@
# Character features
# Characters
## Character features
| Feature | Examples | Notes |
| --------------- | --------------------------------------------- | ----------------------------------------- |
| Name | Timothy Sharpshooter | |
| Gender | Male, Female, NB, Other | |
| Skin Color | Khaki, #F0E68C, rgb(240, 230, 140) | CSS Color |
| Eye Color | LightBlue, #ADD8E6, rgb(173, 216, 230) | CSS Color |
| Hair Color | GoldenRod, #DAA520, rgb(218, 165, 32) | CSS Color |
| Skin Color | [255,255,255] | RGB colour |
| Eye Color | [14,0,244] | RGB Color |
| Hair Color | [0,128,44] | RGB Color |
| Pronoun Subject | He, She, They | See https://en.wikipedia.org/wiki/Pronoun |
| Pronoun Object | Him, Her, Them | See https://en.wikipedia.org/wiki/Pronoun |
| Pronoun Deppos | His, Her, Their | See https://en.wikipedia.org/wiki/Pronoun |
@@ -17,12 +18,12 @@
| Arm Shape | | |
| Leg Shape | | |
| Hair Style | | |
| Clothing | See [Character Clothing](#Character Clothing) | |
| Clothing | See [Character Clothing](##Clothing) | |
> [!NOTE]
> Pronouns can be implied and unrequired with a recognised Gender value, however, custom values can be filled in if desired.
# Character Clothing
## Clothing
| Appearal | Examples | Notes |
| -------- | -------- | ------------------------ |
@@ -33,7 +34,7 @@
| Gloves | | |
| Neck | | Necklace, Scarf, etc... |
# Characters.json
## Characters.json
Characters are stored in the characters.json file which looks like this:
+1 -1
View File
@@ -126,7 +126,7 @@ pub fn modify_data
choices: Vec<String>,
)
{
let mut data = data_to_send.lock().unwrap_or_exit("Data to send Mutex was poisoned",2); // TODO eh?
let mut data = data_to_send.lock().unwrap_or_exit("Data to send Mutex was poisoned",2);
data.id += 1;
data.action_type = action_type;
data.content = content;
+1 -1
View File
@@ -74,7 +74,7 @@ async fn main()
{
id: 0,
action_type: "begin".to_owned(),
content: String::new(),
content: String::new(), // TODO send title and description
character: String::new(),
choices: vec![],
}));
+4 -6
View File
@@ -65,6 +65,7 @@ pub fn token_parse(
increment
},
};
if rx.recv().is_err() { warn!("Some issue with api"); }
continue 'parse_loop
}
Some(_) =>
@@ -129,20 +130,17 @@ pub fn token_parse(
index += 1;
}
}
if rx.recv().is_err()
{
warn!("Some issue with api");
}
if rx.recv().is_err() { warn!("Some issue with api"); }
}
}
fn choice_parse(tokens: &[tokenise::Token], mut index: usize, data_to_send: &Arc<Mutex<api::DataToSend>>,)
-> Result<Vec<usize>, String>
{
let mut next_token: String = "choice".to_string();
let mut next_token: String = "or".to_string();
let mut choices: Vec<String> = Vec::new();
let mut choice_indeces: Vec<usize> = Vec::new();
while next_token == "or" || next_token == "choice"
while next_token == "or"
{
index += 1;
choices.push
+6
View File
@@ -27,6 +27,12 @@ pub fn character_parse
) -> Result<usize,(String,usize)>
{
let mut sum_index: usize = index;
let characters_hashmap = characters.lock().unwrap_or_exit("Characters Mutex was poisoned",2);
if character_name.to_lowercase() != "narrator" && ! characters_hashmap.contains_key(&character_name)
{
return Err((format!("Character {character_name} does not exist"),sum_index + 1));
}
drop(characters_hashmap);
// Ensure the index is valid (the index is not beyond the vector)
let keyword = tokenise::get_keyword_token(tokens, sum_index)
.map_err(|err| (err, sum_index))?;
+10 -2
View File
@@ -91,7 +91,6 @@ pub fn tokenise(file_contents: &str)
tokenised_data.len(),
);
}
// On a new indentation level, do a recursive call
else if item == "{"
{
bracket_stack.push(tokenised_data.len());
@@ -115,7 +114,16 @@ fn tokenise_string(space_seperated: &[&str], mut index: usize)
-> Option<(usize, String)>
{
let mut string = String::new();
let mut chars = space_seperated[index].chars();
let first_word = space_seperated[index];
if first_word.ends_with('"') // One word string edge case
{
let mut chars = first_word.chars();
chars.next();
chars.next_back();
string += chars.as_str();
return Some((index,string));
}
let mut chars = first_word.chars();
chars.next();
string += chars.as_str();
for item in &space_seperated[index+1..]
+4
View File
@@ -0,0 +1,4 @@
{
"title": "Once upon a Test",
"description": "This story is for testing purposes"
}
BIN
View File
Binary file not shown.