Skip to content

Commit f799156

Browse files
authored
Merge pull request #259 from Gemini2035/feat/sortByRarity
Feat/sort by rarity
2 parents 053840b + 1b5d093 commit f799156

File tree

5 files changed

+512
-16
lines changed

5 files changed

+512
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"linkifyjs": "^3.0.5",
4545
"lodash-es": "^4.17.21",
4646
"normalize.css": "^8.0.1",
47+
"prettier": "^3.2.5",
4748
"react": "^18.0.0",
4849
"react-dom": "^18.0.0",
4950
"react-hook-form": "^7.33.1",
@@ -82,7 +83,6 @@
8283
"node-fetch": "^3.2.6",
8384
"npm-run-all2": "^6.0.2",
8485
"pinyin": "^3.0.0-alpha.5",
85-
"prettier": "^2.7.1",
8686
"simplebig": "^0.0.3",
8787
"tailwindcss": "^3.1.4",
8888
"typescript": "^4.6.3",

scripts/shared.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,15 @@ export async function getOperators() {
108108
})
109109
}
110110
}
111-
112111
return [
113112
{
114113
id: id,
115114
subProf: op.subProfessionId,
116115
...transformOperatorName(op.name),
116+
rarity:
117+
op.subProfessionId === 'notchar1'
118+
? 0
119+
: Number(op.rarity?.split('TIER_').join('') || 0),
117120
alt_name: op.appellation,
118121
},
119122
]

scripts/update-operators.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { writeFile } from 'node:fs/promises'
2-
import process from 'process'
32
import * as prettier from 'prettier'
3+
import process from 'process'
44

55
import { getOperators } from './shared'
66

@@ -14,7 +14,8 @@ async function main() {
1414
})
1515

