1use vrm_spec::vrmc_vrm_1_0::{
2 AvatarPermissionType, CommercialUsageType, CreditNotationType, Meta, ModificationType,
3};
4
5#[derive(Debug, Clone, Default)]
7pub struct AvatarMeta {
8 pub(crate) name: String,
9 pub(crate) version: Option<String>,
10 pub(crate) authors: Vec<String>,
11 pub(crate) copyright_information: Option<String>,
12 pub(crate) contact_information: Option<String>,
13 pub(crate) references: Option<Vec<String>>,
14 pub(crate) third_party_licenses: Option<String>,
15 pub(crate) thumbnail_image: Option<u32>,
16 pub(crate) license_url: Option<String>,
17 pub(crate) other_license_url: Option<String>,
18 pub(crate) permissions: AvatarPermissions,
19}
20
21#[derive(Debug, Clone, Default)]
23pub struct AvatarPermissions {
24 pub avatar_permission: AvatarPermission,
26 pub commercial_usage: CommercialUsage,
28 pub credit_notation: CreditNotation,
30 pub modification: ModificationPermission,
32
33 pub allow_redistribution: bool,
35 pub allow_excessively_violent_usage: bool,
37 pub allow_excessively_sexual_usage: bool,
39 pub allow_political_or_religious_usage: bool,
41 pub allow_antisocial_or_hate_usage: bool,
43}
44
45#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
47pub enum AvatarPermission {
48 #[default]
50 OnlyAuthor,
51 OnlySeparatelyLicensedPerson,
53 Everyone,
55}
56
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
59pub enum CommercialUsage {
60 #[default]
62 PersonalNonProfit,
63 PersonalProfit,
65 Corporation,
67}
68
69#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
71pub enum CreditNotation {
72 #[default]
74 Required,
75 Unnecessary,
77}
78
79#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
81pub enum ModificationPermission {
82 #[default]
84 Prohibited,
85 AllowModification,
87 AllowModificationRedistribution,
89}
90
91impl From<AvatarPermissionType> for AvatarPermission {
92 fn from(val: AvatarPermissionType) -> Self {
93 match val {
94 AvatarPermissionType::OnlyAuthor => Self::OnlyAuthor,
95 AvatarPermissionType::OnlySeparatelyLicensedPerson => {
96 Self::OnlySeparatelyLicensedPerson
97 }
98 AvatarPermissionType::Everyone => Self::Everyone,
99 }
100 }
101}
102
103impl From<CommercialUsageType> for CommercialUsage {
104 fn from(val: CommercialUsageType) -> Self {
105 match val {
106 CommercialUsageType::PersonalNonProfit => Self::PersonalNonProfit,
107 CommercialUsageType::PersonalProfit => Self::PersonalProfit,
108 CommercialUsageType::Corporation => Self::Corporation,
109 }
110 }
111}
112
113impl From<CreditNotationType> for CreditNotation {
114 fn from(val: CreditNotationType) -> Self {
115 match val {
116 CreditNotationType::Required => Self::Required,
117 CreditNotationType::Unnecessary => Self::Unnecessary,
118 }
119 }
120}
121
122impl From<ModificationType> for ModificationPermission {
123 fn from(val: ModificationType) -> Self {
124 match val {
125 ModificationType::Prohibited => Self::Prohibited,
126 ModificationType::AllowModification => Self::AllowModification,
127 ModificationType::AllowModificationRedistribution => {
128 Self::AllowModificationRedistribution
129 }
130 }
131 }
132}
133
134impl AvatarPermissions {
135 pub(crate) fn load_meta(meta: &vrm_spec::vrmc_vrm_1_0::Meta) -> Self {
136 Self {
137 avatar_permission: meta.avatar_permission.map(Into::into).unwrap_or_default(),
138 commercial_usage: meta.commercial_usage.map(Into::into).unwrap_or_default(),
139 credit_notation: meta.credit_notation.map(Into::into).unwrap_or_default(),
140 modification: meta.modification.map(Into::into).unwrap_or_default(),
141 allow_redistribution: meta.allow_redistribution.unwrap_or(false),
142 allow_excessively_violent_usage: meta.allow_excessively_violent_usage.unwrap_or(false),
143 allow_excessively_sexual_usage: meta.allow_excessively_sexual_usage.unwrap_or(false),
144 allow_political_or_religious_usage: meta
145 .allow_political_or_religious_usage
146 .unwrap_or(false),
147 allow_antisocial_or_hate_usage: meta.allow_antisocial_or_hate_usage.unwrap_or(false),
148 }
149 }
150}
151
152impl AvatarMeta {
153 pub fn new(
155 name: impl Into<String>,
156 authors: impl IntoIterator<Item = impl Into<String>>,
157 license_url: impl Into<String>,
158 ) -> Self {
159 Self {
160 name: name.into(),
161 authors: authors.into_iter().map(Into::into).collect(),
162 license_url: Some(license_url.into()),
163 ..Self::default()
164 }
165 }
166
167 pub(crate) fn load_meta(meta: &Meta) -> Self {
168 Self {
169 name: meta.name.clone(),
170 version: meta.version.clone(),
171 authors: meta.authors.clone(),
172 copyright_information: meta.copyright_information.clone(),
173 contact_information: meta.contact_information.clone(),
174 references: meta.references.clone(),
175 third_party_licenses: meta.third_party_licenses.clone(),
176 thumbnail_image: meta.thumbnail_image.as_ref().map(|i| i.value() as u32),
177 license_url: Some(meta.license_url.clone()),
178 other_license_url: meta.other_license_url.clone(),
179 permissions: AvatarPermissions::load_meta(meta),
180 }
181 }
182
183 pub fn name(&self) -> &str {
185 &self.name
186 }
187
188 pub fn version(&self) -> Option<&str> {
190 self.version.as_deref()
191 }
192
193 pub fn authors(&self) -> &[String] {
195 &self.authors
196 }
197
198 pub fn copyright_information(&self) -> Option<&str> {
200 self.copyright_information.as_deref()
201 }
202
203 pub fn contact_information(&self) -> Option<&str> {
205 self.contact_information.as_deref()
206 }
207
208 pub fn references(&self) -> Option<&[String]> {
210 self.references.as_deref()
211 }
212
213 pub fn third_party_licenses(&self) -> Option<&str> {
215 self.third_party_licenses.as_deref()
216 }
217
218 pub fn thumbnail_image(&self) -> Option<u32> {
220 self.thumbnail_image
221 }
222
223 pub fn license_url(&self) -> Option<&str> {
225 self.license_url.as_deref()
226 }
227
228 pub fn other_license_url(&self) -> Option<&str> {
230 self.other_license_url.as_deref()
231 }
232
233 pub fn permissions(&self) -> &AvatarPermissions {
235 &self.permissions
236 }
237}