Merge branch 'swilliams/entity-drops-csv-names' into 'master'

Changed entity drops csv export to export names instead of asset paths

See merge request veloren/veloren!3161
This commit is contained in:
Marcel 2022-01-29 17:37:45 +00:00
commit 3120a64be2

View File

@ -17,10 +17,12 @@ use veloren_common::{
Item, ItemKind,
},
},
generation::EntityConfig,
generation::{EntityConfig, EntityInfo},
lottery::{LootSpec, Lottery},
};
use vek::Vec3;
#[derive(StructOpt)]
struct Cli {
/// Available arguments: "armor-stats", "weapon-stats", "all-items",
@ -281,13 +283,22 @@ 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")?;
wtr.write_record(&["Entity Path", "Percent Chance", "Item Path", "Quantity"])?;
wtr.write_record(&[
"Entity Name",
"Entity Path",
"Percent Chance",
"Item Path",
"Quantity",
])?;
fn write_entity_loot<W: std::io::Write>(
wtr: &mut csv::Writer<W>,
asset_path: &str,
) -> Result<(), Box<dyn Error>> {
let entity_config = EntityConfig::load_expect(asset_path).read();
let entity_info = EntityInfo::at(Vec3::new(0.0, 0.0, 0.0))
.with_asset_expect(asset_path, &mut rand::thread_rng());
let name = entity_info.name.unwrap_or_else(|| "".to_string());
// Create initial entry in drop table
let entry: (f32, LootSpec<String>) = (1.0, entity_config.loot.clone());
@ -379,7 +390,13 @@ fn entity_drops(entity_config: &str) -> Result<(), Box<dyn Error>> {
"Nothing"
};
wtr.write_record(&[asset_path, &percent_chance, item_name, &quantity])?
wtr.write_record(&[
name.clone(),
asset_path.to_string(),
percent_chance,
item_name.to_string(),
quantity,
])?
}
Ok(())