From 3a3f4db9db42ea03cea99f436ce61fe7d67c6b83 Mon Sep 17 00:00:00 2001 From: LeoKu Date: Tue, 19 Oct 2021 23:45:30 +0800 Subject: [PATCH] feat: add gender feature --- src/App.vue | 1 + src/types/index.ts | 2 ++ src/utils/index.ts | 19 ++++++++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/App.vue b/src/App.vue index 518e9dd..0f721fe 100644 --- a/src/App.vue +++ b/src/App.vue @@ -111,6 +111,7 @@ function handleGenerate() { ) { colorfulOption = getSpecialAvatarOption() } + colorfulOption.wrapperShape = avatarOption.value.wrapperShape setAvatarOption(colorfulOption) showConfetti() } else { diff --git a/src/types/index.ts b/src/types/index.ts index fe70f80..171d7b2 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -40,6 +40,8 @@ type AvatarWidgets = { } export interface AvatarOption { + gender?: Gender + wrapperShape?: `${WrapperShape}` background: { diff --git a/src/utils/index.ts b/src/utils/index.ts index a05f70a..b69abda 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,4 +1,5 @@ -import type { BeardShape, EarringsShape, GlassesShape } from '@/enums' +import type { EarringsShape, GlassesShape } from '@/enums' +import { BeardShape, Gender, TopsShape } from '@/enums' import type { AvatarOption, None } from '@/types' import { NONE, SETTINGS, SPECIAL_AVATARS } from './constant' @@ -32,7 +33,19 @@ export function getRandomAvatarOption( presetOption: Partial = {}, useOption: Partial = {} ): AvatarOption { + const gender = getRandomValue(SETTINGS.gender) + + const beardList: BeardShape[] = [] + let topList: TopsShape[] = [TopsShape.Danny, TopsShape.Wave, TopsShape.Pixie] + + if (gender === Gender.Male) { + beardList.push(BeardShape.Scruff) + topList = SETTINGS.topsShape.filter((shape) => !topList.includes(shape)) + } + const avatarOption: AvatarOption = { + gender, + wrapperShape: presetOption?.wrapperShape || getRandomValue(SETTINGS.wrapperShape), @@ -47,7 +60,7 @@ export function getRandomAvatarOption( shape: getRandomValue(SETTINGS.faceShape), }, tops: { - shape: getRandomValue(SETTINGS.topsShape, { + shape: getRandomValue(topList, { avoid: [useOption.widgets?.tops?.shape], }), }, @@ -87,7 +100,7 @@ export function getRandomAvatarOption( }), }, beard: { - shape: getRandomValue(SETTINGS.beardShape, { + shape: getRandomValue(beardList, { usually: [NONE], }), }, -- GitLab