Skip to content

Commit

Permalink
Added automatic index opening
Browse files Browse the repository at this point in the history
  • Loading branch information
TCA166 committed Jun 29, 2024
1 parent 97c5e27 commit a6c2957
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ tidy-tree = "0.1.0"
atty = "0.2.14"
serde_json = "1.0.118"
dialoguer = "0.11.0"
open = "5.1.4"
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fn create_dir_maybe(name: &str) {
/// 7. `--no-vis` - A flag that tells the program not to render any images
/// 8. `--output` - A flag that tells the program where to output the rendered files.
/// 9. `--include` - A flag that tells the program where to find additional files to include in the rendering.
/// 10. `--no-interaction` - A flag that tells the program not to interact with the user.
///
/// # Process
///
Expand Down Expand Up @@ -95,6 +96,7 @@ fn main() {
let use_internal = false;
// if we don't want to render any images
let mut no_vis = false;
let mut no_interaction = false;
// The output path, if provided by the user
let mut output_path: Option<String> = None;
// The game path and mod paths, if provided by the user
Expand Down Expand Up @@ -283,6 +285,9 @@ fn main() {
"--dump" => {
dump = true;
}
"--no-interaction" => {
no_interaction = true;
}
_ => {
println!("Unknown argument: {}", arg);
}
Expand Down Expand Up @@ -494,12 +499,15 @@ fn main() {
while let Some(obj) = queue.pop() {
obj.render_all(&mut queue, &mut renderer);
}
if atty::is(atty::Stream::Stdin) && atty::is(atty::Stream::Stdout) && !no_interaction {
open::that(format!("{}/index.html", folder_name)).unwrap();
}
}
if dump {
let json = serde_json::to_string_pretty(&game_state).unwrap();
fs::write("game_state.json", json).unwrap();
}
if atty::is(atty::Stream::Stdin) && atty::is(atty::Stream::Stdout) {
if atty::is(atty::Stream::Stdin) && atty::is(atty::Stream::Stdout) && !no_interaction {
print!("Press enter to exit...");
stdout().flush().unwrap();
let mut inp = String::new();
Expand Down
14 changes: 9 additions & 5 deletions src/structures/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,15 @@ impl Renderable for Player {
char.get_character()
.get_internal()
.render_all(stack, renderer);
let grapher = renderer.get_grapher();
if grapher.is_some() {
let last = self.lineage.last().unwrap().get_character();
grapher.unwrap().create_tree_graph::<Character>(last, true, &format!("{}/line.svg", renderer.get_path()));
}
let grapher = renderer.get_grapher();
if grapher.is_some() {
let last = self.lineage.last().unwrap().get_character();
grapher.unwrap().create_tree_graph::<Character>(
last,
true,
&format!("{}/line.svg", renderer.get_path()),
);
}
}
}
}
Expand Down

0 comments on commit a6c2957

Please sign in to comment.