Skip to content

Commit

Permalink
ZO add dm and stats (#2634)
Browse files Browse the repository at this point in the history
* ZO add zzz_dm using hakush.in

* get HakushinData

* add zzz-stats

* baboom

* fix bugs
  • Loading branch information
frzyc authored Jan 27, 2025
1 parent 7cda611 commit 6f18a25
Show file tree
Hide file tree
Showing 525 changed files with 88,390 additions and 156 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
path = libs/sr/dm/StarRailData
url = https://gitlab.com/Dimbreath/turnbasedgamedata.git
shallow = true
[submodule "libs/zzz/dm/ZenlessData"]
path = libs/zzz/dm/ZenlessData
url = https://git.mero.moe/dimbreath/ZenlessData.git
8 changes: 6 additions & 2 deletions apps/zzz-frontend/src/app/PageHome.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CardThemed } from '@genshin-optimizer/common/ui'
import { CardContent, Typography } from '@mui/material'
import { Box, CardContent, Typography } from '@mui/material'

export default function PageHome() {
return (
Expand All @@ -17,7 +17,11 @@ export default function PageHome() {
</Typography>
<Typography>
I know a lot of stuff isn't implemented, and the stuff that are, are
super ugly. This is only like 10 hours of coding, cut me some slack.
super ugly. This is only like{' '}
<Box component="span" sx={{ textDecoration: 'line-through' }}>
10
</Box>{' '}
20 hours of coding, cut me some slack.
</Typography>
<Typography sx={{ my: 1 }}>Have an optimal day,</Typography>
<Typography>
Expand Down
1 change: 1 addition & 0 deletions libs/common/pipeline/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './lib/extrapolateFloat'
export * from './lib/fetch'
export * from './lib/pipeline'
export * from './lib/util'
27 changes: 27 additions & 0 deletions libs/common/pipeline/src/lib/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { get as httpsGet } from 'https'

export function fetchJsonFromUrl(url: string, debug = false) {
debug && console.log('Fetching', url)
return new Promise((resolve, reject) => {
httpsGet(url, (response) => {
let data = ''

// Accumulate data as it comes in
response.on('data', (chunk) => {
data += chunk
})

// Resolve the promise once all data has been received
response.on('end', () => {
try {
const json = JSON.parse(data)
resolve(json)
} catch (error) {
reject(new Error(`Failed to parse JSON: ${(error as Error).message}`))
}
})
}).on('error', (error) => {
reject(new Error(`Request failed: ${error.message}`))
})
})
}
8 changes: 5 additions & 3 deletions libs/common/util/src/lib/numDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export function valueString(
}
return `${value.toFixed(fixed)}${unit}`
}

export function isPercentStat<Key extends string>(key: Key): boolean {
return key.endsWith('_')
}
export function getUnitStr<Key extends string>(key: Key): Unit {
if (key.endsWith('_')) return '%'
if (isPercentStat(key)) return '%'
return ''
}

Expand All @@ -39,7 +41,7 @@ export function statKeyToFixed(statKey: string) {
}

export function roundStat(value: number, statKey: string) {
return getUnitStr(statKey) === '%'
return isPercentStat(statKey)
? Math.round(value * 10000) / 10000
: Math.round(value * 100) / 100
}
9 changes: 9 additions & 0 deletions libs/common/util/src/lib/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ export function objMap<K extends string | number, V, V2>(
) as Record<K, V2>
}

export function objFilter<K extends string | number, V>(
obj: Record<K, V>,
f: (v: V, k: K, i: number) => boolean
): Record<K, V> {
return Object.fromEntries(
Object.entries(obj).filter(([k, v], i) => f(v as V, k as K, i))
) as Record<K, V>
}

/**
* Generate an object from an array of keys, and a function that maps the key to a value
* @param keys
Expand Down
12 changes: 6 additions & 6 deletions libs/sr/stats/src/executors/gen-stats/executor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dumpFile } from '@genshin-optimizer/common/pipeline'
import { dumpPrettyFile } from '@genshin-optimizer/common/pipeline'
import { workspaceRoot } from '@nx/devkit'
import type { GenStatsExecutorSchema } from './schema'
import type {
Expand Down Expand Up @@ -38,26 +38,26 @@ export type AllStats = typeof allStat
export default async function runExecutor(_options: GenStatsExecutorSchema) {
console.log(`Writing character data to ${path}/Characters`)
Object.entries(characterDataDump).forEach(([key, data]) =>
dumpFile(`${path}/Characters/${key}.json`, data)
dumpPrettyFile(`${path}/Characters/${key}.json`, data)
)

console.log(`Writing lightCone data to ${path}/LightCone`)
Object.entries(lightConeDataDump).forEach(([key, data]) =>
dumpFile(`${path}/LightCone/${key}.json`, data)
dumpPrettyFile(`${path}/LightCone/${key}.json`, data)
)

console.log(`Writing relic data to ${path}/Relic`)
Object.entries(relicDataDump).forEach(([key, data]) =>
dumpFile(`${path}/Relic/${key}.json`, data)
dumpPrettyFile(`${path}/Relic/${key}.json`, data)
)

console.log(`Writing misc data to ${path}/misc`)
Object.entries(miscDataDump).forEach(([key, data]) =>
dumpFile(`${path}/misc/${key}.json`, data)
dumpPrettyFile(`${path}/misc/${key}.json`, data)
)

console.log(`Writing combined data to ${proj_path}/src/allStat_gen.json`)
dumpFile(`${proj_path}/src/allStat_gen.json`, allStat)
dumpPrettyFile(`${proj_path}/src/allStat_gen.json`, allStat)

return { success: true }
}
28 changes: 26 additions & 2 deletions libs/zzz/consts/src/character.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// copy from libs\zzz\dm\src\dm\character\characterKeys.json
export const allCharacterKeys = [
'Anby',
'Anton',
'AstraYao',
'Astra',
'Ben',
'Billy',
'Burnice',
Expand All @@ -20,15 +21,38 @@ export const allCharacterKeys = [
'Nekomata',
'Nicole',
'Piper',
'Qingyi',
'PulchraFeliny',
'QingYi',
'Rina',
'Seth',
'SilverAnby',
'Soldier11',
'Soukaku',
'Trigger',
'Yanagi',
'ZhuYuan',
] as const
export type CharacterKey = (typeof allCharacterKeys)[number]

export const allLocationKeys = [...allCharacterKeys, ''] as const
export type LocationKey = (typeof allLocationKeys)[number]

export const allSpecialityKeys = [
'attack',
'stun',
'anomaly',
'support',
'defense',
] as const
export type SpecialityKey = (typeof allSpecialityKeys)[number]

export const allAttackTypeKeys = ['slash', 'strike', 'pierce'] as const
export type AttackTypeKey = (typeof allAttackTypeKeys)[number]

export const allCharacterRarityKeys = ['S', 'A'] as const
export type CharacterRarityKey = (typeof allCharacterRarityKeys)[number]

export const ascensionlevel = [10, 20, 30, 40, 50, 60] as const
export const coreLevel = [15, 25, 35, 45, 55, 60] as const

export const allCoreKeys = ['None', 'A', 'B', 'C', 'D', 'E', 'F'] as const
2 changes: 2 additions & 0 deletions libs/zzz/consts/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const otherStatKeys = [
// Used by calc, likely will be bundled into pando
'charLvl',
'enemyDef', // Enemy DEF
'enemyDefRed', // Enemy DEF shred
'enemyRes_', // Enemy Resistance
'enemyResRed_', // Enemy Resistance Reduction
'enemyResIgn_', // Enemy Resistance Ignore
Expand Down Expand Up @@ -79,6 +80,7 @@ export const statKeyTextMap: Partial<Record<string, string>> = {
dmg_: 'DMG Bonus',
charLvl: 'Character Level',
enemyDef: 'Enemy DEF',
enemyDefRed: 'Enemy DEF shred',
enemyRes_: 'Enemy Resistance',
enemyResRed_: 'Enemy Resistance Reduction',
enemyResIgn_: 'Enemy Resistance Ignore',
Expand Down
8 changes: 8 additions & 0 deletions libs/zzz/consts/src/formula.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { allAnomalyDmgKeys, allAttributeDamageKeys } from './common'

export const allFormulaKeys = [
'initial_atk',
...allAttributeDamageKeys,
...allAnomalyDmgKeys,
] as const
export type FormulaKey = (typeof allFormulaKeys)[number]
2 changes: 2 additions & 0 deletions libs/zzz/consts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './character'
export * from './common'
export * from './disc'
export * from './formula'
export * from './wengine'
65 changes: 65 additions & 0 deletions libs/zzz/consts/src/wengine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
export const allWengineRarityKeys = ['S', 'A'] as const
export type WengineRarityKey = (typeof allWengineRarityKeys)[number]

export const allWengineKeys = [
'BashfulDemon',
'BigCylinder',
'BlazingLaurel',
'BunnyBand',
'CannonRotor',
'DeepSeaVisitor',
'DemaraBatteryMarkII',
'DrillRigRedAxis',
'ElectroLipGloss',
'ElegantVanity',
'FlamemakerShaker',
'FusionCompiler',
'GildedBlossom',
'HailstormShrine',
'HeartstringNocturne',
'HellfireGears',
'Housekeeper',
'IceJadeTeapot',
'IdentityBase',
'IdentityInflection',
'KaboomTheCannon',
'LunarDecrescent',
'LunarNoviluna',
'LunarPleniluna',
'MagneticStormAlpha',
'MagneticStormBravo',
'MagneticStormCharlie',
'MarcatoDesire',
'OriginalTransmorpher',
'PeacekeeperSpecialized',
'PreciousFossilizedCore',
'RainforestGourmet',
'ReverbMarkI',
'ReverbMarkII',
'ReverbMarkIII',
'RiotSuppressorMarkVI',
'RoaringRide',
'SharpenedStinger',
'SixShooter',
'SliceOfTime',
'SpringEmbrace',
'StarlightEngine',
'StarlightEngineReplica',
'SteamOven',
'SteelCushion',
'StreetSuperstar',
'TheBrimstone',
'TheRestrained',
'TheVault',
'Timeweaver',
'TusksOfFury',
'UnfetteredGameBall',
'VortexArrow',
'VortexHatchet',
'VortexRevolver',
'WeepingCradle',
'WeepingGemini',
'ZanshinHerbCase',
] as const

export type WengineKey = (typeof allWengineKeys)[number]
1 change: 1 addition & 0 deletions libs/zzz/db-ui/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './useCharacter'
export * from './useDisc'
8 changes: 8 additions & 0 deletions libs/zzz/db-ui/src/hooks/useCharacter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useDataManagerBase } from '@genshin-optimizer/common/database-ui'
import type { CharacterKey } from '@genshin-optimizer/zzz/consts'
import { useDatabaseContext } from '../context'

export function useCharacter(characterKey: CharacterKey | '' | undefined) {
const { database } = useDatabaseContext()
return useDataManagerBase(database.chars, characterKey as CharacterKey)
}
Loading

0 comments on commit 6f18a25

Please sign in to comment.