2025-05-08 18:52:57 +07:00
|
|
|
import { getAssetByName, getAssetModuleId } from '@revenge-mod/assets'
|
2025-05-09 21:52:36 +07:00
|
|
|
import { TokensModuleId } from '@revenge-mod/discord/common'
|
2025-05-08 18:52:57 +07:00
|
|
|
|
|
|
|
|
import { byDependencies, byProps } from '@revenge-mod/modules/finders/filters'
|
2025-05-09 21:52:36 +07:00
|
|
|
import { lookupModule } from '@revenge-mod/modules/finders/lookup'
|
2025-05-08 18:52:57 +07:00
|
|
|
|
2025-05-10 01:15:21 +07:00
|
|
|
import { ReactJsxRuntimeModuleId, ReactModuleId, ReactNativeModuleId } from '@revenge-mod/react'
|
2025-05-08 18:52:57 +07:00
|
|
|
|
|
|
|
|
import type { FC } from 'react'
|
|
|
|
|
|
2025-05-10 01:15:21 +07:00
|
|
|
// [React, ReactJsxRuntime, (Tokens), (BaseIconImage), (Asset), 2]
|
2025-05-08 18:52:57 +07:00
|
|
|
// Asset = relativeDep(1)
|
2025-05-09 21:52:36 +07:00
|
|
|
const IconComponentFilter = [ReactModuleId, ReactJsxRuntimeModuleId, TokensModuleId, undefined, undefined, 2]
|
2025-05-08 18:52:57 +07:00
|
|
|
|
2025-05-10 01:15:21 +07:00
|
|
|
// Generated IconComponents that have multiple assets, there is no specific length, so the filter has to be generated on-the-fly.
|
|
|
|
|
// [React, ReactNative, ReactJsxRuntime, (Tokens), (BaseIconImage), (...Assets), 2]
|
|
|
|
|
// ...Assets = relativeDep(1..n)
|
|
|
|
|
const MultiIconComponentFilterBase = [
|
|
|
|
|
ReactModuleId,
|
|
|
|
|
ReactNativeModuleId,
|
|
|
|
|
ReactJsxRuntimeModuleId,
|
|
|
|
|
TokensModuleId,
|
|
|
|
|
undefined,
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
// TODO(utils/discord/lookupGeneratedIconComponent): Make this into a filter?
|
|
|
|
|
export function lookupGeneratedIconComponent<N extends string>(compName: N, ...assetNames: string[]) {
|
2025-05-18 22:24:48 +07:00
|
|
|
const icon = lookupModule(byProps(compName))[0]?.[compName]
|
2025-05-08 18:52:57 +07:00
|
|
|
if (icon) return icon
|
|
|
|
|
|
2025-05-10 01:15:21 +07:00
|
|
|
let filter = IconComponentFilter
|
2025-05-08 18:52:57 +07:00
|
|
|
|
2025-05-10 01:15:21 +07:00
|
|
|
if (assetNames.length) {
|
|
|
|
|
const mids = []
|
2025-05-08 18:52:57 +07:00
|
|
|
|
2025-05-10 01:15:21 +07:00
|
|
|
for (const name of assetNames) {
|
|
|
|
|
const mid = getAssetModuleId(getAssetByName(name)!)
|
|
|
|
|
if (!mid) return
|
|
|
|
|
|
|
|
|
|
mids.push(mid)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filter = [...MultiIconComponentFilterBase, ...mids, 2]
|
|
|
|
|
} else {
|
|
|
|
|
const mid = getAssetModuleId(getAssetByName(compName)!)
|
|
|
|
|
if (!mid) return
|
|
|
|
|
|
|
|
|
|
IconComponentFilter[4] = mid
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lookupModule(byDependencies<{ [K in N]: FC }>(filter), {
|
2025-05-08 18:52:57 +07:00
|
|
|
includeInitialized: false,
|
|
|
|
|
includeUninitialized: true,
|
2025-05-18 22:24:48 +07:00
|
|
|
})[0]?.[compName]
|
2025-05-08 18:52:57 +07:00
|
|
|
}
|