|
| 1 | +import type { CharacterModelLicenseSerializer } from '@/types/Response'; |
| 2 | +import type { VRM1Meta } from '@pixiv/three-vrm'; |
| 3 | + |
| 4 | +type LicenseProperty = keyof CharacterModelLicenseSerializer; |
| 5 | + |
| 6 | +/** |
| 7 | + * VRoid Hubで設定出来るVRM0のライセンスから表示テキストを返す |
| 8 | + * @param license |
| 9 | + * @param property |
| 10 | + * @returns |
| 11 | + */ |
| 12 | +export const getHubVrm0LicenseValue = (license: CharacterModelLicenseSerializer, property: LicenseProperty): string => { |
| 13 | + const status = license[property]; |
| 14 | + |
| 15 | + if (status === 'default') return '未設定'; |
| 16 | + |
| 17 | + switch (property) { |
| 18 | + case 'characterization_allowed_user': |
| 19 | + return status === 'everyone' ? 'OK' : 'NG'; |
| 20 | + case 'personal_commercial_use': |
| 21 | + if (status === 'profit') return 'OK'; |
| 22 | + if (status === 'nonprofit') return '非営利のみ'; |
| 23 | + return 'NG'; |
| 24 | + case 'credit': |
| 25 | + return status === 'necessary' ? '必要' : '不要'; |
| 26 | + case 'modification': |
| 27 | + return status === 'allow' ? 'OK' : 'NG'; |
| 28 | + case 'redistribution': |
| 29 | + return status === 'allow' ? 'OK' : 'NG'; |
| 30 | + case 'sexual_expression': |
| 31 | + return status === 'allow' ? 'OK' : 'NG'; |
| 32 | + case 'violent_expression': |
| 33 | + return status === 'allow' ? 'OK' : 'NG'; |
| 34 | + case 'corporate_commercial_use': |
| 35 | + return status === 'allow' ? 'OK' : 'NG'; |
| 36 | + default: |
| 37 | + return '未設定'; |
| 38 | + } |
| 39 | +}; |
| 40 | + |
| 41 | +/** |
| 42 | + * VRoid Hubで設定出来るVRM0のライセンスからテキストの表示色の種類を返す |
| 43 | + * @param license |
| 44 | + * @param property |
| 45 | + * @returns |
| 46 | + */ |
| 47 | +export const getHubVrm0LicenseVariant = ( |
| 48 | + license: CharacterModelLicenseSerializer, |
| 49 | + property: LicenseProperty, |
| 50 | +): 'default' | 'allow' | 'bold' => { |
| 51 | + const status = license[property]; |
| 52 | + |
| 53 | + switch (property) { |
| 54 | + case 'characterization_allowed_user': |
| 55 | + return status === 'everyone' ? 'allow' : 'default'; |
| 56 | + case 'personal_commercial_use': |
| 57 | + return status === 'profit' || status === 'nonprofit' ? 'allow' : 'default'; |
| 58 | + case 'credit': |
| 59 | + return status === 'necessary' ? 'bold' : 'default'; |
| 60 | + case 'modification': |
| 61 | + return status === 'allow' ? 'allow' : 'default'; |
| 62 | + case 'redistribution': |
| 63 | + return status === 'allow' ? 'allow' : 'default'; |
| 64 | + case 'sexual_expression': |
| 65 | + return status === 'allow' ? 'allow' : 'default'; |
| 66 | + case 'violent_expression': |
| 67 | + return status === 'allow' ? 'allow' : 'default'; |
| 68 | + case 'corporate_commercial_use': |
| 69 | + return status === 'allow' ? 'allow' : 'default'; |
| 70 | + default: |
| 71 | + return 'default'; |
| 72 | + } |
| 73 | +}; |
| 74 | + |
| 75 | +type vrm1MetaProperty = keyof VRM1Meta | 'personalCommercialUse' | 'modificationRedistribution'; |
| 76 | + |
| 77 | +/** |
| 78 | + * VRM1.0のライセンスから表示テキストを返す |
| 79 | + * @param vrm1Meta |
| 80 | + * @param property |
| 81 | + * @returns |
| 82 | + */ |
| 83 | +export const getVrm1LicenseValue = (vrm1Meta: VRM1Meta, property: vrm1MetaProperty) => { |
| 84 | + //「 個人の商用利用」は法人利用とプロパティが共用のため、commercialUsageの値を参照し判定する |
| 85 | + if (property === 'personalCommercialUse') { |
| 86 | + const status = vrm1Meta.commercialUsage; |
| 87 | + if (status == null) return '未設定'; |
| 88 | + |
| 89 | + return status === 'corporation' || status === 'personalProfit' ? 'OK' : 'NG'; |
| 90 | + } |
| 91 | + |
| 92 | + // 「改変物の再配布」は改変とプロパティが共用のため、modificationの値を参照し判定する |
| 93 | + if (property === 'modificationRedistribution') { |
| 94 | + const status = vrm1Meta.modification; |
| 95 | + if (status == null) return '未設定'; |
| 96 | + |
| 97 | + return status === 'allowModificationRedistribution' ? 'OK' : 'NG'; |
| 98 | + } |
| 99 | + |
| 100 | + const status = vrm1Meta[property]; |
| 101 | + if (status == null) return '未設定'; |
| 102 | + |
| 103 | + switch (property) { |
| 104 | + case 'avatarPermission': |
| 105 | + return status === 'everyone' ? 'OK' : 'NG'; |
| 106 | + case 'allowExcessivelyViolentUsage': |
| 107 | + return status === true ? 'OK' : 'NG'; |
| 108 | + case 'allowExcessivelySexualUsage': |
| 109 | + return status === true ? 'OK' : 'NG'; |
| 110 | + case 'allowPoliticalOrReligiousUsage': |
| 111 | + return status === true ? 'OK' : 'NG'; |
| 112 | + case 'allowAntisocialOrHateUsage': |
| 113 | + return status === true ? 'OK' : 'NG'; |
| 114 | + case 'commercialUsage': |
| 115 | + return status === 'corporation' ? 'OK' : 'NG'; |
| 116 | + case 'allowRedistribution': |
| 117 | + return status === true ? 'OK' : 'NG'; |
| 118 | + case 'modification': |
| 119 | + return status === 'allowModification' || status === 'allowModificationRedistribution' ? 'OK' : 'NG'; |
| 120 | + case 'creditNotation': |
| 121 | + return status === 'required' ? '必要' : '不要'; |
| 122 | + default: |
| 123 | + return '未設定'; |
| 124 | + } |
| 125 | +}; |
| 126 | + |
| 127 | +/** |
| 128 | + * VRM1.0のライセンスからテキストの表示色の種類を返す |
| 129 | + * @param vrm1Meta |
| 130 | + * @param property |
| 131 | + * @returns |
| 132 | + */ |
| 133 | +export const getVrm1LicenseVariant = (vrm1Meta: VRM1Meta, property: vrm1MetaProperty): 'default' | 'allow' | 'bold' => { |
| 134 | + //「 個人の商用利用」は法人利用とプロパティが共用のため、commercialUsageの値を参照し判定する |
| 135 | + if (property === 'personalCommercialUse') { |
| 136 | + const status = vrm1Meta.commercialUsage; |
| 137 | + if (status == null) return 'default'; |
| 138 | + |
| 139 | + return status === 'corporation' || status === 'personalProfit' ? 'allow' : 'default'; |
| 140 | + } |
| 141 | + |
| 142 | + // 「改変物の再配布」は改変とプロパティが共用のため、modificationの値を参照し判定する |
| 143 | + if (property === 'modificationRedistribution') { |
| 144 | + const status = vrm1Meta.modification; |
| 145 | + if (status == null) return 'default'; |
| 146 | + |
| 147 | + return status === 'allowModificationRedistribution' ? 'allow' : 'default'; |
| 148 | + } |
| 149 | + |
| 150 | + const status = vrm1Meta[property]; |
| 151 | + if (status == null) return 'default'; |
| 152 | + |
| 153 | + switch (property) { |
| 154 | + case 'avatarPermission': |
| 155 | + return status === 'everyone' ? 'allow' : 'default'; |
| 156 | + case 'allowExcessivelyViolentUsage': |
| 157 | + return status === true ? 'allow' : 'default'; |
| 158 | + case 'allowExcessivelySexualUsage': |
| 159 | + return status === true ? 'allow' : 'default'; |
| 160 | + case 'allowPoliticalOrReligiousUsage': |
| 161 | + return status === true ? 'allow' : 'default'; |
| 162 | + case 'allowAntisocialOrHateUsage': |
| 163 | + return status === true ? 'allow' : 'default'; |
| 164 | + case 'commercialUsage': |
| 165 | + return status === 'corporation' ? 'allow' : 'default'; |
| 166 | + case 'allowRedistribution': |
| 167 | + return status === true ? 'allow' : 'default'; |
| 168 | + case 'modification': |
| 169 | + return status === 'allowModification' || status === 'allowModificationRedistribution' ? 'allow' : 'default'; |
| 170 | + case 'creditNotation': |
| 171 | + return status === 'required' ? 'bold' : 'default'; |
| 172 | + default: |
| 173 | + return 'default'; |
| 174 | + } |
| 175 | +}; |
0 commit comments