mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Bin program to generate dot files for skill trees
This commit is contained in:
parent
eacbdefb75
commit
2116842d30
@ -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"
|
||||
|
@ -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"]
|
||||
|
52
common/src/bin/skill_graphviz.rs
Normal file
52
common/src/bin/skill_graphviz.rs
Normal file
@ -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::<Vec<_>>());
|
||||
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::<Vec<_>>());
|
||||
|
||||
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();
|
||||
}
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user