Skip to content

Commit

Permalink
feat: pre-compatible with Genshin's anthology gacha
Browse files Browse the repository at this point in the history
  • Loading branch information
lgou2w committed Mar 9, 2024
1 parent 19c5a5b commit e7aada5
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src-tauri/src/gacha/uigf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ impl UIGF {
* 302 | 302
*/
pub static GACHA_TYPE_UIGF_MAPPINGS: Lazy<HashMap<&str, &str>> = Lazy::new(|| {
let mut m = HashMap::with_capacity(5);
let mut m = HashMap::with_capacity(6);
m.insert("100", "100");
m.insert("200", "200");
m.insert("301", "301");
m.insert("400", "301"); // 400 -> 301
m.insert("302", "302");
m.insert("500", "500");
m
});

Expand Down
5 changes: 4 additions & 1 deletion src/components/gacha/analysis/GachaAnalysisHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Divider from '@mui/material/Divider'

export default function GachaAnalysisHistory () {
const { facet, gachaRecords } = useGachaLayoutContext()
const { namedValues: { character, weapon, permanent, newbie } } = gachaRecords
const { namedValues: { character, weapon, permanent, newbie, anthology } } = gachaRecords

return (
<Box>
Expand All @@ -26,6 +26,9 @@ export default function GachaAnalysisHistory () {
<Stack direction="column" spacing={2}>
<GachaAnalysisHistoryList facet={facet} value={character} />
<GachaAnalysisHistoryList facet={facet} value={weapon} />
{anthology && anthology.metadata.golden.sum > 0 && (
<GachaAnalysisHistoryList facet={facet} value={anthology} />
)}
<GachaAnalysisHistoryList facet={facet} value={permanent} />
{newbie.metadata.golden.sum > 0 && (
<GachaAnalysisHistoryList facet={facet} value={newbie} />
Expand Down
3 changes: 2 additions & 1 deletion src/components/gacha/analysis/GachaAnalysisSum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Typography from '@mui/material/Typography'

export default function GachaAnalysisSum () {
const { gachaRecords } = useGachaLayoutContext()
const { namedValues: { character, weapon, permanent, newbie }, aggregatedValues } = gachaRecords
const { namedValues: { character, weapon, permanent, newbie, anthology }, aggregatedValues } = gachaRecords

return (
<Box className={GachaAnalysisSumCls} sx={GachaAnalysisSumSx}>
Expand All @@ -25,6 +25,7 @@ export default function GachaAnalysisSum () {
/>
<GachaAnalysisSumCol title={character.categoryTitle} values={computeNamedGachaRecordsValues(character)} />
<GachaAnalysisSumCol title={weapon.categoryTitle} values={computeNamedGachaRecordsValues(weapon)} />
{anthology && anthology.total > 0 && <GachaAnalysisSumCol title={anthology.categoryTitle} values={computeNamedGachaRecordsValues(anthology)} />}
<GachaAnalysisSumCol title={permanent.categoryTitle} values={computeNamedGachaRecordsValues(permanent)} />
{newbie.total > 0 && <GachaAnalysisSumCol title={newbie.categoryTitle} values={computeNamedGachaRecordsValues(newbie)} />}
<GachaAnalysisSumCol title="合计" values={computeNamedGachaRecordsValues(aggregatedValues)} />
Expand Down
3 changes: 0 additions & 3 deletions src/components/gacha/chart/GachaChartCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,8 @@ export default function GachaChartCalendar () {
}}
tooltip={({ color, day, value }) => (
<Box component={Paper}
position="absolute"
bgcolor="white"
width={120}
top={0}
right="0.5rem"
paddingY={0.5}
paddingX={1}
elevation={5}
Expand Down
18 changes: 11 additions & 7 deletions src/components/gacha/chart/GachaChartPie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Box from '@mui/material/Box'
import Typography from '@mui/material/Typography'

export default function GachaChartCalendar () {
const { facet, gachaRecords: { aggregatedValues, namedValues: { character, weapon, permanent, newbie } } } = useGachaLayoutContext()
const { facet, gachaRecords: { aggregatedValues, namedValues: { character, weapon, permanent, newbie, anthology } } } = useGachaLayoutContext()

const itemTypesData = aggregatedValues.values.reduce((acc, cur) => {
const key = cur.item_type
Expand All @@ -25,6 +25,7 @@ export default function GachaChartCalendar () {
<Typography variant="h6" gutterBottom>❖ 多维饼图</Typography>
<Grid container>
<Grid sm={4} item>
<Typography variant="subtitle1" textAlign="center" gutterBottom>➤ 星级</Typography>
<Box width="100%" height={256}>
<ResponsivePie
{...PieProps}
Expand All @@ -37,6 +38,7 @@ export default function GachaChartCalendar () {
</Box>
</Grid>
<Grid sm={4} item>
<Typography variant="subtitle1" textAlign="center" gutterBottom>➤ 类别</Typography>
<Box width="100%" height={256}>
<ResponsivePie
{...PieProps}
Expand All @@ -51,19 +53,21 @@ export default function GachaChartCalendar () {
</Box>
</Grid>
<Grid sm={4} item>
<Typography variant="subtitle1" textAlign="center" gutterBottom>➤ 卡池</Typography>
<Box width="100%" height={256} overflow="hidden">
<ResponsivePie
{...PieProps}
arcLabelsSkipAngle={10}
arcLinkLabelsSkipAngle={10}
data={[
{ id: '角色池', value: character.total },
{ id: '角色', value: character.total },
{
id: facet === AccountFacet.Genshin ? '武器池' : '光锥池',
id: facet === AccountFacet.Genshin ? '武器' : '光锥',
value: weapon.total
},
{ id: '常驻池', value: permanent.total },
{ id: '新手池', value: newbie.total }
{ id: '常驻', value: permanent.total },
{ id: '新手', value: newbie.total },
...(anthology ? [{ id: '集录', value: anthology.total }] : [])
]}
/>
</Box>
Expand All @@ -81,7 +85,7 @@ const PieProps: Partial<PieSvgProps<MayHaveLabel & Record<string, unknown>>> = {
}
},
margin: { top: 36, right: 36, bottom: 60, left: 36 },
colors: ['#0288d188', '#9c27b088', '#ed6c0288', '#f4433688'],
colors: ['#0288d188', '#9c27b088', '#ed6c0288', '#f4433688', '#003cff88'],
fill: [{ id: 'lines', match: '*' }],
defs: [
{
Expand All @@ -100,7 +104,7 @@ const PieProps: Partial<PieSvgProps<MayHaveLabel & Record<string, unknown>>> = {
direction: 'row',
translateY: 56,
translateX: 0,
itemWidth: 72,
itemWidth: 64,
itemHeight: 14,
symbolSize: 14,
symbolShape: 'square'
Expand Down
10 changes: 8 additions & 2 deletions src/components/gacha/overview/GachaOverviewGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import dayjs from '@/utilities/dayjs'

export default function GachaOverviewGrid () {
const { facet, gachaRecords } = useGachaLayoutContext()
const { namedValues: { character, weapon, permanent, newbie }, aggregatedValues } = gachaRecords
const { namedValues: { character, weapon, permanent, newbie, anthology }, aggregatedValues } = gachaRecords
const hasAnthology = !!anthology && anthology.total > 0

return (
<Box>
Expand All @@ -27,7 +28,12 @@ export default function GachaOverviewGrid () {
<Grid xs={6} item>
<GachaOverviewGridCard facet={facet} value={permanent} />
</Grid>
<Grid xs={6} item>
{hasAnthology && (
<Grid xs={6} item>
<GachaOverviewGridCard facet={facet} value={anthology} />
</Grid>
)}
<Grid xs={hasAnthology ? 12 : 6} item>
<GachaOverviewGridCard facet={facet} value={aggregatedValues} newbie={newbie} />
</Grid>
</Grid>
Expand Down
37 changes: 30 additions & 7 deletions src/hooks/useGachaRecordsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ export interface GachaRecords {
readonly uid: Account['uid']
readonly gachaTypeToCategoryMappings: Record<GachaRecord['gacha_type'], NamedGachaRecords['category']>
readonly values: Partial<Record<GachaRecord['gacha_type'], GachaRecord[]>>
readonly namedValues: Record<NamedGachaRecords['category'], NamedGachaRecords>
readonly namedValues: Omit<Record<NamedGachaRecords['category'], NamedGachaRecords>, 'anthology'>
& { 'anthology'?: NamedGachaRecords } // Genshin Impact only
readonly aggregatedValues: Omit<NamedGachaRecords, 'category' | 'categoryTitle' | 'gachaType' | 'lastEndId'>
readonly total: number
readonly firstTime?: GachaRecord['time']
readonly lastTime?: GachaRecord['time']
}

export interface NamedGachaRecords {
category: 'newbie' | 'permanent' | 'character' | 'weapon'
category: 'newbie' | 'permanent' | 'character' | 'weapon' | 'anthology'
categoryTitle: string
gachaType: GachaRecord['gacha_type']
lastEndId?: GachaRecord['id']
Expand Down Expand Up @@ -144,7 +145,8 @@ const KnownGenshinGachaTypes: Record<GenshinGachaRecord['gacha_type'], NamedGach
100: 'newbie',
200: 'permanent',
301: 'character', // include 400
302: 'weapon'
302: 'weapon',
500: 'anthology'
}

const KnownStarRailGachaTypes: Record<StarRailGachaRecord['gacha_type'], NamedGachaRecords['category']> = {
Expand All @@ -156,12 +158,14 @@ const KnownStarRailGachaTypes: Record<StarRailGachaRecord['gacha_type'], NamedGa

const KnownCategoryTitles: Record<AccountFacet, Record<NamedGachaRecords['category'], string>> = {
[AccountFacet.Genshin]: {
anthology: '集录',
character: '角色活动',
weapon: '武器活动',
permanent: '常驻',
newbie: '新手'
},
[AccountFacet.StarRail]: {
anthology: '', // Useless
character: '角色活动',
weapon: '光锥活动',
permanent: '常驻',
Expand Down Expand Up @@ -236,22 +240,41 @@ function computeAggregatedGachaRecords (
const total = data.length
const firstTime = data[0]?.time
const lastTime = data[total - 1]?.time
const { newbie, permanent, character, weapon } = namedValues
const { newbie, permanent, character, weapon, anthology } = namedValues

const blueSum =
newbie.metadata.blue.sum +
permanent.metadata.blue.sum +
character.metadata.blue.sum +
weapon.metadata.blue.sum +
(anthology ? anthology.metadata.blue.sum : 0)

const blueSum = newbie.metadata.blue.sum + permanent.metadata.blue.sum + character.metadata.blue.sum + weapon.metadata.blue.sum
const blueSumPercentage = blueSum > 0 ? Math.round(blueSum / total * 10000) / 100 : 0
const blueValues = data.filter(isRankTypeOfBlue)

const purpleSum = newbie.metadata.purple.sum + permanent.metadata.purple.sum + character.metadata.purple.sum + weapon.metadata.purple.sum
const purpleSum =
newbie.metadata.purple.sum +
permanent.metadata.purple.sum +
character.metadata.purple.sum +
weapon.metadata.purple.sum +
(anthology ? anthology.metadata.purple.sum : 0)

const purpleSumPercentage = purpleSum > 0 ? Math.round(purpleSum / total * 10000) / 100 : 0
const purpleValues = data.filter(isRankTypeOfPurple)

const goldenSum = newbie.metadata.golden.sum + permanent.metadata.golden.sum + character.metadata.golden.sum + weapon.metadata.golden.sum
const goldenSum =
newbie.metadata.golden.sum +
permanent.metadata.golden.sum +
character.metadata.golden.sum +
weapon.metadata.golden.sum +
(anthology ? anthology.metadata.golden.sum : 0)

const goldenSumPercentage = goldenSum > 0 ? Math.round(goldenSum / total * 10000) / 100 : 0
const goldenValues = Array.from(newbie.metadata.golden.values)
.concat(Array.from(permanent.metadata.golden.values))
.concat(Array.from(character.metadata.golden.values))
.concat(Array.from(weapon.metadata.golden.values))
.concat(anthology ? Array.from(anthology.metadata.golden.values) : [])
.sort(sortGachaRecordById)

const { goldenSumRestricted, goldenUsedPitySum } = goldenValues.reduce((acc, record) => {
Expand Down

0 comments on commit e7aada5

Please sign in to comment.