mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fixed csv tools
This commit is contained in:
@ -219,7 +219,7 @@ fn all_items() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
fn loot_table(loot_table: &str) -> Result<(), Box<dyn Error>> {
|
fn loot_table(loot_table: &str) -> Result<(), Box<dyn Error>> {
|
||||||
let mut wtr = csv::Writer::from_path("loot_table.csv")?;
|
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;
|
let loot_table = "common.loot_tables.".to_owned() + loot_table;
|
||||||
|
|
||||||
@ -236,12 +236,12 @@ fn loot_table(loot_table: &str) -> Result<(), Box<dyn Error>> {
|
|||||||
.div(10_f32.powi(5))
|
.div(10_f32.powi(5))
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
let (kind, item) = match item {
|
match item {
|
||||||
LootSpec::Item(item) => ("Item", item),
|
LootSpec::Item(item) => wtr.write_record(&[&chance, "Item", item, "", ""])?,
|
||||||
LootSpec::LootTable(table) => ("LootTable", table),
|
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.write_record(&[kind, item, &chance])?;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wtr.flush()?;
|
wtr.flush()?;
|
||||||
|
@ -383,8 +383,13 @@ fn loot_table(loot_table: &str) -> Result<(), Box<dyn Error>> {
|
|||||||
for record in rdr.records() {
|
for record in rdr.records() {
|
||||||
if let Ok(ref record) = record {
|
if let Ok(ref record) = record {
|
||||||
let item = match record.get(headers["Kind"]).expect("No loot specifier") {
|
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()),
|
"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\""),
|
_ => panic!("Loot specifier kind must be either \"Item\" or \"LootTable\""),
|
||||||
};
|
};
|
||||||
let chance: f32 = record
|
let chance: f32 = record
|
||||||
|
Reference in New Issue
Block a user