1use codec::{Decode, Encode, MaxEncodedLen};2use scale_info::TypeInfo;34#[cfg(feature = "std")]5use serde::Serialize;67#[cfg(feature = "std")]8use crate::serialize;910use crate::primitives::*;1112#[cfg_attr(feature = "std", derive(Serialize))]13#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]14#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]15pub struct FixedPart<BoundedString> {16 pub id: PartId,17 pub z: ZIndex,1819 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]20 pub src: BoundedString,21}2223#[cfg_attr(feature = "std", derive(Serialize))]24#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]25#[cfg_attr(26 feature = "std",27 serde(bound = "BoundedCollectionList: AsRef<[CollectionId]>")28)]29pub enum EquippableList<BoundedCollectionList> {30 All,31 Empty,32 Custom(#[cfg_attr(feature = "std", serde(with = "serialize::vec"))] BoundedCollectionList),33}3435#[cfg_attr(feature = "std", derive(Serialize))]36#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]37#[cfg_attr(38 feature = "std",39 serde(bound = r#"40 BoundedString: AsRef<[u8]>,41 BoundedCollectionList: AsRef<[CollectionId]>42 "#)43)]44pub struct SlotPart<BoundedString, BoundedCollectionList> {45 pub id: PartId,46 pub equippable: EquippableList<BoundedCollectionList>,4748 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]49 pub src: BoundedString,5051 pub z: ZIndex,52}5354#[cfg_attr(feature = "std", derive(Serialize))]55#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]56#[cfg_attr(57 feature = "std",58 serde(bound = r#"59 BoundedString: AsRef<[u8]>,60 BoundedCollectionList: AsRef<[CollectionId]>61 "#)62)]63pub enum PartType<BoundedString, BoundedCollectionList> {64 FixedPart(FixedPart<BoundedString>),65 SlotPart(SlotPart<BoundedString, BoundedCollectionList>),66}6768impl<BoundedString, BoundedCollectionList> PartType<BoundedString, BoundedCollectionList> {69 pub fn id(&self) -> PartId {70 match self {71 Self::FixedPart(part) => part.id,72 Self::SlotPart(part) => part.id,73 }74 }7576 pub fn src(&self) -> &BoundedString {77 match self {78 Self::FixedPart(part) => &part.src,79 Self::SlotPart(part) => &part.src,80 }81 }8283 pub fn z_index(&self) -> ZIndex {84 match self {85 Self::FixedPart(part) => part.z,86 Self::SlotPart(part) => part.z,87 }88 }89}