diff --git a/.cargo/config b/.cargo/config index c694936e59..c25fcc783b 100644 --- a/.cargo/config +++ b/.cargo/config @@ -14,6 +14,8 @@ rustflags = [ cmd-doc-gen = "run --features=bin_cmd_doc_gen --bin cmd_doc_gen" csv-export = "run --manifest-path common/Cargo.toml --features=bin_csv --bin csv_export" csv-import = "run --manifest-path common/Cargo.toml --features=bin_csv --bin csv_import" +dot-recipes = "run --manifest-path common/Cargo.toml --features=bin_graphviz --bin recipe_graphviz" +dot-skills = "run --manifest-path common/Cargo.toml --features=bin_graphviz --bin skill_graphviz" # server-cli server = "run --bin veloren-server-cli" test-server = "run --bin veloren-server-cli --no-default-features --features simd" diff --git a/common/Cargo.toml b/common/Cargo.toml index dc39d1e466..69e3c024c0 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -9,7 +9,7 @@ no-assets = [] hot-reloading = ["common-assets/hot-reloading"] simd = ["vek/platform_intrinsics"] bin_csv = ["ron", "csv", "structopt"] -bin_graphviz = ["petgraph"] +bin_graphviz = ["petgraph", "structopt"] bin_cmd_doc_gen = [] bin_asset_migrate = ["ron"] rrt_pathfinding = ["kiddo"] @@ -112,6 +112,10 @@ required-features = ["bin_asset_migrate"] name = "recipe_graphviz" required-features = ["bin_graphviz"] +[[bin]] +name = "skill_graphviz" +required-features = ["bin_graphviz"] + [[bin]] name = "cmd_doc_gen" required-features = ["bin_cmd_doc_gen"] diff --git a/common/src/bin/skill_graphviz.rs b/common/src/bin/skill_graphviz.rs new file mode 100644 index 0000000000..84f909f88a --- /dev/null +++ b/common/src/bin/skill_graphviz.rs @@ -0,0 +1,52 @@ +use hashbrown::HashMap; +use petgraph::{ + dot::{Config, Dot}, + Graph, +}; +use std::{fs::File, io::Write}; +use structopt::StructOpt; +use veloren_common::comp::{ + item::tool::ToolKind, + skillset::{skills::Skill, SkillGroupKind, SKILL_GROUP_DEFS, SKILL_PREREQUISITES}, +}; + +#[derive(StructOpt)] +struct Cli { + /// Available arguments: "sword" + skill_group: String, +} + +fn main() { + let args = Cli::from_args(); + let skill_group = match args.skill_group.as_str() { + "sword" => SkillGroupKind::Weapon(ToolKind::Sword), + _ => { + println!("Invalid argument, available arguments:\n\"sword\""); + return; + }, + }; + + let skills = SKILL_GROUP_DEFS + .get(&skill_group) + .map_or(Vec::new(), |def| def.skills.iter().collect::>()); + let mut graph = Graph::new(); + let mut nodes = HashMap::new(); + let mut add_node = |graph: &mut Graph<_, _>, node: Skill| { + *nodes.entry(node).or_insert_with(|| graph.add_node(node)) + }; + for skill in skills { + let prerequisites = SKILL_PREREQUISITES + .get(&skill) + .map_or(Vec::new(), |p| p.iter().collect::>()); + + let out_node = add_node(&mut graph, *skill); + for prerequisite in prerequisites.iter().map(|(s, _)| s) { + let in_node = add_node(&mut graph, **prerequisite); + graph.add_edge(in_node, out_node, ()); + } + } + // you can render the dot file as a png with `dot -Tpng recipe_graph.dot > + // recipe_graph.png` or interactively view it with `xdot recipe_graph.dot` + let mut f = File::create("skill_graph.dot").unwrap(); + write!(f, "{:?}", Dot::with_config(&graph, &[Config::EdgeNoLabel])).unwrap(); +} diff --git a/voxygen/src/hud/diary.rs b/voxygen/src/hud/diary.rs index e2d11d68a6..02b16974c8 100644 --- a/voxygen/src/hud/diary.rs +++ b/voxygen/src/hud/diary.rs @@ -80,24 +80,6 @@ widget_ids! { skills_bot_l[], skills_bot_r[], sword_render, - skill_sword_combo_0, - skill_sword_combo_1, - skill_sword_combo_2, - skill_sword_combo_3, - skill_sword_combo_4, - skill_sword_dash_0, - skill_sword_dash_1, - skill_sword_dash_2, - skill_sword_dash_3, - skill_sword_dash_4, - skill_sword_dash_5, - skill_sword_dash_6, - skill_sword_spin_0, - skill_sword_spin_1, - skill_sword_spin_2, - skill_sword_spin_3, - skill_sword_spin_4, - skill_sword_passive_0, axe_render, skill_axe_combo_0, skill_axe_combo_1,