Skip to content

Commit

Permalink
Decouple dot output tool from dot and zathura commands (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrea-c committed Dec 14, 2023
1 parent 0540950 commit ab6484e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
31 changes: 0 additions & 31 deletions graph.dot

This file was deleted.

19 changes: 11 additions & 8 deletions src/bin/show_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@ use std::env;
fn main() {
let args: Vec<String> = env::args().collect();

if args.len() != 2 {
panic!("Usage: show_graph <PATH_TO_TARGET_GRAPH>");
if args.len() != 3 {
panic!("Usage: show_graph <ASSET_PATH_TO_TARGET_GRAPH> <PATH_TO_DOT_OUTPUT>");
}

App::new()
.add_plugins((
// TODO: Figure out the minimal set of plugins needed
// to make this work
DefaultPlugins,
// LogPlugin::default(),
// TimePlugin::default(),
// TaskPoolPlugin::default(),
// AssetPlugin::default(),
// GltfPlugin::default(),
AnimationGraphPlugin,
))
.insert_resource(TargetGraph {
name: args[1].clone(),
output_path: args[2].clone(),
handle: None,
})
.add_systems(Startup, load_graph)
Expand All @@ -33,6 +29,7 @@ fn main() {
#[derive(Resource)]
struct TargetGraph {
name: String,
output_path: String,
handle: Option<Handle<AnimationGraph>>,
}

Expand Down Expand Up @@ -62,7 +59,13 @@ fn show_graph(
animation_graph_assets: &animation_graph_assets,
};

graph.dot_to_tmp_file_and_open(None, context_tmp).unwrap();
if target_graph.output_path == "-" {
graph.dot_to_stdout(None, context_tmp).unwrap();
} else {
graph
.dot_to_file(&target_graph.output_path, None, context_tmp)
.unwrap();
}

exit.send(AppExit);
}
Expand Down
28 changes: 28 additions & 0 deletions src/core/animation_graph/dot_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,34 @@ pub trait ToDot {
Ok(())
}

fn dot_to_file(
&self,
path: &str,
context: Option<&mut GraphContext>,
context_tmp: GraphContextTmp,
) -> std::io::Result<()> {
{
let file = File::create(path)?;
let mut writer = BufWriter::new(file);
self.to_dot(&mut writer, context, context_tmp)?;
}

Ok(())
}

fn dot_to_stdout(
&self,
context: Option<&mut GraphContext>,
context_tmp: GraphContextTmp,
) -> std::io::Result<()> {
{
let mut stdout = std::io::stdout();
self.to_dot(&mut stdout, context, context_tmp)?;
}

Ok(())
}

fn dot_to_tmp_file(
&self,
context: Option<&mut GraphContext>,
Expand Down

0 comments on commit ab6484e

Please sign in to comment.