2021-04-02 20:27:39 +00:00
|
|
|
use common::trade::Good;
|
|
|
|
use std::io::Write;
|
2022-06-01 19:09:31 +00:00
|
|
|
use veloren_world::site::economy::{GraphInfo, Labor};
|
2021-04-02 20:27:39 +00:00
|
|
|
//use regex::Regex::replace_all;
|
|
|
|
|
|
|
|
fn good_name(g: Good) -> String {
|
|
|
|
let res = format!("{:?}", g);
|
2021-12-21 20:19:23 +00:00
|
|
|
let res = res.replace('(', "_");
|
|
|
|
res.replace(')', "_")
|
2021-04-02 20:27:39 +00:00
|
|
|
}
|
|
|
|
|
2022-06-01 19:09:31 +00:00
|
|
|
fn labor_name(l: Labor) -> String {
|
2021-04-02 20:27:39 +00:00
|
|
|
let res = format!("{:?}", l);
|
2021-12-21 20:19:23 +00:00
|
|
|
res.replace(' ', "_")
|
2021-04-02 20:27:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> Result<(), std::io::Error> {
|
2022-06-01 19:09:31 +00:00
|
|
|
let eco = GraphInfo::default();
|
2021-04-02 20:27:39 +00:00
|
|
|
|
|
|
|
let mut f = std::fs::File::create("economy.gv")?;
|
|
|
|
writeln!(f, "digraph economy {{")?;
|
2022-06-01 19:09:31 +00:00
|
|
|
for i in eco.good_list() {
|
|
|
|
let color = if !eco.can_store(&i) {
|
2021-04-02 20:27:39 +00:00
|
|
|
"green"
|
|
|
|
} else {
|
|
|
|
"orange"
|
|
|
|
};
|
2021-06-20 16:00:37 +00:00
|
|
|
writeln!(f, "{:?} [color=\"{}\"];", good_name(i.into()), color)?; // shape doubleoctagon ?
|
2021-04-02 20:27:39 +00:00
|
|
|
}
|
|
|
|
|
2021-04-03 08:43:20 +00:00
|
|
|
writeln!(f)?;
|
2021-04-02 20:27:39 +00:00
|
|
|
writeln!(f, "// Professions")?;
|
|
|
|
writeln!(f, "Everyone [shape=doubleoctagon];")?;
|
2022-06-01 19:09:31 +00:00
|
|
|
for i in eco.labor_list() {
|
2021-04-02 20:27:39 +00:00
|
|
|
writeln!(f, "{:?} [shape=box];", labor_name(i))?;
|
|
|
|
}
|
|
|
|
|
2021-04-03 08:43:20 +00:00
|
|
|
writeln!(f)?;
|
2021-04-02 20:27:39 +00:00
|
|
|
writeln!(f, "// Orders")?;
|
2022-06-01 19:09:31 +00:00
|
|
|
let o = eco.get_orders();
|
2021-04-02 20:27:39 +00:00
|
|
|
for i in o.iter() {
|
|
|
|
for j in i.1.iter() {
|
2022-06-01 19:09:31 +00:00
|
|
|
let style = if matches!(j.0.into(), Good::Tools | Good::Armor | Good::Potions) {
|
|
|
|
", style=dashed, color=orange"
|
2021-04-02 20:27:39 +00:00
|
|
|
} else {
|
2022-06-01 19:09:31 +00:00
|
|
|
""
|
|
|
|
};
|
|
|
|
writeln!(
|
|
|
|
f,
|
|
|
|
"{:?} -> {:?} [label=\"{:.1}\"{}];",
|
|
|
|
good_name(j.0.into()),
|
|
|
|
labor_name(i.0),
|
|
|
|
j.1,
|
|
|
|
style
|
|
|
|
)?;
|
2021-04-02 20:27:39 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-07 19:29:06 +00:00
|
|
|
for j in eco.get_orders_everyone() {
|
2022-06-01 19:09:31 +00:00
|
|
|
writeln!(
|
|
|
|
f,
|
|
|
|
"{:?} -> Everyone [label=\"{:.1}\"];",
|
|
|
|
good_name(j.0.into()),
|
|
|
|
j.1
|
|
|
|
)?;
|
|
|
|
}
|
2021-04-02 20:27:39 +00:00
|
|
|
|
2021-04-03 08:43:20 +00:00
|
|
|
writeln!(f)?;
|
2021-04-02 20:27:39 +00:00
|
|
|
writeln!(f, "// Products")?;
|
2022-06-01 19:09:31 +00:00
|
|
|
let p = eco.get_production();
|
2021-04-02 20:27:39 +00:00
|
|
|
for i in p.iter() {
|
2021-06-20 16:00:37 +00:00
|
|
|
writeln!(
|
|
|
|
f,
|
|
|
|
"{:?} -> {:?} [label=\"{:.1}\"];",
|
|
|
|
labor_name(i.0),
|
|
|
|
good_name(i.1.0.into()),
|
|
|
|
i.1.1
|
|
|
|
)?;
|
2021-04-02 20:27:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
writeln!(f, "}}")?;
|
|
|
|
Ok(())
|
|
|
|
}
|