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