diff --git a/.cargo/config b/.cargo/config index f588f639ff..09fa64d2ea 100644 --- a/.cargo/config +++ b/.cargo/config @@ -4,7 +4,8 @@ rustflags = [ ] [alias] -generate = "run --package tools --" +csv-export = "run --manifest-path common/Cargo.toml --features=bin_csv --bin csv_export" +csv-import = "run --manifest-path common/Cargo.toml --features=bin_csv --bin csv_import" test-server = "-Zpackage-features run --bin veloren-server-cli --no-default-features -- -b" tracy-server = "-Zunstable-options -Zpackage-features run --bin veloren-server-cli --no-default-features --features tracy,simd --profile no_overflow" test-voxygen = "-Zpackage-features run --bin veloren-voxygen --no-default-features --features gl,simd" diff --git a/common/src/bin/csv_export/main.rs b/common/src/bin/csv_export/main.rs index 5025ee2811..88137b4718 100644 --- a/common/src/bin/csv_export/main.rs +++ b/common/src/bin/csv_export/main.rs @@ -71,6 +71,7 @@ fn weapon_stats() -> Result<(), Box> { "Path", "Kind", "Name", + "Hands", "Quality", "Power", "Poise Strength", @@ -89,11 +90,13 @@ fn weapon_stats() -> Result<(), Box> { let speed = tool.base_speed().to_string(); let equip_time = tool.equip_time().subsec_millis().to_string(); let kind = get_tool_kind(&tool.kind); + let hands = get_tool_hands(&tool); wtr.write_record(&[ item.item_definition_id(), &kind, item.name(), + &hands, &format!("{:?}", item.quality()), &power, &poise_strength, @@ -127,6 +130,13 @@ fn get_tool_kind(kind: &ToolKind) -> String { } } +fn get_tool_hands(tool: &Tool) -> String { + match tool.hands { + Hands::OneHand => "OneHand".to_string(), + Hands::TwoHand => "TwoHand".to_string(), + } +} + fn get_armor_kind(kind: &ArmorKind) -> String { match kind { ArmorKind::Shoulder(_) => "Shoulder".to_string(), diff --git a/common/src/bin/csv_import/main.rs b/common/src/bin/csv_import/main.rs index c3f2f3707b..6e403316fb 100644 --- a/common/src/bin/csv_import/main.rs +++ b/common/src/bin/csv_import/main.rs @@ -171,7 +171,7 @@ fn weapon_stats() -> Result<(), Box> { { let kind = tool.kind; let equip_time_millis: u32 = record - .get(7) + .get(8) .expect(&format!( "Error unwrapping equip time for {:?}", item.item_definition_id() @@ -179,7 +179,7 @@ fn weapon_stats() -> Result<(), Box> { .parse() .expect(&format!("Not a u32? {:?}", item.item_definition_id())); let power: f32 = record - .get(4) + .get(5) .expect(&format!( "Error unwrapping power for {:?}", item.item_definition_id() @@ -187,7 +187,7 @@ fn weapon_stats() -> Result<(), Box> { .parse() .expect(&format!("Not a f32? {:?}", item.item_definition_id())); let poise_strength: f32 = record - .get(5) + .get(6) .expect(&format!( "Error unwrapping poise power for {:?}", item.item_definition_id() @@ -196,7 +196,7 @@ fn weapon_stats() -> Result<(), Box> { .expect(&format!("Not a f32? {:?}", item.item_definition_id())); let speed: f32 = record - .get(6) + .get(7) .expect(&format!( "Error unwrapping speed for {:?}", item.item_definition_id() @@ -204,15 +204,40 @@ fn weapon_stats() -> Result<(), Box> { .parse() .expect(&format!("Not a f32? {:?}", item.item_definition_id())); + let hands = if let Some(hands_raw) = record.get(3) { + match hands_raw { + "OneHand" | "One" | "1" | "1h" => { + comp::item::tool::Hands::OneHand + }, + "TwoHand" | "Two" | "2" | "2h" => { + comp::item::tool::Hands::TwoHand + }, + _ => { + eprintln!( + "Unknown hand variant for {:?}", + item.item_definition_id() + ); + comp::item::tool::Hands::TwoHand + }, + } + } else { + eprintln!( + "Could not unwrap hand for {:?}", + item.item_definition_id() + ); + comp::item::tool::Hands::TwoHand + }; + let tool = comp::item::tool::Tool::new( kind, + hands, equip_time_millis, power, poise_strength, speed, ); - let quality = if let Some(quality_raw) = record.get(3) { + let quality = if let Some(quality_raw) = record.get(4) { match quality_raw { "Low" => comp::item::Quality::Low, "Common" => comp::item::Quality::Common, @@ -238,7 +263,7 @@ fn weapon_stats() -> Result<(), Box> { comp::item::Quality::Debug }; - let description = record.get(8).expect(&format!( + let description = record.get(9).expect(&format!( "Error unwrapping description for {:?}", item.item_definition_id() )); diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index f0588cf938..dfd0413a08 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -99,7 +99,7 @@ impl ItemTag { } } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub enum ItemKind { /// Something wieldable Tool(tool::Tool), diff --git a/common/src/comp/inventory/item/tool.rs b/common/src/comp/inventory/item/tool.rs index 1a9512b454..e402453d9a 100644 --- a/common/src/comp/inventory/item/tool.rs +++ b/common/src/comp/inventory/item/tool.rs @@ -27,31 +27,13 @@ pub enum ToolKind { Empty, } -impl ToolKind { - pub fn hands(&self) -> Hands { - match self { - ToolKind::Sword => Hands::TwoHand, - ToolKind::Axe => Hands::TwoHand, - ToolKind::Hammer => Hands::TwoHand, - ToolKind::Bow => Hands::TwoHand, - ToolKind::Dagger => Hands::OneHand, - ToolKind::Staff => Hands::TwoHand, - ToolKind::Sceptre => Hands::TwoHand, - ToolKind::Shield => Hands::OneHand, - ToolKind::Unique(_) => Hands::TwoHand, - ToolKind::Debug => Hands::TwoHand, - ToolKind::Farming => Hands::TwoHand, - ToolKind::Empty => Hands::OneHand, - } - } -} - +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] pub enum Hands { OneHand, TwoHand, } -#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, Serialize, Deserialize)] pub struct Stats { equip_time_millis: u32, power: f32, @@ -59,9 +41,10 @@ pub struct Stats { speed: f32, } -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct Tool { pub kind: ToolKind, + pub hands: Hands, pub stats: Stats, // TODO: item specific abilities } @@ -71,6 +54,7 @@ impl Tool { // Added for CSV import of stats pub fn new( kind: ToolKind, + hands: Hands, equip_time_millis: u32, power: f32, poise_strength: f32, @@ -78,6 +62,7 @@ impl Tool { ) -> Self { Self { kind, + hands, stats: Stats { equip_time_millis, power, @@ -90,6 +75,7 @@ impl Tool { pub fn empty() -> Self { Self { kind: ToolKind::Empty, + hands: Hands::OneHand, stats: Stats { equip_time_millis: 0, power: 1.00, diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 3c467a1039..0f3c8c5592 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -424,28 +424,25 @@ pub fn handle_ability1_input(data: &JoinData, update: &mut StateUpdate) { pub fn handle_ability2_input(data: &JoinData, update: &mut StateUpdate) { if data.inputs.secondary.is_pressed() { - let active_tool_kind = match data + let active_tool_hands = match data .inventory .equipped(EquipSlot::Mainhand) .map(|i| i.kind()) { - Some(ItemKind::Tool(Tool { kind, .. })) => Some(kind), + Some(ItemKind::Tool(tool)) => Some(tool.hands), _ => None, }; - let second_tool_kind = match data + let second_tool_hands = match data .inventory .equipped(EquipSlot::Offhand) .map(|i| i.kind()) { - Some(ItemKind::Tool(Tool { kind, .. })) => Some(kind), + Some(ItemKind::Tool(tool)) => Some(tool.hands), _ => None, }; - match ( - active_tool_kind.map(|tk| tk.hands()), - second_tool_kind.map(|tk| tk.hands()), - ) { + match (active_tool_hands, second_tool_hands) { (Some(Hands::TwoHand), _) => { if let Some(ability) = data .inventory diff --git a/voxygen/anim/src/character/idle.rs b/voxygen/anim/src/character/idle.rs index e4394dac97..5bccb863bc 100644 --- a/voxygen/anim/src/character/idle.rs +++ b/voxygen/anim/src/character/idle.rs @@ -8,7 +8,13 @@ use std::{f32::consts::PI, ops::Mul}; pub struct IdleAnimation; impl Animation for IdleAnimation { - type Dependency = (Option, Option, f64); + #[allow(clippy::type_complexity)] + type Dependency = ( + Option, + Option, + (Option, Option), + f64, + ); type Skeleton = CharacterSkeleton; #[cfg(feature = "use-dyn-lib")] @@ -17,7 +23,7 @@ impl Animation for IdleAnimation { #[cfg_attr(feature = "be-dyn-lib", export_name = "character_idle")] fn update_skeleton_inner( skeleton: &Self::Skeleton, - (active_tool_kind, second_tool_kind, global_time): Self::Dependency, + (active_tool_kind, second_tool_kind, hands, global_time): Self::Dependency, anim_time: f64, _rate: &mut f32, s_a: &SkeletonAttr, @@ -137,10 +143,7 @@ impl Animation for IdleAnimation { next.torso.position = Vec3::new(0.0, 0.0, 0.0) * s_a.scaler; - next.second.scale = match ( - active_tool_kind.map(|tk| tk.hands()), - second_tool_kind.map(|tk| tk.hands()), - ) { + next.second.scale = match hands { (Some(Hands::OneHand), Some(Hands::OneHand)) => Vec3::one(), (_, _) => Vec3::zero(), }; diff --git a/voxygen/anim/src/character/jump.rs b/voxygen/anim/src/character/jump.rs index 27db8b89b4..c947138521 100644 --- a/voxygen/anim/src/character/jump.rs +++ b/voxygen/anim/src/character/jump.rs @@ -7,9 +7,11 @@ use std::f32::consts::PI; pub struct JumpAnimation; impl Animation for JumpAnimation { + #[allow(clippy::type_complexity)] type Dependency = ( Option, Option, + (Option, Option), Vec3, Vec3, f64, @@ -23,7 +25,7 @@ impl Animation for JumpAnimation { fn update_skeleton_inner( skeleton: &Self::Skeleton, - (active_tool_kind, second_tool_kind, orientation, last_ori, global_time): Self::Dependency, + (active_tool_kind, second_tool_kind, hands, orientation, last_ori, global_time): Self::Dependency, anim_time: f64, _rate: &mut f32, s_a: &SkeletonAttr, @@ -179,10 +181,7 @@ impl Animation for JumpAnimation { next.torso.orientation = Quaternion::rotation_x(-0.2); next.torso.scale = Vec3::one() / 11.0 * s_a.scaler; - next.second.scale = match ( - active_tool_kind.map(|tk| tk.hands()), - second_tool_kind.map(|tk| tk.hands()), - ) { + next.second.scale = match hands { (Some(Hands::OneHand), Some(Hands::OneHand)) => Vec3::one(), (_, _) => Vec3::zero(), }; diff --git a/voxygen/anim/src/character/run.rs b/voxygen/anim/src/character/run.rs index 685e1f2061..886738bf95 100644 --- a/voxygen/anim/src/character/run.rs +++ b/voxygen/anim/src/character/run.rs @@ -10,6 +10,7 @@ pub struct RunAnimation; type RunAnimationDependency = ( Option, Option, + (Option, Option), Vec3, Vec3, Vec3, @@ -32,6 +33,7 @@ impl Animation for RunAnimation { ( active_tool_kind, second_tool_kind, + hands, velocity, orientation, last_ori, @@ -263,10 +265,7 @@ impl Animation for RunAnimation { next.torso.position = Vec3::new(0.0, 0.0, 0.0) * s_a.scaler; next.torso.scale = Vec3::one() / 11.0 * s_a.scaler; - next.second.scale = match ( - active_tool_kind.map(|tk| tk.hands()), - second_tool_kind.map(|tk| tk.hands()), - ) { + next.second.scale = match hands { (Some(Hands::OneHand), Some(Hands::OneHand)) => Vec3::one(), (_, _) => Vec3::zero(), }; diff --git a/voxygen/anim/src/character/stand.rs b/voxygen/anim/src/character/stand.rs index b9cb4be619..c9eba1140e 100644 --- a/voxygen/anim/src/character/stand.rs +++ b/voxygen/anim/src/character/stand.rs @@ -8,7 +8,14 @@ use std::{f32::consts::PI, ops::Mul}; pub struct StandAnimation; impl Animation for StandAnimation { - type Dependency = (Option, Option, f64, Vec3); + #[allow(clippy::type_complexity)] + type Dependency = ( + Option, + Option, + (Option, Option), + f64, + Vec3, + ); type Skeleton = CharacterSkeleton; #[cfg(feature = "use-dyn-lib")] @@ -17,7 +24,7 @@ impl Animation for StandAnimation { #[cfg_attr(feature = "be-dyn-lib", export_name = "character_stand")] fn update_skeleton_inner( skeleton: &Self::Skeleton, - (active_tool_kind, second_tool_kind, global_time, avg_vel): Self::Dependency, + (active_tool_kind, second_tool_kind, hands, global_time, avg_vel): Self::Dependency, anim_time: f64, _rate: &mut f32, s_a: &SkeletonAttr, @@ -143,10 +150,7 @@ impl Animation for StandAnimation { next.torso.position = Vec3::new(0.0, 0.0, 0.0) * s_a.scaler; - next.second.scale = match ( - active_tool_kind.map(|tk| tk.hands()), - second_tool_kind.map(|tk| tk.hands()), - ) { + next.second.scale = match hands { (Some(Hands::OneHand), Some(Hands::OneHand)) => Vec3::one(), (_, _) => Vec3::zero(), }; diff --git a/voxygen/anim/src/character/swim.rs b/voxygen/anim/src/character/swim.rs index ebb6f3d29a..d3c5f4780d 100644 --- a/voxygen/anim/src/character/swim.rs +++ b/voxygen/anim/src/character/swim.rs @@ -10,6 +10,7 @@ pub struct SwimAnimation; type SwimAnimationDependency = ( Option, Option, + (Option, Option), Vec3, Vec3, Vec3, @@ -28,7 +29,16 @@ impl Animation for SwimAnimation { fn update_skeleton_inner( skeleton: &Self::Skeleton, - (active_tool_kind, second_tool_kind, velocity, orientation, last_ori, global_time, avg_vel): Self::Dependency, + ( + active_tool_kind, + second_tool_kind, + hands, + velocity, + orientation, + last_ori, + global_time, + avg_vel, + ): Self::Dependency, anim_time: f64, rate: &mut f32, s_a: &SkeletonAttr, @@ -223,10 +233,7 @@ impl Animation for SwimAnimation { * Quaternion::rotation_z(tilt * 8.0); next.torso.scale = Vec3::one() / 11.0 * s_a.scaler; - next.second.scale = match ( - active_tool_kind.map(|tk| tk.hands()), - second_tool_kind.map(|tk| tk.hands()), - ) { + next.second.scale = match hands { (Some(Hands::OneHand), Some(Hands::OneHand)) => Vec3::one(), (_, _) => Vec3::zero(), }; diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index 5f607689d5..c89a359feb 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -587,10 +587,7 @@ impl<'a> Widget for Skillbar<'a> { let active_tool = get_tool(self.inventory, EquipSlot::Mainhand); let second_tool = get_tool(self.inventory, EquipSlot::Offhand); - let tool = match ( - active_tool.map(|x| x.kind.hands()), - second_tool.map(|x| x.kind.hands()), - ) { + let tool = match (active_tool.map(|x| x.hands), second_tool.map(|x| x.hands)) { (Some(Hands::TwoHand), _) => active_tool, (_, Some(Hands::OneHand)) => second_tool, (_, _) => None, diff --git a/voxygen/src/scene/figure/mod.rs b/voxygen/src/scene/figure/mod.rs index 40e6fa1c6e..f1717bd619 100644 --- a/voxygen/src/scene/figure/mod.rs +++ b/voxygen/src/scene/figure/mod.rs @@ -689,21 +689,25 @@ impl FigureMgr { let active_item_kind = inventory .and_then(|i| i.equipped(EquipSlot::Mainhand)) .map(|i| i.kind()); - let active_tool_kind = if let Some(ItemKind::Tool(tool)) = active_item_kind { - Some(tool.kind) - } else { - None - }; + let (active_tool_kind, active_tool_hand) = + if let Some(ItemKind::Tool(tool)) = active_item_kind { + (Some(tool.kind), Some(tool.hands)) + } else { + (None, None) + }; let second_item_kind = inventory .and_then(|i| i.equipped(EquipSlot::Offhand)) .map(|i| i.kind()); - let second_tool_kind = if let Some(ItemKind::Tool(tool)) = second_item_kind { - Some(tool.kind) - } else { - None - }; + let (second_tool_kind, second_tool_hand) = + if let Some(ItemKind::Tool(tool)) = second_item_kind { + (Some(tool.kind), Some(tool.hands)) + } else { + (None, None) + }; + + let hands = (active_tool_hand, second_tool_hand); match body { Body::Humanoid(body) => { @@ -742,7 +746,13 @@ impl FigureMgr { // Standing (true, false, false) => anim::character::StandAnimation::update_skeleton( &CharacterSkeleton::default(), - (active_tool_kind, second_tool_kind, time, state.avg_vel), + ( + active_tool_kind, + second_tool_kind, + hands, + time, + state.avg_vel, + ), state.state_time, &mut state_animation_rate, skeleton_attr, @@ -753,6 +763,7 @@ impl FigureMgr { ( active_tool_kind, second_tool_kind, + hands, vel.0, // TODO: Update to use the quaternion. ori * anim::vek::Vec3::::unit_y(), @@ -771,6 +782,7 @@ impl FigureMgr { ( active_tool_kind, second_tool_kind, + hands, // TODO: Update to use the quaternion. ori * anim::vek::Vec3::::unit_y(), state.last_ori * anim::vek::Vec3::::unit_y(), @@ -786,6 +798,7 @@ impl FigureMgr { ( active_tool_kind, second_tool_kind, + hands, vel.0, // TODO: Update to use the quaternion. ori * anim::vek::Vec3::::unit_y(), diff --git a/voxygen/src/scene/simple.rs b/voxygen/src/scene/simple.rs index 63c8277b0d..c3cd629d07 100644 --- a/voxygen/src/scene/simple.rs +++ b/voxygen/src/scene/simple.rs @@ -308,26 +308,30 @@ impl Scene { .and_then(|inv| inv.equipped(EquipSlot::Mainhand)) .map(|i| i.kind()); - let active_tool_kind = if let Some(ItemKind::Tool(tool)) = active_item_kind { - Some(tool.kind) - } else { - None - }; + let (active_tool_kind, active_tool_hand) = + if let Some(ItemKind::Tool(tool)) = active_item_kind { + (Some(tool.kind), Some(tool.hands)) + } else { + (None, None) + }; let second_item_kind = inventory .and_then(|inv| inv.equipped(EquipSlot::Offhand)) .map(|i| i.kind()); - let second_tool_kind = if let Some(ItemKind::Tool(tool)) = second_item_kind { - Some(tool.kind) - } else { - None - }; + let (second_tool_kind, second_tool_hand) = + if let Some(ItemKind::Tool(tool)) = second_item_kind { + (Some(tool.kind), Some(tool.hands)) + } else { + (None, None) + }; + + let hands = (active_tool_hand, second_tool_hand); if let Some(body) = scene_data.body { let tgt_skeleton = IdleAnimation::update_skeleton( self.figure_state.skeleton_mut(), - (active_tool_kind, second_tool_kind, scene_data.time), + (active_tool_kind, second_tool_kind, hands, scene_data.time), scene_data.time, &mut 0.0, &SkeletonAttr::from(&body),