diff --git a/apps/gi-frontend/src/app/teams/[teamId]/TalentContent.tsx b/apps/gi-frontend/src/app/teams/[teamId]/TalentContent.tsx index 073c1a5890..7585138eb5 100644 --- a/apps/gi-frontend/src/app/teams/[teamId]/TalentContent.tsx +++ b/apps/gi-frontend/src/app/teams/[teamId]/TalentContent.tsx @@ -305,6 +305,7 @@ function SkillDisplayCard({ document={doc} collapse // hideHeader={hideHeader} + setConditional={() => {}} // TODO: frzyc setConditional /> ))} diff --git a/libs/pando/ui-sheet/src/components/DocumentDisplay.tsx b/libs/pando/ui-sheet/src/components/DocumentDisplay.tsx index e6781b86f7..0b2c77c6a7 100644 --- a/libs/pando/ui-sheet/src/components/DocumentDisplay.tsx +++ b/libs/pando/ui-sheet/src/components/DocumentDisplay.tsx @@ -2,21 +2,39 @@ import type { CardBackgroundColor } from '@genshin-optimizer/common/ui' import { CardHeaderCustom, CardThemed } from '@genshin-optimizer/common/ui' import { evalIfFunc } from '@genshin-optimizer/common/util' +import { read } from '@genshin-optimizer/pando/engine' +import CheckBoxIcon from '@mui/icons-material/CheckBox' +import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank' import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown' -import { Box, Collapse, Divider } from '@mui/material' +import { Box, Button, Collapse, Divider } from '@mui/material' import { useContext, useState } from 'react' import { CalcContext } from '../context' -import type { Document, FieldsDocument, Header, TextDocument } from '../types' +import type { + Conditional, + Document, + FieldsDocument, + Header, + TextDocument, +} from '../types' import { FieldsDisplay } from './FieldDisplay' +type SetConditionalFunc = ( + srcKey: string, + sheetKey: string, + condKey: string, + value: number +) => void + export function DocumentDisplay({ document, bgt = 'normal', collapse = false, + setConditional, }: { document: Document bgt?: CardBackgroundColor collapse?: boolean + setConditional: SetConditionalFunc }) { switch (document.type) { case 'fields': @@ -28,16 +46,16 @@ export function DocumentDisplay({ ) case 'conditional': - return null //TODO: - // return ( - // - // ) + return ( + + ) default: return null } @@ -136,3 +154,88 @@ export function HeaderDisplay({ ) } + +function ConditionalDisplay({ + conditional, + bgt = 'normal', + setConditional, +}: { + conditional: Conditional + bgt?: CardBackgroundColor + setConditional: SetConditionalFunc +}) { + const { header, fields } = conditional + return ( + + {!!header && } + + {!!fields && } + + ) +} +function ConditionalSelector({ + conditional, + setConditional, +}: { + conditional: Conditional + setConditional: SetConditionalFunc +}) { + switch (conditional.metadata.type) { + case 'bool': + return ( + + ) + //TODO: case 'list' and 'num' + default: + return null + } +} +function BoolConditional({ + conditional, + setConditional, +}: { + conditional: Conditional + setConditional: SetConditionalFunc +}) { + const calc = useContext(CalcContext) + const { label, badge } = conditional + const { sheet: sheetKey, name: condKey } = conditional.metadata + if (!sheetKey || !condKey) throw new Error('metadata missing') + const srcKey = 'all' + const conditionalValue = calc?.compute( + read( + { + et: 'own', + qt: 'cond', + sheet: sheetKey, + q: condKey, + src: srcKey, + dst: calc.cache.tag.src, + }, + 'max' + ) + ).val + return ( + + ) +} diff --git a/libs/pando/ui-sheet/src/types/conditional.ts b/libs/pando/ui-sheet/src/types/conditional.ts index 9289b6637a..fa819d1307 100644 --- a/libs/pando/ui-sheet/src/types/conditional.ts +++ b/libs/pando/ui-sheet/src/types/conditional.ts @@ -1,7 +1,15 @@ -import type { Tag } from '@genshin-optimizer/pando/engine' +import type { ReactNode } from 'react' import type { Field } from './field' +import type { Header } from './header' export type Conditional = { - tag: Tag - fields: Field[] + metadata: { + // TODO: hoist IConditionalData of gi/sr meta.ts to be accessible here + type: 'bool' | 'list' | 'num' + [x: string]: string | null + } + label: ReactNode + badge?: ReactNode + header?: Header + fields?: Field[] } diff --git a/libs/sr/assets/src/index.ts b/libs/sr/assets/src/index.ts index d64fb83ed0..e137d34f47 100644 --- a/libs/sr/assets/src/index.ts +++ b/libs/sr/assets/src/index.ts @@ -8,7 +8,7 @@ import type { import chars from './gen/chars' import lightCones from './gen/lightCones' import relics from './gen/relics' -type characterAssetKey = 'icon' | 'basic_0' +type characterAssetKey = 'icon' | 'basic_0' | 'skill_0' export function characterAsset( ck: NonTrailblazerCharacterKey | TrailblazerGenderedKey, asset: characterAssetKey diff --git a/libs/sr/db/src/Types/conditional.ts b/libs/sr/db/src/Types/conditional.ts index 49b12a3f7c..6f20136e13 100644 --- a/libs/sr/db/src/Types/conditional.ts +++ b/libs/sr/db/src/Types/conditional.ts @@ -4,15 +4,15 @@ import type { RelicSetKey, } from '@genshin-optimizer/sr/consts' -export type CondKey = CharacterKey | RelicSetKey | LightConeKey +type SheetKey = CharacterKey | RelicSetKey | LightConeKey // Stored per-char loadout, so the dst is assumed to be the owning char -// CharKey is the srcKey -// CondKey is the SheetKey -// key is the condKey +// CharKey|'all' is the srcKey +// SheetKey is the SheetKey +// condkey is the condKey // value is the condValue export type ConditionalValues = Partial< Record< CharacterKey | 'all', - Partial> + Partial> > > diff --git a/libs/sr/formula-ui/src/char/sheets/RuanMei.tsx b/libs/sr/formula-ui/src/char/sheets/RuanMei.tsx index 52ba8c9004..c780e4c04c 100644 --- a/libs/sr/formula-ui/src/char/sheets/RuanMei.tsx +++ b/libs/sr/formula-ui/src/char/sheets/RuanMei.tsx @@ -1,7 +1,8 @@ +import { ImgIcon, SqBadge } from '@genshin-optimizer/common/ui' import type { UISheet } from '@genshin-optimizer/pando/ui-sheet' import { characterAsset } from '@genshin-optimizer/sr/assets' import type { CharacterKey } from '@genshin-optimizer/sr/consts' -import { formulas, own } from '@genshin-optimizer/sr/formula' +import { conditionals, formulas, own } from '@genshin-optimizer/sr/formula' import { getInterpolateObject } from '@genshin-optimizer/sr/stats' import { trans } from '../../util' import type { TalentSheetElementKey } from '../consts' @@ -33,6 +34,35 @@ const sheet: UISheet = { }, ], }, + skill: { + name: chg('abilities.skill.0.name'), + img: characterAsset(key, 'skill_0'), + documents: [ + { + type: 'text', + text: (calculator) => { + const basicLevel = calculator.compute(own.char.basic).val + return chg( + `abilities.skill.0.fullDesc`, + getInterpolateObject(key, 'skill', basicLevel) + ) + }, + }, + { + type: 'conditional', + conditional: { + header: { + icon: , + text: 'skill active', + additional: Skill, + }, + metadata: conditionals.RuanMei.skillOvertone, + label: 'Overtone', + fields: [{ title: 'Duration', fieldValue: 3 }], + }, + }, + ], + }, } export default sheet diff --git a/libs/sr/page-team/src/TeammateDisplay/Tabs/TalentContent.tsx b/libs/sr/page-team/src/TeammateDisplay/Tabs/TalentContent.tsx index a496d14126..2b7f262b00 100644 --- a/libs/sr/page-team/src/TeammateDisplay/Tabs/TalentContent.tsx +++ b/libs/sr/page-team/src/TeammateDisplay/Tabs/TalentContent.tsx @@ -4,7 +4,7 @@ import { DropdownButton, NextImage, } from '@genshin-optimizer/common/ui' -import { range } from '@genshin-optimizer/common/util' +import { layeredAssignment, range } from '@genshin-optimizer/common/util' import type { UISheetElement } from '@genshin-optimizer/pando/ui-sheet' import { DocumentDisplay } from '@genshin-optimizer/pando/ui-sheet' import { maxEidolonCount } from '@genshin-optimizer/sr/consts' @@ -14,7 +14,11 @@ import { useSrCalcContext, type TalentSheetElementKey, } from '@genshin-optimizer/sr/formula-ui' -import { useLoadoutContext } from '@genshin-optimizer/sr/ui' +import { + LoadoutContext, + useDatabaseContext, + useLoadoutContext, +} from '@genshin-optimizer/sr/ui' import { Box, CardActionArea, @@ -26,7 +30,7 @@ import { useTheme, } from '@mui/material' import type { ReactNode } from 'react' -import { useCallback } from 'react' +import { useCallback, useContext } from 'react' import { useTranslation } from 'react-i18next' const talentSpacing = { @@ -86,7 +90,6 @@ export default function CharacterTalentPane() { // ] // ) const characterSheet = uiSheets[characterKey] - console.log({ characterSheet, calc }) if (!characterSheet || !calc) return return ( <> @@ -278,6 +281,23 @@ function SkillDisplayCard({ // return false // } + const { loadoutId } = useContext(LoadoutContext) + const { database } = useDatabaseContext() + const setConditional = useCallback( + (srcKey: string, sheetKey: string, condKey: string, condValue: number) => { + database.loadouts.set(loadoutId, (loadout) => { + loadout = structuredClone(loadout) + layeredAssignment( + loadout.conditional, + [srcKey, sheetKey, condKey], + condValue + ) + return loadout + }) + }, + [database, loadoutId] + ) + return ( {header} @@ -307,6 +327,7 @@ function SkillDisplayCard({ document={doc} collapse // hideHeader={hideHeader} + setConditional={setConditional} /> ))}