1616
const prettierConfig = await prettier.resolveConfig(process.cwd())
17-
const formatted = prettier.format(content, {
17+
console.log(prettierConfig)
18+
const formatted = await prettier.format(content, {
1819
...prettierConfig,
1920
parser: 'json',
2021
})

src/components/editor/operator/sheet/SheetOperator.tsx

Lines changed: 129 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Alert, Button, Divider, H4, H5, H6, Intent } from '@blueprintjs/core'
2+
import { Popover2 } from '@blueprintjs/popover2'
3+
import { POPOVER2_DISMISS } from '@blueprintjs/popover2/lib/esm/classes'
24

35
import clsx from 'clsx'
46
import { useAtom } from 'jotai'
@@ -61,6 +63,9 @@ const formattedProfessions = [
6163
]
6264

6365
const paginationSize = 60
66+
const defaultRarityFilter = Array.from(
67+
new Array(Math.max(...OPERATORS.map(({ rarity }) => rarity)) + 1).keys(),
68+
).slice(Math.min(...OPERATORS.map(({ rarity }) => rarity)))
6469

6570
const SheetOperator = ({
6671
submitOperator,
@@ -72,6 +77,8 @@ const SheetOperator = ({
7277

7378
const [selectedProf, setSelectedProf] = useState(formattedProfessions[0])
7479
const [selectedSubProf, setSelectedSubProf] = useState(defaultSubProf[0])
80+
const [operatorRarity, setOperatorRarity] = useState(defaultRarityFilter)
81+
const [rarityReverse, setRarityReverse] = useState(false)
7582
const [favOperators, setFavOperators] = useAtom(favOperatorAtom)
7683
const [coverOperator, setCoverOperator] = useState<Operator>()
7784

@@ -90,6 +97,7 @@ const SheetOperator = ({
9097
return {
9198
name,
9299
subProf: '',
100+
rarity: 0,
93101
}
94102
}),
95103
...OPERATORS,
@@ -157,17 +165,43 @@ const SheetOperator = ({
157165
}
158166
}
159167

168+
const getOperatorRarity = (target: string) =>
169+
operatorsGroupedByProf.find((item) => item.name === target)!.rarity
170+
160171
const operatorsGroupedBySubProf = useMemo(() => {
161-
if (selectedSubProf.id === 'all') return operatorsGroupedByProf
172+
let result: Operator[] = []
173+
if (selectedSubProf.id === 'all') result = operatorsGroupedByProf
162174
else if (selectedSubProf.id === 'selected')
163-
return operatorsGroupedByProf.filter((item) =>
175+
result = operatorsGroupedByProf.filter((item) =>
164176
checkOperatorSelected(item.name),
165177
)
166178
else
167-
return operatorsGroupedByProf.filter(
179+
result = operatorsGroupedByProf.filter(
168180
(item) => item.subProf === selectedSubProf.id,
169181
)
170-
}, [selectedSubProf, operatorsGroupedByProf, checkOperatorSelected])
182+
183+
result = result
184+
.filter(({ name }) => {
185+
return (
186+
operatorRarity.findIndex(
187+
(rarity) => getOperatorRarity(name) === rarity,
188+
) !== -1
189+
)
190+
})
191+
.sort(
192+
({ name: aName }, { name: bName }) =>
193+
getOperatorRarity(bName) - getOperatorRarity(aName),
194+
)
195+
196+
return rarityReverse ? result.reverse() : result
197+
}, [
198+
selectedSubProf,
199+
operatorsGroupedByProf,
200+
checkOperatorSelected,
201+
operatorRarity,
202+
rarityReverse,
203+
getOperatorRarity,
204+
])
171205

172206
const operatorSelectHandle: OperatorModifyProps['operatorSelectHandle'] = (
173207
operatorName,
@@ -227,6 +261,20 @@ const SheetOperator = ({
227261

228262
const ActionList = (
229263
<div className="absolute bottom-0">
264+
<Popover2
265+
content={
266+
<RaritySelector
267+
{...{
268+
operatorRarity,
269+
setOperatorRarity,
270+
rarityReverse,
271+
setRarityReverse,
272+
}}
273+
/>
274+
}
275+
>
276+
<Button minimal icon="filter-list" />
277+
</Popover2>
230278
<Button
231279
minimal
232280
icon="circle"
@@ -321,6 +369,7 @@ const SheetOperator = ({
321369
className={clsx(
322370
'truncate cursor-pointer my-3 opacity-50 hover:underline hover:opacity-90',
323371
subProf.id === selectedSubProf.id && '!opacity-100 underline',
372+
subProf.name.length > 3 && '!text-base',
324373
)}
325374
onClick={() => setSelectedSubProf(subProf)}
326375
>
@@ -351,7 +400,7 @@ const SheetOperator = ({
351400
)
352401
return (
353402
<div
354-
className="flex items-center w-32 h-32 flex-0"
403+
className="flex items-center flex-0 w-32 h-32"
355404
key={index}
356405
>
357406
<OperatorItem
@@ -401,6 +450,81 @@ const SheetOperator = ({
401450
)
402451
}
403452

453+
const RaritySelector = ({
454+
operatorRarity,
455+
setOperatorRarity,
456+
rarityReverse,
457+
setRarityReverse,
458+
}: {
459+
operatorRarity: number[]
460+
setOperatorRarity: (target: number[]) => void
461+
rarityReverse: boolean
462+
setRarityReverse: (target: boolean) => void
463+
}) => {
464+
const selectClass = 'scale-90'
465+
const [rarity, setRarity] = useState<number[]>(operatorRarity)
466+
const [reverse, setReverse] = useState<boolean>(rarityReverse)
467+
468+
const resetFilter = () => {
469+
setRarity(defaultRarityFilter)
470+
setReverse(false)
471+
}
472+
const submitFilter = () => {
473+
setOperatorRarity(rarity)
474+
setRarityReverse(reverse)
475+
}
476+
477+
return (
478+
<div>
479+
<div className="flex items-center">
480+
<H5 className="m-0 mr-1">按干员稀有度展示</H5>
481+
<Button icon="reset" minimal title="重置选择" onClick={resetFilter} />
482+
</div>
483+
<div className="flex my-1">
484+
{Array(7)
485+
.fill(0)
486+
.map((_, index) => {
487+
const isSelect = rarity.findIndex((item) => item === index) !== -1
488+
return (
489+
<Button
490+
key={index}
491+
active={isSelect}
492+
text={index}
493+
minimal
494+
className={clsx(isSelect && selectClass)}
495+
onClick={() =>
496+
isSelect
497+
? setRarity([...rarity].filter((item) => item !== index))
498+
: setRarity([...rarity, index])
499+
}
500+
/>
501+
)
502+
})}
503+
</div>
504+
<div className="flex">
505+
<Button
506+
minimal
507+
icon="arrow-up"
508+
className={clsx(!reverse && selectClass)}
509+
active={!reverse}
510+
onClick={() => setReverse(false)}
511+
title="按从下至上升序排列"
512+
/>
513+
<Button
514+
minimal
515+
icon="arrow-down"
516+
className={clsx(reverse && selectClass)}
517+
active={reverse}
518+
onClick={() => setReverse(true)}
519+
title="按从下至上降序排列"
520+
/>
521+
</div>
522+
<Divider />
523+
<Button text="确认" className={POPOVER2_DISMISS} onClick={submitFilter} />
524+
</div>
525+
)
526+
}
527+
404528
export const SheetOperatorContainer = (
405529
sheetOperatorProp: SheetOperatorProps,
406530
) => (

0 commit comments

Comments
 (0)