#[multi_param]Expand description
Annotates a trait to automatically generate getters and setters that forward to methods of the same name in various structs.
This is used to create traits that encapsulate state that’s shared across multiple parameter definitions.
This trait takes as arguments the names of various structs for which it
should automatically generate an implementation. It should annotate a trait
that contains a fields! macro, using the same named field syntax that a
struct uses. For each field, a getter and setter is generated both in the
trait and in its implementation for each struct.
#[multi_param(EQUIP_PARAM_ACCESSORY_ST, EQUIP_PARAM_GOODS_ST)]
pub trait EquipParamPassive: EquipParam {
fields! {
sfx_variation_id: i32,
ref_category: u8,
sp_effect_category: u8,
shop_lv: i16,
}
}§Field Attributes
This can also be used as to annotate field attributes.
§rename()
You can use the rename() annotation to rename the field this targets for a
particular struct. This can be useful if the same logical field has
different names, which sometimes happens due to typos in FromSoftware’s
internal names.
The syntax is #[multi_param(rename(param = ..., name = ...))]. The struct
must exactly match one of the structs passed to the outer annotation, and
the name must be a valid identifier.
#[multi_param(
EQUIP_PARAM_ACCESSORY_ST,
EQUIP_PARAM_GOODS_ST,
EQUIP_PARAM_PROTECTOR_ST,
EQUIP_PARAM_WEAPON_ST
)]
pub trait EquipParam {
fields! {
weight: f32,
basic_price: i32,
sell_value: i32,
sort_id: i32,
vagrant_item_lot_id: i32,
#[multi_param(
rename(param = EQUIP_PARAM_PROTECTOR_ST, name = "vagrant_bonusene_drop_item_lot_id"),
rename(param = EQUIP_PARAM_WEAPON_ST, name = "vagrant_bonusene_drop_item_lot_id"),
)]
vagrant_bonus_ene_drop_item_lot_id: i32;
vagrant_item_ene_drop_item_lot_id: i32,
}
}
```rs
## Enums
Each trait also generates two enums, one mutable and one immutable, which
can be used in contexts where it's relevant *which* param type in particular
you have. These enums have a variant for each defined parameter type. The
above example would define:
```rs
pub enum EquipParamStruct<'a> {
EQUIP_PARAM_ACCESSORY_ST(&'a EQUIP_PARAM_ACCESSORY_ST),
EQUIP_PARAM_GOODS_ST(&'a EQUIP_PARAM_GOODS_ST),
EQUIP_PARAM_PROTECTOR_ST(&'a EQUIP_PARAM_PROTECTOR_ST),
EQUIP_PARAM_WEAPON_ST(&'a EQUIP_PARAM_WEAPON_ST),
}
impl EquipParamStruct<'_> {
pub fn as_dyn(&self) -> &dyn EquipParam;
}
pub enum EquipParamStructMut<'a> {
EQUIP_PARAM_ACCESSORY_ST(&'a mut EQUIP_PARAM_ACCESSORY_ST),
EQUIP_PARAM_GOODS_ST(&'a mut EQUIP_PARAM_GOODS_ST),
EQUIP_PARAM_PROTECTOR_ST(&'a mut EQUIP_PARAM_PROTECTOR_ST),
EQUIP_PARAM_WEAPON_ST(&'a mut EQUIP_PARAM_WEAPON_ST),
}
impl EquipParamStructMut<'_> {
pub fn as_dyn(&mut self) -> &mut dyn EquipParam;
}You can access these using the as_enum() and as_enum_mut() methods.