introduce optional model indices for drop items as well (fixing orichalcum armor drops)

This commit is contained in:
Christof Petig 2023-04-16 22:56:04 +02:00
parent b931b350fd
commit 4c1c84030f
2 changed files with 47 additions and 13 deletions

View File

@ -699,13 +699,13 @@
Simple("common.items.armor.mail.bloodsteel.shoulder"): "voxel.armor.mail.bloodsteel.shoulder",
Simple("common.items.armor.mail.bloodsteel.back"): "voxel.armor.mail.bloodsteel.back",
//Orichalcum Set
Simple("common.items.armor.mail.orichalcum.chest"): "voxel.armor.mail.orichalcum.chest",
Simple("common.items.armor.mail.orichalcum.pants"): "voxel.armor.mail.orichalcum.pants",
Simple("common.items.armor.mail.orichalcum.belt"): "voxel.armor.mail.orichalcum.belt",
Simple("common.items.armor.mail.orichalcum.foot"): "voxel.armor.mail.orichalcum.foot",
Simple("common.items.armor.mail.orichalcum.hand"): "voxel.armor.mail.orichalcum.hand",
Simple("common.items.armor.mail.orichalcum.shoulder"): "voxel.armor.mail.orichalcum.shoulder",
Simple("common.items.armor.mail.orichalcum.back"): "voxel.armor.mail.orichalcum.back",
Simple("common.items.armor.mail.orichalcum.chest"): ("voxel.armor.mail.orichalcum", 0),
Simple("common.items.armor.mail.orichalcum.pants"): ("voxel.armor.mail.orichalcum", 1),
Simple("common.items.armor.mail.orichalcum.belt"): ("voxel.armor.mail.orichalcum", 2),
Simple("common.items.armor.mail.orichalcum.foot"): ("voxel.armor.mail.orichalcum", 3),
Simple("common.items.armor.mail.orichalcum.hand"): ("voxel.armor.mail.orichalcum", 4),
Simple("common.items.armor.mail.orichalcum.shoulder"): ("voxel.armor.mail.orichalcum", 5),
Simple("common.items.armor.mail.orichalcum.back"): ("voxel.armor.mail.orichalcum", 6),
//misc
Simple("common.items.armor.misc.pants.hunting"): "voxel.armor.misc.pants.grayscale",
// Backs

View File

@ -27,7 +27,7 @@ use common::{
vol::{IntoFullPosIterator, ReadVol, Vox},
};
use hashbrown::HashMap;
use serde::Deserialize;
use serde::{Deserialize, Deserializer};
use std::{fmt, hash::Hash};
use tracing::{error, warn};
use vek::*;
@ -5116,8 +5116,42 @@ impl ObjectCentralSpec {
}
}
struct ModelWithOptionalIndex(String, u32);
impl<'de> Deserialize<'de> for ModelWithOptionalIndex {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
struct StringWithOptionalIndex;
use serde::de;
impl<'de> de::Visitor<'de> for StringWithOptionalIndex {
type Value = ModelWithOptionalIndex;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("model_spec or (spec, index)")
}
fn visit_str<E: de::Error>(self, model: &str) -> Result<Self::Value, E> {
Ok(ModelWithOptionalIndex(model.into(), DEFAULT_INDEX))
}
fn visit_seq<A: de::SeqAccess<'de>>(self, mut seq: A) -> Result<Self::Value, A::Error> {
if let Some(spec) = seq.next_element::<String>()? {
if let Some(num) = seq.next_element::<u32>()? {
Ok(ModelWithOptionalIndex(spec, num))
} else {
Err(de::Error::missing_field("index"))
}
} else {
Err(de::Error::missing_field("spec"))
}
}
}
deserializer.deserialize_any(StringWithOptionalIndex {})
}
}
#[derive(Deserialize)]
struct ItemDropCentralSpec(HashMap<ItemKey, String>);
struct ItemDropCentralSpec(HashMap<ItemKey, ModelWithOptionalIndex>);
make_vox_spec!(
item_drop::Body,
@ -5148,17 +5182,17 @@ make_vox_spec!(
impl ItemDropCentralSpec {
fn mesh_bone0(&self, item_drop: &item_drop::Body, item_key: &ItemKey) -> BoneMeshes {
let coin_pouch = "voxel.object.pouch".to_string();
let coin_pouch = ModelWithOptionalIndex("voxel.object.pouch".to_string(), DEFAULT_INDEX);
if let Some(spec) = match item_drop {
item_drop::Body::CoinPouch => Some(&coin_pouch),
_ => self.0.get(item_key),
} {
let full_spec: String = ["voxygen.", spec.as_str()].concat();
let full_spec: String = ["voxygen.", spec.0.as_str()].concat();
let segment = match item_drop {
item_drop::Body::Armor(_) => MatSegment::from_vox_model_index(
&graceful_load_vox_fullspec(&full_spec).read().0,
0,
spec.1 as usize,
)
.map(|mat_cell| match mat_cell {
MatCell::None => None,
@ -5166,7 +5200,7 @@ impl ItemDropCentralSpec {
MatCell::Normal(data) => data.is_hollow().then_some(MatCell::None),
})
.to_segment(|_| Default::default()),
_ => graceful_load_segment_fullspec(&full_spec, DEFAULT_INDEX),
_ => graceful_load_segment_fullspec(&full_spec, spec.1),
};
let offset = segment_center(&segment).unwrap_or_default();
(segment, match item_drop {