mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Use item_definition_id for weapon asset mapping
This commit is contained in:
parent
4ae946d699
commit
133ba82a9b
@ -8,7 +8,7 @@
|
||||
"voxel.weapon.bow.shortbow_starter",
|
||||
(0.0, 0.0, 0.0), (90.0, 90.0, 0.0), 1.0,
|
||||
),
|
||||
Tool(Tool("common.items.weapons.bow.wood_shortbow-0")): VoxTrans(
|
||||
Tool("common.items.weapons.bow.wood_shortbow-0"): VoxTrans(
|
||||
"voxel.weapon.bow.shortbow_wood-0",
|
||||
(0.0, 0.0, 0.0), (90.0, 90.0, 0.0), 1.0,
|
||||
),
|
||||
|
@ -461,7 +461,7 @@
|
||||
vox_spec: ("weapon.hammer.cult_purp-0", (-3.5, -4.5, -5.0)),
|
||||
color: None
|
||||
),
|
||||
"Craftsman": ( //TODO This should be a 1h hammer!
|
||||
/*"Craftsman": ( //TODO This should be a 1h hammer!
|
||||
vox_spec: ("weapon.hammer.craftsman", (-2.0, -5.0, -5.5)),
|
||||
color: None
|
||||
),*/
|
||||
|
@ -351,6 +351,7 @@ pub trait ItemDesc {
|
||||
fn name(&self) -> &str;
|
||||
fn kind(&self) -> &ItemKind;
|
||||
fn quality(&self) -> &Quality;
|
||||
fn item_definition_id(&self) -> &str;
|
||||
}
|
||||
|
||||
impl ItemDesc for Item {
|
||||
@ -361,6 +362,8 @@ impl ItemDesc for Item {
|
||||
fn kind(&self) -> &ItemKind { &self.item_def.kind }
|
||||
|
||||
fn quality(&self) -> &Quality { &self.item_def.quality }
|
||||
|
||||
fn item_definition_id(&self) -> &str { &self.item_def.item_definition_id }
|
||||
}
|
||||
|
||||
impl ItemDesc for ItemDef {
|
||||
@ -371,6 +374,8 @@ impl ItemDesc for ItemDef {
|
||||
fn kind(&self) -> &ItemKind { &self.kind }
|
||||
|
||||
fn quality(&self) -> &Quality { &self.quality }
|
||||
|
||||
fn item_definition_id(&self) -> &str { &self.item_definition_id }
|
||||
}
|
||||
|
||||
impl Component for Item {
|
||||
|
@ -1,4 +1,4 @@
|
||||
-- Changes filepaths of sceptres
|
||||
-- Changes filepaths of npcweapons
|
||||
|
||||
UPDATE item
|
||||
SET item_definition_id = 'common.items.npc_weapons.unique.beast_claws' WHERE item_definition_id = 'common.items.npc_weapons.npcweapon.beast_claws';
|
||||
|
@ -87,23 +87,6 @@ fn get_tool_kind(kind: &ToolKind) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/*fn get_tool_kind_kind(kind: &ToolKind) -> String {
|
||||
match kind {
|
||||
ToolKind::Sword(x) => x.clone(),
|
||||
ToolKind::Axe(x) => x.clone(),
|
||||
ToolKind::Hammer(x) => x.clone(),
|
||||
ToolKind::Bow(x) => x.clone(),
|
||||
ToolKind::Dagger(x) => x.clone(),
|
||||
ToolKind::Staff(x) => x.clone(),
|
||||
ToolKind::Sceptre(x) => x.clone(),
|
||||
ToolKind::Shield(x) => x.clone(),
|
||||
ToolKind::Debug(x) => x.clone(),
|
||||
ToolKind::Farming(x) => x.clone(),
|
||||
ToolKind::NpcWeapon(x) => x.clone(),
|
||||
ToolKind::Empty => "".to_string(),
|
||||
}
|
||||
}*/
|
||||
|
||||
fn get_armor_kind(kind: &ArmorKind) -> String {
|
||||
match kind {
|
||||
ArmorKind::Shoulder(_) => "Shoulder".to_string(),
|
||||
@ -146,7 +129,6 @@ fn all_items() -> Result<(), Box<dyn Error>> {
|
||||
let kind = match item.kind() {
|
||||
ItemKind::Armor(armor) => get_armor_kind_kind(&armor.kind),
|
||||
ItemKind::Lantern(lantern) => lantern.kind.clone(),
|
||||
//ItemKind::Tool(tool) => get_tool_kind_kind(&tool.kind),
|
||||
_ => "".to_owned(),
|
||||
};
|
||||
|
||||
|
@ -93,7 +93,7 @@ impl Animation for IdleAnimation {
|
||||
next.main.position = Vec3::new(0.0, -5.0, 6.0);
|
||||
next.main.orientation = Quaternion::rotation_y(2.5) * Quaternion::rotation_z(1.57);
|
||||
},
|
||||
Some(ToolKind::Staff(_)) | Some(ToolKind::Sceptre(_)) => {
|
||||
Some(ToolKind::Staff) | Some(ToolKind::Sceptre) => {
|
||||
next.main.position = Vec3::new(2.0, -5.0, -1.0);
|
||||
next.main.orientation = Quaternion::rotation_y(-0.5) * Quaternion::rotation_z(1.57);
|
||||
},
|
||||
|
@ -272,7 +272,7 @@ impl<'a> Widget for Crafting<'a> {
|
||||
let quality_col = get_quality_col(&*recipe.output.0);
|
||||
Button::image(
|
||||
self.item_imgs
|
||||
.img_id_or_not_found_img((&*recipe.output.0.kind()).into()),
|
||||
.img_id_or_not_found_img((&*recipe.output.0).into()),
|
||||
)
|
||||
.w_h(55.0, 55.0)
|
||||
.label(&output_text)
|
||||
@ -433,20 +433,17 @@ impl<'a> Widget for Crafting<'a> {
|
||||
frame.set(state.ids.ingredient_frame[i], ui);
|
||||
//Item Image
|
||||
let (title, desc) = super::util::item_text(&**item_def);
|
||||
Button::image(
|
||||
self.item_imgs
|
||||
.img_id_or_not_found_img((&*item_def.kind()).into()),
|
||||
)
|
||||
.w_h(22.0, 22.0)
|
||||
.middle_of(state.ids.ingredient_frame[i])
|
||||
.with_tooltip(
|
||||
self.tooltip_manager,
|
||||
title,
|
||||
&*desc,
|
||||
&item_tooltip,
|
||||
quality_col,
|
||||
)
|
||||
.set(state.ids.ingredient_img[i], ui);
|
||||
Button::image(self.item_imgs.img_id_or_not_found_img((&**item_def).into()))
|
||||
.w_h(22.0, 22.0)
|
||||
.middle_of(state.ids.ingredient_frame[i])
|
||||
.with_tooltip(
|
||||
self.tooltip_manager,
|
||||
title,
|
||||
&*desc,
|
||||
&item_tooltip,
|
||||
quality_col,
|
||||
)
|
||||
.set(state.ids.ingredient_img[i], ui);
|
||||
// Ingredients text and amount
|
||||
// Don't show inventory amounts above 999 to avoid the widget clipping
|
||||
let over9k = "99+";
|
||||
|
@ -3,8 +3,7 @@ use common::{
|
||||
assets::{self, watch::ReloadIndicator, Asset},
|
||||
comp::item::{
|
||||
armor::{Armor, ArmorKind},
|
||||
tool::{Tool, ToolKind},
|
||||
Glider, ItemKind, Lantern, Throwable, Utility,
|
||||
Glider, ItemDesc, ItemKind, Lantern, Throwable, Utility,
|
||||
},
|
||||
figure::Segment,
|
||||
};
|
||||
@ -19,7 +18,7 @@ use vek::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum ItemKey {
|
||||
Tool(ToolKind),
|
||||
Tool(String),
|
||||
Lantern(String),
|
||||
Glider(String),
|
||||
Armor(ArmorKind),
|
||||
@ -30,10 +29,13 @@ pub enum ItemKey {
|
||||
Empty,
|
||||
}
|
||||
|
||||
impl From<&ItemKind> for ItemKey {
|
||||
fn from(item_kind: &ItemKind) -> Self {
|
||||
impl<T: ItemDesc> From<&T> for ItemKey {
|
||||
fn from(item_desc: &T) -> Self {
|
||||
let item_kind = item_desc.kind();
|
||||
let item_definition_id = item_desc.item_definition_id();
|
||||
|
||||
match item_kind {
|
||||
ItemKind::Tool(Tool { kind, .. }) => ItemKey::Tool(kind.clone()),
|
||||
ItemKind::Tool(_) => ItemKey::Tool(item_definition_id.to_owned()),
|
||||
ItemKind::Lantern(Lantern { kind, .. }) => ItemKey::Lantern(kind.clone()),
|
||||
ItemKind::Glider(Glider { kind, .. }) => ItemKey::Glider(kind.clone()),
|
||||
ItemKind::Armor(Armor { kind, .. }) => ItemKey::Armor(kind.clone()),
|
||||
@ -140,13 +142,13 @@ impl ItemImgs {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn img_id(&self, item_kind: ItemKey) -> Option<Id> {
|
||||
match self.map.get(&item_kind) {
|
||||
pub fn img_id(&self, item_key: ItemKey) -> Option<Id> {
|
||||
match self.map.get(&item_key) {
|
||||
Some(id) => Some(*id),
|
||||
// There was no specification in the ron
|
||||
None => {
|
||||
warn!(
|
||||
?item_kind,
|
||||
?item_key,
|
||||
"missing specified image file (note: hot-reloading won't work here)",
|
||||
);
|
||||
None
|
||||
@ -154,8 +156,8 @@ impl ItemImgs {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn img_id_or_not_found_img(&self, item_kind: ItemKey) -> Id {
|
||||
self.img_id(item_kind).unwrap_or(self.not_found)
|
||||
pub fn img_id_or_not_found_img(&self, item_key: ItemKey) -> Id {
|
||||
self.img_id(item_key).unwrap_or(self.not_found)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ impl SlotKey<Inventory, ItemImgs> for InventorySlot {
|
||||
type ImageKey = ItemKey;
|
||||
|
||||
fn image_key(&self, source: &Inventory) -> Option<(Self::ImageKey, Option<Color>)> {
|
||||
source.get(self.0).map(|i| (i.kind().into(), None))
|
||||
source.get(self.0).map(|i| (i.into(), None))
|
||||
}
|
||||
|
||||
fn amount(&self, source: &Inventory) -> Option<u32> {
|
||||
@ -69,7 +69,7 @@ impl SlotKey<Loadout, ItemImgs> for EquipSlot {
|
||||
EquipSlot::Glider => source.glider.as_ref(),
|
||||
};
|
||||
|
||||
item.map(|i| (i.kind().into(), None))
|
||||
item.map(|i| (i.into(), None))
|
||||
}
|
||||
|
||||
fn amount(&self, _: &Loadout) -> Option<u32> { None }
|
||||
@ -103,7 +103,7 @@ impl<'a> SlotKey<HotbarSource<'a>, HotbarImageSource<'a>> for HotbarSlot {
|
||||
hotbar.get(*self).and_then(|contents| match contents {
|
||||
hotbar::SlotContents::Inventory(idx) => inventory
|
||||
.get(idx)
|
||||
.map(|item| HotbarImage::Item(item.kind().into()))
|
||||
.map(|item| HotbarImage::Item(item.into()))
|
||||
.map(|i| (i, None)),
|
||||
hotbar::SlotContents::Ability3 => loadout
|
||||
.active_item
|
||||
|
@ -12,7 +12,6 @@ use common::{
|
||||
comp::{
|
||||
item::{
|
||||
armor::{Armor, ArmorKind},
|
||||
tool::ToolKind,
|
||||
ItemKind,
|
||||
},
|
||||
CharacterState, Loadout,
|
||||
@ -69,8 +68,8 @@ pub struct FigureKey<Body> {
|
||||
/// person or when the character is in a tool-using state).
|
||||
#[derive(Eq, Hash, PartialEq)]
|
||||
pub(super) struct CharacterToolKey {
|
||||
pub active: Option<ToolKind>,
|
||||
pub second: Option<ToolKind>,
|
||||
pub active: Option<String>,
|
||||
pub second: Option<String>,
|
||||
}
|
||||
|
||||
/// Character data that exists in third person only.
|
||||
@ -180,20 +179,14 @@ impl CharacterCacheKey {
|
||||
},
|
||||
tool: if are_tools_visible {
|
||||
Some(CharacterToolKey {
|
||||
active: if let Some(ItemKind::Tool(tool)) =
|
||||
loadout.active_item.as_ref().map(|i| i.item.kind())
|
||||
{
|
||||
Some(tool.kind.clone())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
second: if let Some(ItemKind::Tool(tool)) =
|
||||
loadout.second_item.as_ref().map(|i| i.item.kind())
|
||||
{
|
||||
Some(tool.kind.clone())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
active: loadout
|
||||
.active_item
|
||||
.as_ref()
|
||||
.map(|i| i.item.item_definition_id().to_owned()),
|
||||
second: loadout
|
||||
.second_item
|
||||
.as_ref()
|
||||
.map(|i| i.item.item_definition_id().to_owned()),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
@ -9,7 +9,6 @@ use common::{
|
||||
fish_medium, fish_small,
|
||||
golem::{self, BodyType as GBodyType, Species as GSpecies},
|
||||
humanoid::{self, Body, BodyType, EyeColor, Skin, Species},
|
||||
item::tool::ToolKind,
|
||||
object,
|
||||
quadruped_low::{self, BodyType as QLBodyType, Species as QLSpecies},
|
||||
quadruped_medium::{self, BodyType as QMBodyType, Species as QMSpecies},
|
||||
@ -327,7 +326,7 @@ struct HumArmorPantsSpec(ArmorVoxSpecMap<String, ArmorVoxSpec>);
|
||||
#[derive(Deserialize)]
|
||||
struct HumArmorFootSpec(ArmorVoxSpecMap<String, ArmorVoxSpec>);
|
||||
#[derive(Deserialize)]
|
||||
struct HumMainWeaponSpec(HashMap<ToolKind, ArmorVoxSpec>);
|
||||
struct HumMainWeaponSpec(HashMap<String, ArmorVoxSpec>);
|
||||
#[derive(Deserialize)]
|
||||
struct HumArmorLanternSpec(ArmorVoxSpecMap<String, ArmorVoxSpec>);
|
||||
#[derive(Deserialize)]
|
||||
@ -826,11 +825,11 @@ impl HumArmorFootSpec {
|
||||
}
|
||||
|
||||
impl HumMainWeaponSpec {
|
||||
fn mesh_main_weapon(&self, tool_kind: &ToolKind, flipped: bool) -> BoneMeshes {
|
||||
let spec = match self.0.get(tool_kind) {
|
||||
fn mesh_main_weapon(&self, item_definition_id: &str, flipped: bool) -> BoneMeshes {
|
||||
let spec = match self.0.get(item_definition_id) {
|
||||
Some(spec) => spec,
|
||||
None => {
|
||||
error!(?tool_kind, "No tool/weapon specification exists");
|
||||
error!(?item_definition_id, "No tool/weapon specification exists");
|
||||
return load_mesh("not_found", Vec3::new(-1.5, -1.5, -7.0));
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user