Skip to content

Commit

Permalink
Merge 0d4a07e into 67e6e0b
Browse files Browse the repository at this point in the history
  • Loading branch information
frzyc authored Nov 27, 2024
2 parents 67e6e0b + 0d4a07e commit 005ac20
Show file tree
Hide file tree
Showing 17 changed files with 452 additions and 365 deletions.
26 changes: 23 additions & 3 deletions libs/sr/db/src/Database/DataManagers/TeamDataManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IConditionalData } from '@genshin-optimizer/common/formula'
import {
notEmpty,
objKeyMap,
pruneOrPadArray,
range,
Expand Down Expand Up @@ -37,14 +38,19 @@ export type TeammateDatum = {

optConfigId?: string
}
export type Frame = {
tag: Tag
multiplier: number
description?: string
}
export interface Team {
name: string
description: string

lastEdit: number

// frames, store data as a "sparse 2d array"
frames: Array<Tag>
frames: Array<Frame>
conditionals: Array<{
sheet: Sheet
src: Member
Expand All @@ -56,7 +62,11 @@ export interface Team {
tag: Tag
values: number[] // should be the same length as `frames`
}>
statConstraints: Array<{ tag: Tag; values: number[]; isMaxs: boolean[] }>
statConstraints: Array<{
tag: Tag
values: number[] // should be the same length as `frames`
isMaxs: boolean[] // should be the same length as `frames`
}>

// TODO enemy base stats
teamMetadata: Array<TeammateDatum | undefined>
Expand Down Expand Up @@ -170,7 +180,17 @@ export class TeamDataManager extends DataManager<string, 'teams', Team, Team> {
if (typeof lastEdit !== 'number') lastEdit = Date.now()

if (!Array.isArray(frames)) frames = []
frames = frames.filter(validateTag)
frames = frames
.map((f) => {
const { tag } = f
let { multiplier, description } = f
if (!validateTag(tag)) return undefined
if (typeof multiplier !== 'number' || multiplier === 0) multiplier = 1
if (typeof description !== 'string') description = undefined

return { tag, multiplier, description }
})
.filter(notEmpty)
const framesLength = frames.length
if (!framesLength) {
conditionals = []
Expand Down
4 changes: 2 additions & 2 deletions libs/sr/page-team/src/BonusStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
Stack,
} from '@mui/material'
import { useContext } from 'react'
import { PresetContext, useTeamContext } from './context'
import { PresetContext, useTeamContext, useTeammateContext } from './context'

export function BonusStats() {
const [open, onOpen, onClose] = useBoolState()
Expand All @@ -47,8 +47,8 @@ function BonusStatsModal({
const {
teamId,
team: { bonusStats },
teammateDatum: { characterKey },
} = useTeamContext()
const { characterKey } = useTeammateContext()
const newTarget = (q: InitialStats) => {
const tag = newTag(q, characterKey)
database.teams.setBonusStat(teamId, tag, 0, presetIndex)
Expand Down
12 changes: 4 additions & 8 deletions libs/sr/page-team/src/BuildsDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ import {
} from '@mui/material'
import type { ReactNode } from 'react'
import { useCallback, useEffect, useMemo, useState } from 'react'
import { useTeamContext } from './context'
import { useTeamContext, useTeammateContext } from './context'
export function BuildsDisplay({ onClose }: { onClose?: () => void }) {
const { database } = useDatabaseContext()
const {
teammateDatum: { characterKey },
} = useTeamContext()
const { characterKey } = useTeammateContext()
const [dbDirty, setDbDirty] = useForceUpdate()
const [dbTCDirty, setDbTCDirty] = useForceUpdate()
const buildIds = useMemo(
Expand Down Expand Up @@ -145,10 +143,8 @@ function useActiveBuildSwap(
newBuildId = ''
) {
const { database } = useDatabaseContext()
const {
teamId,
teammateDatum: { characterKey, buildType, buildId, buildTcId },
} = useTeamContext()
const { characterKey, buildType, buildId, buildTcId } = useTeammateContext()
const { teamId } = useTeamContext()

return useMemo(
() => ({
Expand Down
Loading

0 comments on commit 005ac20

Please sign in to comment.