12345use codec::{Decode, Encode, MaxEncodedLen};6use scale_info::TypeInfo;78#[cfg(feature = "std")]9use serde::Serialize;1011#[cfg(feature = "std")]12use crate::serialize;1314use crate::primitives::*;1516#[cfg_attr(feature = "std", derive(Serialize))]17#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]18#[cfg_attr(feature = "std", serde(bound = "BoundedString: AsRef<[u8]>"))]19pub struct FixedPart<BoundedString> {20 pub id: PartId,21 pub z: ZIndex,2223 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]24 pub src: BoundedString,25}2627#[cfg_attr(feature = "std", derive(Serialize))]28#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]29#[cfg_attr(30 feature = "std",31 serde(bound = "BoundedCollectionList: AsRef<[CollectionId]>")32)]33pub enum EquippableList<BoundedCollectionList> {34 All,35 Empty,36 Custom(#[cfg_attr(feature = "std", serde(with = "serialize::vec"))] BoundedCollectionList),37}3839#[cfg_attr(feature = "std", derive(Serialize))]40#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]41#[cfg_attr(42 feature = "std",43 serde(bound = r#"44 BoundedString: AsRef<[u8]>,45 BoundedCollectionList: AsRef<[CollectionId]>46 "#)47)]48pub struct SlotPart<BoundedString, BoundedCollectionList> {49 pub id: PartId,50 pub equippable: EquippableList<BoundedCollectionList>,5152 #[cfg_attr(feature = "std", serde(with = "serialize::vec"))]53 pub src: BoundedString,5455 pub z: ZIndex,56}5758#[cfg_attr(feature = "std", derive(Serialize))]59#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, Eq, MaxEncodedLen)]60#[cfg_attr(61 feature = "std",62 serde(bound = r#"63 BoundedString: AsRef<[u8]>,64 BoundedCollectionList: AsRef<[CollectionId]>65 "#)66)]67pub enum PartType<BoundedString, BoundedCollectionList> {68 FixedPart(FixedPart<BoundedString>),69 SlotPart(SlotPart<BoundedString, BoundedCollectionList>),70}7172impl<BoundedString, BoundedCollectionList> PartType<BoundedString, BoundedCollectionList> {73 pub fn id(&self) -> PartId {74 match self {75 Self::FixedPart(part) => part.id,76 Self::SlotPart(part) => part.id,77 }78 }7980 pub fn src(&self) -> &BoundedString {81 match self {82 Self::FixedPart(part) => &part.src,83 Self::SlotPart(part) => &part.src,84 }85 }8687 pub fn z_index(&self) -> ZIndex {88 match self {89 Self::FixedPart(part) => part.z,90 Self::SlotPart(part) => part.z,91 }92 }93}