Skip to content

Commit

Permalink
Merge pull request #46 from hiddenpeopleclub/skip-command
Browse files Browse the repository at this point in the history
Skip command
  • Loading branch information
loomstyla authored Oct 5, 2023
2 parents 0ed80be + 007399b commit d709e10
Show file tree
Hide file tree
Showing 6 changed files with 525 additions and 62 deletions.
91 changes: 89 additions & 2 deletions cli/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ impl Console {
fn run_command(command: &str, parameters: Vec<&str>, runtime: &mut Runtime) -> String {
match command {
"" => progress_story(runtime),
"next" | "n" => next_block(runtime),
"sections" => sections_command(parameters, runtime),
"?" => state_command(parameters, runtime),
"variables" => variables_command(parameters, runtime),
"set" => set_command(parameters, runtime),
"->" => divert(parameters, runtime),
"<->" => boomerang_divert(parameters, runtime),
"skip" | "s" => skip(runtime),
"skip-all" => skip_all(runtime),
"reset" => reset_command(parameters, runtime),
str => {
if str.starts_with("->") {
Expand Down Expand Up @@ -150,10 +153,12 @@ fn get_output_string(output: Output, runtime: &Runtime) -> String {
for block in output.blocks {
let block_output = get_block_string(block, runtime);
if !block_output.is_empty() {
output_string += &block_output;
output_string = output_string + &block_output + "\n";
}
}

output_string = output_string.trim_end().to_string();

let choices_string = get_choices_string(output.choices);
if !choices_string.is_empty() {
output_string += &format!("\n{}", choices_string);
Expand Down Expand Up @@ -195,6 +200,8 @@ fn get_block_string(block: Block, runtime: &Runtime) -> String {
}
_ => block_string,
}
.trim_end()
.to_string()
}

fn get_change_string(chance: &Chance) -> String {
Expand Down Expand Up @@ -255,6 +262,13 @@ fn progress_story(runtime: &mut Runtime) -> String {
}
}

fn next_block(runtime: &mut Runtime) -> String {
match runtime.next_block() {
Ok(output) => get_output_string(output, runtime),
Err(error) => get_runtime_error_string(error, runtime),
}
}

fn grep(pattern: &str, source: &str) -> String {
let mut final_string = String::default();

Expand Down Expand Up @@ -389,6 +403,34 @@ fn set_command(parameters: Vec<&str>, runtime: &mut Runtime) -> String {
}
}

fn skip(runtime: &mut Runtime) -> String {
match runtime.skip() {
Ok(output) => {
let mut output_string = output.text;
let choices_string = get_choices_string(output.choices);
if !choices_string.is_empty() {
output_string += &format!("\n{}", choices_string);
}
output_string
}
Err(error) => get_runtime_error_string(error, runtime),
}
}

fn skip_all(runtime: &mut Runtime) -> String {
match runtime.skip_all() {
Ok(output) => {
let mut output_string = output.text;
let choices_string = get_choices_string(output.choices);
if !choices_string.is_empty() {
output_string += &format!("\n{}", choices_string);
}
output_string
}
Err(error) => get_runtime_error_string(error, runtime),
}
}

fn boomerang_divert(parameters: Vec<&str>, runtime: &mut Runtime) -> String {
if parameters.is_empty() {
return "Provide a section".to_string();
Expand Down Expand Up @@ -512,7 +554,11 @@ mod test {
let str_found = Console::process_line(Ok("".to_string()), &mut rl, &mut runtime).unwrap();
assert_eq!(expected_str, &str_found);

let str_found = runtime.current().unwrap().text;
runtime.reset_all();
runtime.database.config.story_progress_style = StoryProgressStyle::Skip;

let expected_str = "You've just arrived in the bustling city, full of excitement and anticipation for your new job.\nThe skyline reaches for the clouds, and the sounds of traffic and people surround you.\nAs you take your first steps in this urban jungle, you feel a mix of emotions, hoping to find your place in this new environment.\n (1)I take a walk through a nearby park to relax and acclimate to the city.\n (2)I visit a popular street market to experience the city's unique flavors and energy.\n";
let str_found = Console::process_line(Ok("".to_string()), &mut rl, &mut runtime).unwrap();
assert_eq!(expected_str, &str_found);
}

Expand Down Expand Up @@ -690,4 +736,45 @@ mod test {
let stack_found = runtime.block_stack.clone();
assert_eq!(expected_stack, stack_found);
}

#[test]
fn skip_command() {
let mut runtime = Console::load_runtime("./fixtures/script");
let mut rl = DefaultEditor::new().unwrap();

let expected_str = "You've just arrived in the bustling city, full of excitement and anticipation for your new job.\nThe skyline reaches for the clouds, and the sounds of traffic and people surround you.\nAs you take your first steps in this urban jungle, you feel a mix of emotions, hoping to find your place in this new environment.\n (1)I take a walk through a nearby park to relax and acclimate to the city.\n (2)I visit a popular street market to experience the city's unique flavors and energy.\n";
let str_found = Console::process_line(Ok("skip".to_string()), &mut rl, &mut runtime).unwrap();
assert_eq!(expected_str, &str_found);

runtime.reset_all();

let str_found = Console::process_line(Ok("s".to_string()), &mut rl, &mut runtime).unwrap();
assert_eq!(expected_str, &str_found);
}

#[test]
fn skip_all_command() {
let mut runtime = Console::load_runtime("./fixtures/script");
let mut rl = DefaultEditor::new().unwrap();

let expected_str = "As you take your first steps in this urban jungle, you feel a mix of emotions, hoping to find your place in this new environment.\n (1)I take a walk through a nearby park to relax and acclimate to the city.\n (2)I visit a popular street market to experience the city's unique flavors and energy.\n";
let str_found =
Console::process_line(Ok("skip-all".to_string()), &mut rl, &mut runtime).unwrap();
assert_eq!(expected_str, &str_found);
}

#[test]
fn next_command() {
let mut runtime = Console::load_runtime("./fixtures/script");
let mut rl = DefaultEditor::new().unwrap();

let expected_str = "You've just arrived in the bustling city, full of excitement and anticipation for your new job.";
let str_found = Console::process_line(Ok("n".to_string()), &mut rl, &mut runtime).unwrap();
assert_eq!(expected_str, &str_found);

runtime.reset_all();

let str_found = Console::process_line(Ok("next".to_string()), &mut rl, &mut runtime).unwrap();
assert_eq!(expected_str, &str_found);
}
}
9 changes: 9 additions & 0 deletions common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ pub struct Config {
pub variables: HashMap<String, VariableKind>,
pub locales: Vec<String>,
pub default_locale: String,
#[serde(default)]
pub story_progress_style: StoryProgressStyle,
}
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone, Eq)]
#[serde(rename_all = "lowercase")]
pub enum StoryProgressStyle {
#[default]
Next,
Skip,
}

impl Config {
Expand Down
93 changes: 54 additions & 39 deletions compiler/en.csv
Original file line number Diff line number Diff line change
@@ -1,51 +1,66 @@
Id,Text
61,I call my parents
64,"The phone rings twice, and dad picks up. You have a good chat."
4,I take a walk through a nearby park to relax and acclimate to the city.
28,The musician smiles and nods thanking you.
67,"The phone rings twice, and mom picks up. You have a good chat."
27,I leave two dollars to the artist.
32,I grab my phone and take pictures of the murals.
2,"The skyline reaches for the clouds, and the sounds of traffic and people surround you."
30,"Wandering the market, you stumble upon a hidden alley adorned with vibrant street art."
115,"You buy an apple and take a bite. Hmm, delicious."
10,"At the bustling street market, you discover a food stand offering mouthwa tering delicacies."
40,The moonlight gives the room a peaceful tone.
74,You decide it's now time to go to sleep.
18,"You spot a visibly agitated vendor, their clenched fists and piercing glare making it clear that they're unhappy with the current situation unfolding before them."
83,Go to the Farmer's Market
116,Buy an orange
38,The sun shines bright through the window.
81,Explore a museum
5,"As you stroll through the nearby park, the soothing sounds of rustling leaves and chirping birds help calm your senses."
8,This serene oasis gives you the confidence to face the challenges ahead as you acclimate to your new life in the bustling city.
13,"You notice the stand owner, their eyes sparkling with joy as they animatedly describe their homemade offerings to an eager customer."
47,You decide to focus on the now...
117,"You buy an orange and take a bite. Hmm, refreshing."
22,"The vendor at a nearby food stand appears worn, their movements slow and deliberate, as they attempt to maintain a smile while attending to the seemingly endless stream of customers."
56,I go to bed
29,"I nod when the musician looks my way, to show I really enjoy the music."
113,You stop by a fruit stand that sells apples and oranges.
49,I make some tea
72,"The phone rings ten times, nobody is at home."
24,"As you try to navigate the crowded market, you're drawn to the entrancing melody of a street musician."
44,That makes you feel overwhelmed.
101,You learn something new today and return home with a smile on your face.
62,I call my parents
9,I visit a popular street market to experience the city's unique flavors and energy.
57,"Feeling depleted of spoons, you go right back to bed."
87,"You enter the museum, it is crowded but the exhibitions look amazing."
68,"The phone rings twice, and mom picks up. You have a good chat."
4,I take a walk through a nearby park to relax and acclimate to the city.
23,You feel they're too busy to bother them with questions.
91,Where should I go?
26,"You take a moment to appreciate the beauty of the music, feeling a connection to the artist and the vibrant energy they bring to the urban landscape."
14,"You see the owner beaming with joy, their infectious smile and animated gestures inviting customers to try their delectable creations."
17,"You come across a vendor with furrowed brows and a tense expression, their voice raised as they heatedly argue with a customer over a transaction at their stand."
7,"A solitary figure sits on the bench, engrossed in a book, seemingly unfazed by the surrounding city noise."
34,"This unexpected oasis of visual tranquility provides a respite from the chaos of the city, inspiring you to explore more of the urban canvas and the stories it holds."
29,"I nod when the musician looks my way, to show I really enjoy the music."
30,"Wandering the market, you stumble upon a hidden alley adorned with vibrant street art."
100,Go home.
105,You get to the farmer's market. It's very early and some stands are still being set up.
33,"I keep walking, even if the murals look good, the darkness of the alley is unsettling."
13,"You notice the stand owner, their eyes sparkling with joy as they animatedly describe their homemade offerings to an eager customer."
37,"As you enter the peaceful sanctuary of your room, you take a deep breath, relieved to have a quiet space where you can recharge and prepare for the challenges ahead."
5,"As you stroll through the nearby park, the soothing sounds of rustling leaves and chirping birds help calm your senses."
27,I leave two dollars to the artist.
2,"The skyline reaches for the clouds, and the sounds of traffic and people surround you."
7,"A solitary figure sits on the bench, engrossed in a book, seemingly unfazed by the surrounding city noise."
107,The fruit looks very appetizing and you feel like trying some.
1,"You've just arrived in the bustling city, full of excitement and anticipation for your new job."
92,Go to the dinosaur section.
6,"You find a quiet bench to sit on, taking a moment to breathe deeply and gather your thoughts."
28,The musician smiles and nods thanking you.
36,"Feeling mentally and physically exhausted from the day's adventures, you decide it's time to head back to your hotel."
42,You start to think about all the stuff you need to do tomorrow.
71,"The phone rings ten times, nobody is at home."
33,"I keep walking, even if the murals look good, the darkness of the alley is unsettling."
10,"At the bustling street market, you discover a food stand offering mouthwa tering delicacies."
80,Explore a museum
18,"You spot a visibly agitated vendor, their clenched fists and piercing glare making it clear that they're unhappy with the current situation unfolding before them."
6,"You find a quiet bench to sit on, taking a moment to breathe deeply and gather your thoughts."
1,"You've just arrived in the bustling city, full of excitement and anticipation for your new job."
40,The moonlight gives the room a peaceful tone.
49,I make some tea
44,That makes you feel overwhelmed.
57,"Feeling depleted of spoons, you go right back to bed."
73,You decide it's now time to go to sleep.
38,The sun shines bright through the window.
82,Go to the Farmer's Market
86,You get to the museum door. You watch through the window. It seems crowded.
89,You get to the farmer's market. It's very early and some stands are still being set up.
21,"You observe a vendor at a small food stand, their shoulders slumped and eyes slightly glazed as they quietly serve customers, mustering just enough energy to complete each transaction."
24,"As you try to navigate the crowded market, you're drawn to the entrancing melody of a street musician."
3,"As you take your first steps in this urban jungle, you feel a mix of emotions, hoping to find your place in this new environment."
31,"Each colorful mural tells a different story, capturing your imagination and sparking your creativity."
98,You admire the paintings.
32,I grab my phone and take pictures of the murals.
65,"The phone rings twice, and dad picks up. You have a good chat."
17,"You come across a vendor with furrowed brows and a tense expression, their voice raised as they heatedly argue with a customer over a transaction at their stand."
21,"You observe a vendor at a small food stand, their shoulders slumped and eyes slightly glazed as they quietly serve customers, mustering just enough energy to complete each transaction."
109,You feel satisfied with the fruit you bought and return home with a smile on your face.
25,"The captivating sound creates a soothing bubble, momentarily transporting you away from the city's noise."
51,A good cup of tea is always good to regulate after the sensory overload of the city.
96,Go to the art section.
34,"This unexpected oasis of visual tranquility provides a respite from the chaos of the city, inspiring you to explore more of the urban canvas and the stories it holds."
14,"You see the owner beaming with joy, their infectious smile and animated gestures inviting customers to try their delectable creations."
94,The Tyrannosaurus Rex is scary up close.
106,You take a stroll while patiently waiting for the market to finish setting up.
3,"As you take your first steps in this urban jungle, you feel a mix of emotions, hoping to find your place in this new environment."
80,You wake up feeling refreshed. Let's see what this day brings.
114,Buy an apple
52,You sit in the couch to enjoy your tea. Drink half of the cup and fall asleep.
47,You decide to focus on the now...
79,You wake up feeling refreshed. Let's see what this day brings.
25,"The captivating sound creates a soothing bubble, momentarily transporting you away from the city's noise."
56,I go to bed
1 change: 1 addition & 0 deletions examples/cuentitos.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
locales = ['en']
default_locale = 'en'
story_progress_style = 'next'

[variables]
energy = "integer"
Expand Down
1 change: 1 addition & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod runtime;
pub use runtime::*;

pub use cuentitos_common::Database;
pub use cuentitos_common::StoryProgressStyle;

mod game_state;
pub use cuentitos_common::Section;
Expand Down
Loading

0 comments on commit d709e10

Please sign in to comment.