Fixed errors in csv import, csv export, and recipe graphviz bins

This commit is contained in:
Sam 2022-05-07 11:35:00 -04:00
parent 1c626da66b
commit de8f98446e
4 changed files with 38 additions and 36 deletions

View File

@ -13,7 +13,7 @@ use veloren_common::{
self, self,
item::{ item::{
armor::{ArmorKind, Protection}, armor::{ArmorKind, Protection},
tool::{Hands, HandsKind, MaterialStatManifest, Tool, ToolKind}, tool::{Hands, Tool, ToolKind},
Item, ItemKind, Item, ItemKind,
}, },
}, },
@ -49,7 +49,7 @@ fn armor_stats() -> Result<(), Box<dyn Error>> {
for item in comp::item::Item::new_from_asset_glob("common.items.armor.*") for item in comp::item::Item::new_from_asset_glob("common.items.armor.*")
.expect("Failed to iterate over item folders!") .expect("Failed to iterate over item folders!")
{ {
match item.kind() { match &*item.kind() {
comp::item::ItemKind::Armor(armor) => { comp::item::ItemKind::Armor(armor) => {
let kind = get_armor_kind(&armor.kind); let kind = get_armor_kind(&armor.kind);
if kind == "Bag" { if kind == "Bag" {
@ -72,7 +72,7 @@ fn armor_stats() -> Result<(), Box<dyn Error>> {
let stealth = armor.stealth().unwrap_or(0.0).to_string(); let stealth = armor.stealth().unwrap_or(0.0).to_string();
wtr.write_record(&[ wtr.write_record(&[
item.item_definition_id(), item.item_definition_id().raw().expect("All items from asset glob should be simple items"),
&kind, &kind,
&item.name(), &item.name(),
&format!("{:?}", item.quality()), &format!("{:?}", item.quality()),
@ -112,28 +112,26 @@ fn weapon_stats() -> Result<(), Box<dyn Error>> {
"Description", "Description",
])?; ])?;
let msm = MaterialStatManifest::default();
// Does all items even outside weapon folder since we check if itemkind was a // Does all items even outside weapon folder since we check if itemkind was a
// tool anyways // tool anyways
let items: Vec<comp::Item> = comp::Item::new_from_asset_glob("common.items.*") let items: Vec<comp::Item> = comp::Item::new_from_asset_glob("common.items.*")
.expect("Failed to iterate over item folders!"); .expect("Failed to iterate over item folders!");
for item in items.iter() { for item in items.iter() {
if let comp::item::ItemKind::Tool(tool) = item.kind() { if let comp::item::ItemKind::Tool(tool) = &*item.kind() {
let power = tool.base_power(&msm, &[]).to_string(); let power = tool.base_power().to_string();
let effect_power = tool.base_effect_power(&msm, &[]).to_string(); let effect_power = tool.base_effect_power().to_string();
let speed = tool.base_speed(&msm, &[]).to_string(); let speed = tool.base_speed().to_string();
let crit_chance = tool.base_crit_chance(&msm, &[]).to_string(); let crit_chance = tool.base_crit_chance().to_string();
let range = tool.base_range(&msm, &[]).to_string(); let range = tool.base_range().to_string();
let energy_efficiency = tool.base_energy_efficiency(&msm, &[]).to_string(); let energy_efficiency = tool.base_energy_efficiency().to_string();
let buff_strength = tool.base_buff_strength(&msm, &[]).to_string(); let buff_strength = tool.base_buff_strength().to_string();
let equip_time = tool.equip_time(&msm, &[]).as_secs_f32().to_string(); let equip_time = tool.equip_time().as_secs_f32().to_string();
let kind = get_tool_kind(&tool.kind); let kind = get_tool_kind(&tool.kind);
let hands = get_tool_hands(tool); let hands = get_tool_hands(tool);
wtr.write_record(&[ wtr.write_record(&[
item.item_definition_id(), item.item_definition_id().raw().expect("All items from asset glob should be simple items"),
&kind, &kind,
&item.name(), &item.name(),
&hands, &hands,
@ -223,13 +221,13 @@ fn all_items() -> Result<(), Box<dyn Error>> {
for item in comp::item::Item::new_from_asset_glob("common.items.*") for item in comp::item::Item::new_from_asset_glob("common.items.*")
.expect("Failed to iterate over item folders!") .expect("Failed to iterate over item folders!")
{ {
let kind = match item.kind() { let kind = match &*item.kind() {
ItemKind::Armor(armor) => get_armor_kind_kind(&armor.kind), ItemKind::Armor(armor) => get_armor_kind_kind(&armor.kind),
ItemKind::Lantern(lantern) => lantern.kind.clone(), ItemKind::Lantern(lantern) => lantern.kind.clone(),
_ => "".to_owned(), _ => "".to_owned(),
}; };
wtr.write_record(&[item.item_definition_id(), &item.name(), &kind])?; wtr.write_record(&[item.item_definition_id().raw().expect("All items in asset glob should be simple items"), &item.name(), &kind])?;
} }
wtr.flush()?; wtr.flush()?;
@ -395,6 +393,10 @@ fn entity_drops(entity_config: &str) -> Result<(), Box<dyn Error>> {
// Tab needed so excel doesn't think it is a date... // Tab needed so excel doesn't think it is a date...
(Some(item), format!("{}-{}\t", lower, upper)) (Some(item), format!("{}-{}\t", lower, upper))
}, },
LootSpec::ModularWeapon { .. } => {
// TODO: Figure out how modular weapons should work here
(None, String::from("1"))
},
LootSpec::LootTable(_) => panic!("Shouldn't exist"), LootSpec::LootTable(_) => panic!("Shouldn't exist"),
LootSpec::Nothing => (None, "-".to_string()), LootSpec::Nothing => (None, "-".to_string()),
}; };
@ -402,9 +404,9 @@ fn entity_drops(entity_config: &str) -> Result<(), Box<dyn Error>> {
let item = item_asset.map(|asset| Item::new_from_asset_expect(asset)); let item = item_asset.map(|asset| Item::new_from_asset_expect(asset));
let item_name = if let Some(item) = &item { let item_name = if let Some(item) = &item {
item.name() item.name().into_owned()
} else { } else {
"Nothing" String::from("Nothing")
}; };
wtr.write_record(&[ wtr.write_record(&[

View File

@ -14,7 +14,7 @@ use veloren_common::{
item::{ item::{
armor::{ArmorKind, Protection}, armor::{ArmorKind, Protection},
tool::{AbilitySpec, Hands, Stats, ToolKind}, tool::{AbilitySpec, Hands, Stats, ToolKind},
ItemDesc, ItemKind, ItemTag, Material, Quality, ItemKind, ItemTag, Material, Quality, ItemDefinitionId,
}, },
}, },
lottery::LootSpec, lottery::LootSpec,
@ -71,7 +71,7 @@ fn armor_stats() -> Result<(), Box<dyn Error>> {
for item in comp::item::Item::new_from_asset_glob("common.items.armor.*") for item in comp::item::Item::new_from_asset_glob("common.items.armor.*")
.expect("Failed to iterate over item folders!") .expect("Failed to iterate over item folders!")
{ {
match item.kind() { match &*item.kind() {
comp::item::ItemKind::Armor(armor) => { comp::item::ItemKind::Armor(armor) => {
if let ArmorKind::Bag(_) = armor.kind { if let ArmorKind::Bag(_) = armor.kind {
continue; continue;
@ -79,7 +79,7 @@ fn armor_stats() -> Result<(), Box<dyn Error>> {
if let Ok(ref record) = record { if let Ok(ref record) = record {
if item.item_definition_id() if item.item_definition_id()
== record.get(headers["Path"]).expect("No file path in csv?") == ItemDefinitionId::Simple(record.get(headers["Path"]).expect("No file path in csv?"))
{ {
let protection = let protection =
if let Some(protection_raw) = record.get(headers["Protection"]) { if let Some(protection_raw) = record.get(headers["Protection"]) {
@ -222,7 +222,7 @@ fn armor_stats() -> Result<(), Box<dyn Error>> {
ItemKind::Armor(armor), ItemKind::Armor(armor),
quality, quality,
item.tags().to_vec(), item.tags().to_vec(),
item.ability_spec.clone(), item.ability_spec().map(|spec| spec.into_owned()),
); );
let pretty_config = PrettyConfig::new() let pretty_config = PrettyConfig::new()
@ -232,7 +232,7 @@ fn armor_stats() -> Result<(), Box<dyn Error>> {
.enumerate_arrays(true); .enumerate_arrays(true);
let mut path = ASSETS_PATH.clone(); let mut path = ASSETS_PATH.clone();
for part in item.item_definition_id().split('.') { for part in item.item_definition_id().raw().expect("Csv import only works on simple items, not modular items").split('.') {
path.push(part); path.push(part);
} }
path.set_extension("ron"); path.set_extension("ron");
@ -273,10 +273,10 @@ fn weapon_stats() -> Result<(), Box<dyn Error>> {
.expect("Failed to iterate over item folders!"); .expect("Failed to iterate over item folders!");
for item in items.iter() { for item in items.iter() {
if let comp::item::ItemKind::Tool(tool) = item.kind() { if let comp::item::ItemKind::Tool(tool) = &*item.kind() {
if let Ok(ref record) = record { if let Ok(ref record) = record {
if item.item_definition_id() if item.item_definition_id()
== record.get(headers["Path"]).expect("No file path in csv?") == ItemDefinitionId::Simple(record.get(headers["Path"]).expect("No file path in csv?"))
{ {
let kind = tool.kind; let kind = tool.kind;
let equip_time_secs: f32 = record let equip_time_secs: f32 = record
@ -414,7 +414,7 @@ fn weapon_stats() -> Result<(), Box<dyn Error>> {
ItemKind::Tool(tool), ItemKind::Tool(tool),
quality, quality,
item.tags().to_vec(), item.tags().to_vec(),
item.ability_spec.clone(), item.ability_spec().map(|spec| spec.into_owned()),
); );
let pretty_config = PrettyConfig::new() let pretty_config = PrettyConfig::new()
@ -424,7 +424,7 @@ fn weapon_stats() -> Result<(), Box<dyn Error>> {
.enumerate_arrays(true); .enumerate_arrays(true);
let mut path = ASSETS_PATH.clone(); let mut path = ASSETS_PATH.clone();
for part in item.item_definition_id().split('.') { for part in item.item_definition_id().raw().expect("Csv import only works on simple items, not modular items").split('.') {
path.push(part); path.push(part);
} }
path.set_extension("ron"); path.set_extension("ron");
@ -513,10 +513,9 @@ fn loot_table(loot_table: &str) -> Result<(), Box<dyn Error>> {
tool: get_tool_kind(record.get(headers["Item"]).expect("No tool").to_string()) tool: get_tool_kind(record.get(headers["Item"]).expect("No tool").to_string())
.expect("Invalid tool kind"), .expect("Invalid tool kind"),
material: Material::from_str( material: Material::from_str(
&record record
.get(headers["Lower Amount or Material"]) .get(headers["Lower Amount or Material"])
.expect("No material") .expect("No material"),
.to_string(),
) )
.expect("Invalid material type"), .expect("Invalid material type"),
hands: get_tool_hands( hands: get_tool_hands(

View File

@ -20,20 +20,20 @@ fn main() {
.or_insert_with(|| graph.add_node(node.to_owned())) .or_insert_with(|| graph.add_node(node.to_owned()))
}; };
for (_, recipe) in recipes.iter() { for (_, recipe) in recipes.iter() {
let output = recipe.output.0.item_definition_id(); let output = String::from(recipe.output.0.item_definition_id().raw().expect("Recipe book can only create simple items (probably)"));
let inputs = recipe let inputs = recipe
.inputs .inputs
.iter() .iter()
.map(|(i, _)| i) .map(|(i, _, _)| i)
.filter_map(|input| { .filter_map(|input| {
if let RecipeInput::Item(item) = input { if let RecipeInput::Item(item) = input {
Some(item.item_definition_id()) item.item_definition_id().raw().map(String::from)
} else { } else {
None None
} }
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let out_node = add_node(&mut graph, output); let out_node = add_node(&mut graph, &output);
for input in inputs.iter() { for input in inputs.iter() {
let in_node = add_node(&mut graph, input); let in_node = add_node(&mut graph, input);
graph.add_edge(in_node, out_node, ()); graph.add_edge(in_node, out_node, ());

View File

@ -1,7 +1,8 @@
use super::*; use super::*;
use crate::comp::{ use crate::comp::{
inventory::{slot::ArmorSlot, test_helpers::get_test_bag}, inventory::{slot::ArmorSlot, test_helpers::get_test_bag},
Item, item::ItemDefinitionId, item::ItemDefinitionId,
Item,
}; };
use lazy_static::lazy_static; use lazy_static::lazy_static;
lazy_static! { lazy_static! {