Skip to content

Commit

Permalink
Added switch command to cli player to create and change between flows.
Browse files Browse the repository at this point in the history
  • Loading branch information
bladecoder committed Jun 26, 2024
1 parent 475312d commit 0c1abc5
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cli-player/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum Command {
Load(String),
Save(String),
DivertPath(String),
Flow(String),
}

struct EHandler {
Expand Down Expand Up @@ -121,6 +122,13 @@ fn process_command(command: Command, story: &mut Story) -> Result<bool, Box<dyn
save_json(&filename, &json_string)?;
println!("Ok.")
}
Command::Flow(flow) => {
let result = story.switch_flow(&flow);

if let Err(desc) = result {
println!("<error switching to '{flow}': {desc}>")
}
}
Command::DivertPath(path) => {
let result = story.choose_path_string(&path, true, None);

Expand All @@ -129,7 +137,7 @@ fn process_command(command: Command, story: &mut Story) -> Result<bool, Box<dyn
}
}
Command::Help() => println!(
"Commands:\n\tload <filename>\n\tsave <filename>\n\t-> <divert_path>\n\tquit\n\t"
"Commands:\n\tload <filename>\n\tsave <filename>\n\t-> <divert_path>\n\tswitch <flow_name>\n\tquit\n\t"
),
}

Expand Down Expand Up @@ -197,6 +205,14 @@ fn read_input(choices: &Vec<Rc<Choice>>) -> Result<Command, Box<dyn Error>> {
print_error("incorrect filename");
}

"switch" => {
if words.len() == 2 {
return Ok(Command::Flow(words[1].trim().to_string()));
}

print_error("incorrect flow name");
}

"->" => {
if words.len() == 2 {
return Ok(Command::DivertPath(words[1].trim().to_string()));
Expand Down

0 comments on commit 0c1abc5

Please sign in to comment.