mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'sam/wiki-all-entities' into 'master'
Csv export entity drops tool now has ability to export all entities at once. See merge request veloren/veloren!2910
This commit is contained in:
@ -8,7 +8,7 @@ use std::{
|
||||
use structopt::StructOpt;
|
||||
|
||||
use veloren_common::{
|
||||
assets::AssetExt,
|
||||
assets::{self, AssetExt},
|
||||
comp::{
|
||||
self,
|
||||
item::{
|
||||
@ -278,11 +278,13 @@ 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(&["Percent Chance", "Item Path", "Quantity"])?;
|
||||
wtr.write_record(&["Entity Path", "Percent Chance", "Item Path", "Quantity"])?;
|
||||
|
||||
let entity_config = "common.entity.".to_owned() + entity_config;
|
||||
|
||||
let entity_config = EntityConfig::load_expect(&entity_config).read();
|
||||
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();
|
||||
|
||||
// Create initial entry in drop table
|
||||
let entry: (f32, LootSpec<String>) = (1.0, entity_config.loot.clone());
|
||||
@ -359,7 +361,8 @@ fn entity_drops(entity_config: &str) -> Result<(), Box<dyn Error>> {
|
||||
let (item_asset, quantity) = match item {
|
||||
LootSpec::Item(item) => (Some(item), "1".to_string()),
|
||||
LootSpec::ItemQuantity(item, lower, upper) => {
|
||||
(Some(item), format!("{}-{}", lower, upper))
|
||||
// Tab needed so excel doesn't think it is a date...
|
||||
(Some(item), format!("{}-{}\t", lower, upper))
|
||||
},
|
||||
LootSpec::LootTable(_) => panic!("Shouldn't exist"),
|
||||
LootSpec::Nothing => (None, "-".to_string()),
|
||||
@ -373,7 +376,22 @@ fn entity_drops(entity_config: &str) -> Result<(), Box<dyn Error>> {
|
||||
"Nothing"
|
||||
};
|
||||
|
||||
wtr.write_record(&[&percent_chance, item_name, &quantity])?
|
||||
wtr.write_record(&[asset_path, &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 {
|
||||
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()?;
|
||||
@ -405,7 +423,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)
|
||||
|
Reference in New Issue
Block a user