diff --git a/.gitignore b/.gitignore index 0ddede8..2f7e3c4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ .venv .~* report.odt +examples/ diff --git a/client/main.py b/client/main.py index 7927be3..086c7bc 100644 --- a/client/main.py +++ b/client/main.py @@ -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() diff --git a/docs/CHARACTERS.md b/docs/CHARACTERS.md index 25d4c15..2363695 100644 --- a/docs/CHARACTERS.md +++ b/docs/CHARACTERS.md @@ -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: diff --git a/server/src/api.rs b/server/src/api.rs index 40398ec..aef52fb 100644 --- a/server/src/api.rs +++ b/server/src/api.rs @@ -126,7 +126,7 @@ pub fn modify_data choices: Vec, ) { - 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; diff --git a/server/src/main.rs b/server/src/main.rs index 32ff07b..cd51982 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -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![], })); diff --git a/server/src/parsing.rs b/server/src/parsing.rs index d8e3793..2b11547 100644 --- a/server/src/parsing.rs +++ b/server/src/parsing.rs @@ -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>,) -> Result, String> { - let mut next_token: String = "choice".to_string(); + let mut next_token: String = "or".to_string(); let mut choices: Vec = Vec::new(); let mut choice_indeces: Vec = Vec::new(); - while next_token == "or" || next_token == "choice" + while next_token == "or" { index += 1; choices.push diff --git a/server/src/parsing/character_parse.rs b/server/src/parsing/character_parse.rs index e80142a..0d760d3 100644 --- a/server/src/parsing/character_parse.rs +++ b/server/src/parsing/character_parse.rs @@ -27,6 +27,12 @@ pub fn character_parse ) -> Result { 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))?; diff --git a/server/src/tokenise.rs b/server/src/tokenise.rs index f2f05f8..e70fadc 100644 --- a/server/src/tokenise.rs +++ b/server/src/tokenise.rs @@ -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..] diff --git a/stories/about.json b/stories/about.json new file mode 100644 index 0000000..65f3ce7 --- /dev/null +++ b/stories/about.json @@ -0,0 +1,4 @@ +{ + "title": "Once upon a Test", + "description": "This story is for testing purposes" +} diff --git a/stories/test.zip b/stories/test.zip index 3e1fc1f..089a22d 100644 Binary files a/stories/test.zip and b/stories/test.zip differ