2024-09-27 14:46:45 +00:00
|
|
|
import {
|
|
|
|
Group,
|
|
|
|
ProcessedOperator,
|
|
|
|
} from '@/containers/Dashboard/DashboardContainer'
|
2024-09-27 15:41:52 +00:00
|
|
|
import { Archetype } from '../types/operators'
|
2024-09-27 14:46:45 +00:00
|
|
|
|
2024-09-27 15:41:52 +00:00
|
|
|
export function processOperators(
|
|
|
|
data: Group[],
|
|
|
|
selectedArchetypes: Archetype[],
|
|
|
|
): ProcessedOperator[] {
|
|
|
|
const hasSelectedArchetypes = selectedArchetypes.length > 0
|
|
|
|
|
|
|
|
return data?.flatMap((group) => {
|
|
|
|
const groupArchetype = group.name.slice(0, -1) as Archetype
|
|
|
|
|
|
|
|
const isSelectedArchetype = hasSelectedArchetypes
|
|
|
|
? selectedArchetypes.includes(groupArchetype)
|
|
|
|
: true
|
|
|
|
|
|
|
|
if (isSelectedArchetype) {
|
|
|
|
return group.operators.map((operator) => ({
|
|
|
|
id: operator.id.toString(),
|
|
|
|
image: operator.image_400_jpeg_url,
|
|
|
|
gif: operator.image_400_url,
|
|
|
|
name: `OP ${operator.id}`,
|
|
|
|
pointsPerHour: Math.floor(Math.random() * 500),
|
|
|
|
isStaked: false,
|
|
|
|
isPinned: false,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
return []
|
|
|
|
})
|
2024-09-27 14:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getRandomSubset<T>(array: T[], count: number): T[] {
|
|
|
|
const shuffled = array?.sort(() => 0.5 - Math.random())
|
|
|
|
return shuffled?.slice(0, count)
|
|
|
|
}
|