From bdbe6134f2cd1c559987caea61288646214bd33c Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 28 Mar 2021 23:48:51 -0400 Subject: [PATCH] Fixed csv tools --- common/src/bin/csv_export/main.rs | 14 +++++++------- common/src/bin/csv_import/main.rs | 7 ++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/common/src/bin/csv_export/main.rs b/common/src/bin/csv_export/main.rs index ea3696b607..6878a5a776 100644 --- a/common/src/bin/csv_export/main.rs +++ b/common/src/bin/csv_export/main.rs @@ -219,7 +219,7 @@ fn all_items() -> Result<(), Box> { fn loot_table(loot_table: &str) -> Result<(), Box> { let mut wtr = csv::Writer::from_path("loot_table.csv")?; - wtr.write_record(&["Kind", "Item", "Relative Chance"])?; + wtr.write_record(&["Relative Chance", "Kind", "Item", "Lower Amount", "Upper Amount"])?; let loot_table = "common.loot_tables.".to_owned() + loot_table; @@ -236,12 +236,12 @@ fn loot_table(loot_table: &str) -> Result<(), Box> { .div(10_f32.powi(5)) .to_string(); - let (kind, item) = match item { - LootSpec::Item(item) => ("Item", item), - LootSpec::LootTable(table) => ("LootTable", table), - }; - - wtr.write_record(&[kind, item, &chance])?; + match item { + LootSpec::Item(item) => wtr.write_record(&[&chance, "Item", item, "", ""])?, + LootSpec::ItemQuantity(item, lower, upper) => wtr.write_record(&[&chance, "Item", item, &lower.to_string(), &upper.to_string()])?, + LootSpec::LootTable(table) => wtr.write_record(&[&chance, "LootTable", table, "", ""])?, + LootSpec::CreatureMaterial => wtr.write_record(&[&chance, "CreatureMaterial", "", "", ""])?, + } } wtr.flush()?; diff --git a/common/src/bin/csv_import/main.rs b/common/src/bin/csv_import/main.rs index 14750b5062..255c9498ba 100644 --- a/common/src/bin/csv_import/main.rs +++ b/common/src/bin/csv_import/main.rs @@ -383,8 +383,13 @@ fn loot_table(loot_table: &str) -> Result<(), Box> { for record in rdr.records() { if let Ok(ref record) = record { let item = match record.get(headers["Kind"]).expect("No loot specifier") { - "Item" => LootSpec::Item(record.get(headers["Item"]).expect("No item").to_string()), + "Item" => if let (Some(Ok(lower)), Some(Ok(upper))) = (record.get(headers["Lower Amount"]).map(|a| a.parse()), record.get(headers["Upper Amount"]).map(|a| a.parse())) { + LootSpec::ItemQuantity(record.get(headers["Item"]).expect("No item").to_string(), lower, upper) + } else { + LootSpec::Item(record.get(headers["Item"]).expect("No item").to_string()) + }, "LootTable" => LootSpec::LootTable(record.get(headers["Item"]).expect("No loot table").to_string()), + "CreatureMaterial" => LootSpec::CreatureMaterial, _ => panic!("Loot specifier kind must be either \"Item\" or \"LootTable\""), }; let chance: f32 = record