Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tc opt 2 with feasibility check #1424

Merged
merged 6 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ type Data = {
setNumKey: SetNum
hideHeader?: boolean
conditionalsOnly?: boolean
disabled?: boolean
}

export default function SetEffectDisplay({
setKey,
setNumKey,
hideHeader = false,
conditionalsOnly = false,
disabled = false,
}: Data) {
const sheet = getArtSheet(setKey)

Expand All @@ -27,7 +29,11 @@ export default function SetEffectDisplay({
return (
<Box display="flex" flexDirection="column">
{document ? (
<DocumentDisplay sections={document} hideHeader={hideHeader} />
<DocumentDisplay
sections={document}
hideHeader={hideHeader}
disabled={disabled}
/>
) : null}
</Box>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ type ConditionalDisplayProps = {
conditional: DocumentConditional
hideHeader?: boolean | ((section: DocumentSection) => boolean)
hideDesc?: boolean
disabled?: boolean
}

export default function ConditionalDisplay({
conditional,
hideHeader = false,
hideDesc = false,
disabled = false,
}: ConditionalDisplayProps) {
const { data } = useContext(DataContext)
let fields
Expand All @@ -38,7 +40,7 @@ export default function ConditionalDisplay({
<HeaderDisplay header={conditional.header} hideDesc={hideDesc} />
)}
<CardContent sx={{ p: 0, '&:last-child': { pb: 0 } }}>
<ConditionalSelector conditional={conditional} />
<ConditionalSelector conditional={conditional} disabled={disabled} />
</CardContent>
{fields && <FieldsDisplay fields={fields} />}
</CardDark>
Expand Down
6 changes: 6 additions & 0 deletions apps/frontend/src/app/Components/DocumentDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ type DocumentDisplayProps = {
teamBuffOnly?: boolean
hideDesc?: boolean
hideHeader?: boolean | ((section: DocumentSection) => boolean)
disabled?: boolean
}

export default function DocumentDisplay({
sections,
teamBuffOnly,
hideDesc = false,
hideHeader = false,
disabled = false,
}: DocumentDisplayProps) {
const { data } = useContext(DataContext)
if (!sections.length) return null
Expand All @@ -41,6 +43,7 @@ export default function DocumentDisplay({
key={i}
hideDesc={hideDesc}
hideHeader={hideHeader}
disabled={disabled}
/>
)
})
Expand All @@ -57,10 +60,12 @@ function SectionDisplay({
section,
hideDesc = false,
hideHeader = false,
disabled = false,
}: {
section: DocumentSection
hideDesc?: boolean
hideHeader?: boolean | ((section: DocumentSection) => boolean)
disabled?: boolean
}) {
if ('fields' in section) {
return (
Expand All @@ -76,6 +81,7 @@ function SectionDisplay({
conditional={section}
hideDesc={hideDesc}
hideHeader={hideHeader}
disabled={disabled}
/>
)
} /* if ("text" in section) */ else {
Expand Down
13 changes: 11 additions & 2 deletions apps/frontend/src/app/Components/LevelSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export default function LevelSelect({
ascension,
setBoth,
useLow = false,
disabled = false,
}: {
level: number
ascension: AscensionKey
setBoth: (action: { level?: number; ascension?: AscensionKey }) => void
useLow?: boolean
disabled?: boolean
}) {
const { t } = useTranslation('ui')
const ascensionMaxLevels = useLow ? ascensionMaxLevelLow : ascensionMaxLevel
Expand Down Expand Up @@ -56,6 +58,7 @@ export default function LevelSelect({
onChange={setLevel}
value={level}
startAdornment="Lv. "
disabled={disabled}
inputProps={{
min: 1,
max: 90,
Expand All @@ -66,12 +69,18 @@ export default function LevelSelect({
</CustomNumberInputButtonGroupWrapper>
<Button
sx={{ pl: 1, whiteSpace: 'nowrap' }}
disabled={!(useLow ? ambiguousLevelLow : ambiguousLevel)(level)}
disabled={
!(useLow ? ambiguousLevelLow : ambiguousLevel)(level) || disabled
}
onClick={setAscension}
>
<strong>/ {ascensionMaxLevel[ascension]}</strong>
</Button>
<DropdownButton title={t('selectlevel')} sx={{ flexGrow: 1 }}>
<DropdownButton
title={t('selectlevel')}
sx={{ flexGrow: 1 }}
disabled={disabled}
>
{[...(useLow ? milestoneLevelsLow : milestoneLevels)].map(
([lv, as]) => {
const selected = lv === level && as === ascension
Expand Down
7 changes: 6 additions & 1 deletion apps/frontend/src/app/Components/RefinementDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ import DropdownButton from './DropdownMenu/DropdownButton'
export default function RefinementDropdown({
refinement,
setRefinement,
disabled = false,
}: {
refinement: RefinementKey
setRefinement: (r: RefinementKey) => void
disabled?: boolean
}) {
const { t } = useTranslation('ui')
return (
<DropdownButton title={t('refinement', { value: refinement })}>
<DropdownButton
title={t('refinement', { value: refinement })}
disabled={disabled}
>
{allRefinementKeys.map((r) => (
<MenuItem
key={r}
Expand Down
31 changes: 21 additions & 10 deletions apps/frontend/src/app/Database/DataManagers/CharacterTCData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,32 @@ import type {
ArtifactSlotKey,
CharacterKey,
MainStatKey,
SubstatKey,
WeaponKey,
} from '@genshin-optimizer/consts'
import {
allArtifactRarityKeys,
allArtifactSlotKeys,
allSubstatKeys,
allWeaponKeys,
substatTypeKeys,
substatTypeKeys
} from '@genshin-optimizer/consts'
import { validateLevelAsc } from '@genshin-optimizer/gi-util'
import { objKeyMap } from '@genshin-optimizer/util'
import type { ICharTC } from '../../Types/character'
import type { ArtCharDatabase } from '../Database'
import { DataManager } from '../DataManager'
import type { ArtCharDatabase } from '../Database'

export type MinTotalStatKey = Exclude<SubstatKey, 'hp_' | 'atk_' | 'def_'>
export const minTotalStatKeys: MinTotalStatKey[] = [
'atk',
'hp',
'def',
'eleMas',
'enerRech_',
'critRate_',
'critDMG_',
]

export class CharacterTCDataManager extends DataManager<
CharacterKey,
Expand Down Expand Up @@ -85,7 +97,7 @@ export function initCharTC(weaponKey: WeaponKey): ICharTC {
target: undefined,
distributedSubstats: 45,
maxSubstats: initCharTcOptimizationMaxSubstats(),
minTotal: initCharTcOptimizationMinTotal(),
minTotal: {},
},
}
}
Expand Down Expand Up @@ -166,11 +178,13 @@ function validateCharTcOptimization(
maxSubstats = objKeyMap([...allSubstatKeys], (k) =>
typeof maxSubstats[k] === 'number' ? maxSubstats[k] : 0
)
if (typeof minTotal !== 'object')
minTotal = initCharTcOptimizationMaxSubstats()
minTotal = objKeyMap([...allSubstatKeys], (k) =>
typeof minTotal[k] === 'number' ? minTotal[k] : 0
if (typeof minTotal !== 'object') minTotal = {}
minTotal = Object.fromEntries(
Object.entries(minTotal).filter(
([k, v]) => minTotalStatKeys.includes(k) && typeof v === 'number'
)
)

return { target, distributedSubstats, maxSubstats, minTotal }
}
function initCharTcOptimizationMaxSubstats(): ICharTC['optimization']['maxSubstats'] {
Expand All @@ -179,6 +193,3 @@ function initCharTcOptimizationMaxSubstats(): ICharTC['optimization']['maxSubsta
(k) => 6 * (k === 'hp' || k === 'atk' ? 4 : k === 'atk_' ? 2 : 5)
)
}
function initCharTcOptimizationMinTotal(): ICharTC['optimization']['minTotal'] {
return objKeyMap(allSubstatKeys, () => 0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import { CharTCContext } from '../CharTCContext'

export function ArtifactMainLevelSlot({
slotKey,
disabled = false,
}: {
slotKey: ArtifactSlotKey
disabled?: boolean
}) {
const {
charTC: {
Expand Down Expand Up @@ -82,6 +84,7 @@ export function ArtifactMainLevelSlot({
fullWidth
title={<StatWithUnit statKey={statKey} />}
color={KeyMap.getVariant(statKey) ?? 'success'}
disabled={disabled}
>
{keys.map((msk) => (
<MenuItem
Expand All @@ -102,6 +105,7 @@ export function ArtifactMainLevelSlot({
{rarity} <StarRoundedIcon fontSize="inherit" />
</Box>
}
disabled={disabled}
>
{[5, 4, 3].map((r) => (
<MenuItem
Expand All @@ -122,6 +126,7 @@ export function ArtifactMainLevelSlot({
onChange={(l) => l !== undefined && setSlot({ level: l })}
sx={{ borderRadius: 1, pl: 1, my: 0, height: '100%' }}
inputProps={{ sx: { pl: 0.5, width: '2em' }, max: 20, min: 0 }}
disabled={disabled}
/>
<CardDark sx={{ height: '100%', minWidth: '4em' }}>
<Box p={1} textAlign="center">{`${artDisplayValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import { CharTCContext } from '../CharTCContext'
export function ArtifactSetEditor({
setKey,
remaining,
disabled = false,
}: {
setKey: ArtifactSetKey
remaining: number
disabled?: boolean
}) {
const {
charTC: {
Expand Down Expand Up @@ -66,6 +68,7 @@ export function ArtifactSetEditor({
<DropdownButton
size="small"
title={<Box whiteSpace="nowrap">{value}-set</Box>}
disabled={disabled}
>
{Object.keys(artifactSheet.setEffects)
.map((setKey) => parseInt(setKey))
Expand All @@ -79,7 +82,12 @@ export function ArtifactSetEditor({
</MenuItem>
))}
</DropdownButton>
<Button color="error" size="small" onClick={deleteValue}>
<Button
color="error"
size="small"
onClick={deleteValue}
disabled={disabled}
>
<DeleteForever />
</Button>
</ButtonGroup>
Expand All @@ -93,6 +101,7 @@ export function ArtifactSetEditor({
setNumKey={parseInt(setNumKey) as SetNum}
hideHeader
conditionalsOnly
disabled={disabled}
/>
))}
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { getArtSheet } from '../../../../../Data/Artifacts'
import { ArtifactSetEditor } from './ArtifactSetEditor'
import { CharTCContext } from '../CharTCContext'

export function ArtifactSetsEditor() {
export function ArtifactSetsEditor({
disabled = false,
}: {
disabled?: boolean
}) {
const {
charTC: {
artifact: { sets: artSet },
Expand Down Expand Up @@ -35,6 +39,7 @@ export function ArtifactSetsEditor() {
key={setKey}
setKey={setKey as ArtifactSetKey}
remaining={remaining}
disabled={disabled}
/>
))}
<CardLight sx={{ flexGrow: 1, overflow: 'visible' }}>
Expand All @@ -49,6 +54,7 @@ export function ArtifactSetsEditor() {
(n) => parseInt(n) > remaining
)
}
disabled={disabled}
/>
</CardLight>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ import CardLight from '../../../../../Components/Card/CardLight'
import { ArtifactMainLevelSlot } from './ArtifactMainLevelSlot'
import { ArtifactSetsEditor } from './ArtifactSetsEditor'

export function ArtifactMainStatAndSetEditor() {
export function ArtifactMainStatAndSetEditor({
disabled = false,
}: {
disabled?: boolean
}) {
return (
<Stack spacing={1}>
<CardLight sx={{ p: 1 }}>
<Stack spacing={1}>
{allArtifactSlotKeys.map((s) => (
<ArtifactMainLevelSlot key={s} slotKey={s} />
<ArtifactMainLevelSlot key={s} slotKey={s} disabled={disabled} />
))}
</Stack>
</CardLight>
<Suspense
fallback={<Skeleton variant="rectangular" width="100%" height={200} />}
>
<ArtifactSetsEditor />
<ArtifactSetsEditor disabled={disabled} />
</Suspense>
</Stack>
)
Expand Down
Loading
Loading