Csv export entity drops tool now has ability to export all entities at once.

This commit is contained in:
Sam
2021-10-07 20:28:18 -04:00
parent 84b563a7b6
commit 53c9dfcd92

View File

@ -8,7 +8,7 @@ use std::{
use structopt::StructOpt;
use veloren_common::{
assets::AssetExt,
assets::{self, AssetExt},
comp::{
self,
item::{
@ -278,11 +278,14 @@ fn loot_table(loot_table: &str) -> Result<(), Box<dyn Error>> {
fn entity_drops(entity_config: &str) -> Result<(), Box<dyn Error>> {
let mut wtr = csv::Writer::from_path("drop_table.csv")?;
fn write_entity_loot<W: std::io::Write>(
wtr: &mut csv::Writer<W>,
asset_path: &str,
) -> Result<(), Box<dyn Error>> {
wtr.write_record(&["Percent Chance", "Item Path", "Quantity"])?;
let entity_config = "common.entity.".to_owned() + entity_config;
let entity_config = EntityConfig::load_expect(&entity_config).read();
let entity_config = EntityConfig::load_expect(&asset_path).read();
// Create initial entry in drop table
let entry: (f32, LootSpec<String>) = (1.0, entity_config.loot.clone());
@ -376,6 +379,22 @@ fn entity_drops(entity_config: &str) -> Result<(), Box<dyn Error>> {
wtr.write_record(&[&percent_chance, item_name, &quantity])?
}
Ok(())
}
if entity_config.eq_ignore_ascii_case("all") {
let configs = assets::load_dir::<EntityConfig>("common.entity", true)
.expect("Entity files moved somewhere else maybe?")
.ids();
for config in configs {
wtr.write_record(&[config, "", ""])?;
write_entity_loot(&mut wtr, config)?;
}
} else {
let entity_config = "common.entity.".to_owned() + entity_config;
write_entity_loot(&mut wtr, &entity_config)?;
}
wtr.flush()?;
Ok(())
}
@ -405,7 +424,8 @@ fn main() {
} else if args.function.eq_ignore_ascii_case("entity-drops") {
let entity_config = get_input(
"Specify the name of the entity to export loot drops to csv. Assumes entity config is \
in directory: assets.common.entity.\n",
in directory: assets.common.entity.\nCan also use \"all\" to export loot from all \
entity configs.\n",
);
if let Err(e) = entity_drops(&entity_config) {
println!("Error: {}\n", e)