Skip to content

Commit

Permalink
minimal ui-sheets for SRO (#2392)
Browse files Browse the repository at this point in the history
  • Loading branch information
frzyc authored Aug 24, 2024
1 parent 0ce40d4 commit a609eea
Show file tree
Hide file tree
Showing 16 changed files with 241 additions and 22 deletions.
45 changes: 23 additions & 22 deletions libs/sr/assets/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import type { CharacterKey, LightConeKey } from '@genshin-optimizer/sr/consts'
// import artifacts from './gen/artifacts'
// import chars from './gen/chars'
// import lightCones from './gen/lightCones'
type characterAssetKey = 'icon' | 'cover'
import type {
LightConeKey,
NonTrailblazerCharacterKey,
RelicSetKey,
RelicSlotKey,
TrailblazerGenderedKey,
} from '@genshin-optimizer/sr/consts'
import chars from './gen/chars'
import lightCones from './gen/lightCones'
import relics from './gen/relic'
type characterAssetKey = 'icon' | 'basic_0'
export function characterAsset(
_ck: CharacterKey,
ck: NonTrailblazerCharacterKey | TrailblazerGenderedKey,
asset: characterAssetKey
): string {
switch (asset) {
case 'icon':
default:
// return chars[ck][asset] ?? ''
throw new Error('TODO')
}
) {
return chars[ck][asset]
}
export function lightConeAsset(_lck: LightConeKey) {
// return lightCones[lck]
throw new Error('TODO')
type LightConeAssetKey = 'icon' | 'cover'
export function lightConeAsset(lck: LightConeKey, asset: LightConeAssetKey) {
return lightCones[lck][asset]
}

export function relicAsset(rk: RelicSetKey, slotKey: RelicSlotKey) {
const relic = relics[rk]

return relic[slotKey as keyof typeof relic]
}
// export function artifactAsset(
// ak: ArtifactSetKey,
// slotKey: ArtifactSlotKey
// ): string {
// return artifacts[ak][slotKey] ?? ''
// }
13 changes: 13 additions & 0 deletions libs/sr/formula-ui/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage",
"importSource": "@emotion/react"
}
]
],
"plugins": ["@emotion/babel-plugin"]
}
21 changes: 21 additions & 0 deletions libs/sr/formula-ui/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": ["plugin:@nx/react", "../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"parserOptions": {
"project": "libs/sr/formula-ui/tsconfig.eslint.json"
},
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/sr/formula-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# sr-formula-ui

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test sr-formula-ui` to execute the unit tests via [Jest](https://jestjs.io).
8 changes: 8 additions & 0 deletions libs/sr/formula-ui/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "sr-formula-ui",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/sr/formula-ui/src",
"projectType": "library",
"tags": [],
"targets": {}
}
14 changes: 14 additions & 0 deletions libs/sr/formula-ui/src/char/consts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type TalentSheetElementKey =
| 'basic'
| 'skill'
| 'ultimate'
| 'talent'
| 'passive1'
| 'passive2'
| 'passive3'
| 'eidolon1'
| 'eidolon2'
| 'eidolon3'
| 'eidolon4'
| 'eidolon5'
| 'eidolon6'
41 changes: 41 additions & 0 deletions libs/sr/formula-ui/src/char/sheets/RuanMei.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { UISheet } from '@genshin-optimizer/pando/ui-sheet'
import { characterAsset } from '@genshin-optimizer/sr/assets'
import type { CharacterKey } from '@genshin-optimizer/sr/consts'
import { formulas } from '@genshin-optimizer/sr/formula'
import { trans } from '../../util'
import type { TalentSheetElementKey } from '../consts'
const key: CharacterKey = 'RuanMei'
const [chg, _ch] = trans('char', key)
const sheet: UISheet<TalentSheetElementKey> = {
basic: {
name: chg('abilities.basic.0.name'),
img: characterAsset(key, 'basic_0'),
documents: [
{
type: 'text',
text: chg('auto.fields.normal'),
},
{
type: 'fields',
fields: Object.entries(formulas.RuanMei)
.filter(([key]) => key.startsWith('normal'))
.map(([_, { tag }], i) => ({
title: chg(`auto.skillParams.${i}`),
fieldRef: tag,
})),
},
{ type: 'text', text: chg(`abilities.basic.0.fullDesc`) },
{
type: 'fields',
fields: [
{
title: chg('abilities.basic.0.shortDesc'),
fieldRef: formulas.RuanMei.basicDmg_0.tag,
},
],
},
],
},
}

export default sheet
7 changes: 7 additions & 0 deletions libs/sr/formula-ui/src/char/sheets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { UISheet } from '@genshin-optimizer/pando/ui-sheet'
import type { CharacterKey } from '@genshin-optimizer/sr/consts'
import type { TalentSheetElementKey } from '../consts'
import RuanMei from './RuanMei'
export const uiSheets: Partial<
Record<CharacterKey, UISheet<TalentSheetElementKey>>
> = { RuanMei } as const
1 change: 1 addition & 0 deletions libs/sr/formula-ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './char/sheets'
44 changes: 44 additions & 0 deletions libs/sr/formula-ui/src/util.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type {
LightConeKey,
NonTrailblazerCharacterKey,
RelicSetKey,
TrailblazerGenderedKey,
} from '@genshin-optimizer/sr/consts'
import { Translate } from '@genshin-optimizer/sr/i18n'
import type { ReactNode } from 'react'
export const st = (
strKey: string,
values?: Record<string, string | number>
) => <Translate ns="sheet" key18={strKey} values={values} />
export const stg = (strKey: string) => (
<Translate ns="sheet_gen" key18={strKey} />
)

type Translated = [
trg: (i18key: string) => ReactNode,
tr: (i18key: string, values?: Record<string, string | number>) => ReactNode
]

export function trans(
typeKey: 'char',
key: NonTrailblazerCharacterKey | TrailblazerGenderedKey
): Translated
export function trans(typeKey: 'lightcone', key: LightConeKey): Translated
export function trans(typeKey: 'relic', key: RelicSetKey): Translated
export function trans(
typeKey: 'char' | 'lightcone' | 'relic',
key:
| NonTrailblazerCharacterKey
| TrailblazerGenderedKey
| LightConeKey
| RelicSetKey
): Translated {
return [
(strKey: string) => (
<Translate ns={`${typeKey}_${key}_gen`} key18={strKey} />
),
(strKey: string, values?: Record<string, string | number>) => (
<Translate ns={`${typeKey}_${key}`} key18={strKey} values={values} />
),
]
}
8 changes: 8 additions & 0 deletions libs/sr/formula-ui/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"types": ["node"]
},
"include": ["**/*.ts", "**/*.tsx"]
}
18 changes: 18 additions & 0 deletions libs/sr/formula-ui/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"allowJs": false,
"esModuleInterop": false,
"exactOptionalPropertyTypes": false,
"strict": true,
"jsxImportSource": "@emotion/react"
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
}
],
"extends": "../../../tsconfig.base.json"
}
24 changes: 24 additions & 0 deletions libs/sr/formula-ui/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"types": [
"node",

"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
]
},
"exclude": [
"jest.config.ts",
"src/**/*.spec.ts",
"src/**/*.test.ts",
"src/**/*.spec.tsx",
"src/**/*.test.tsx",
"src/**/*.spec.js",
"src/**/*.test.js",
"src/**/*.spec.jsx",
"src/**/*.test.jsx"
],
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
}
1 change: 1 addition & 0 deletions libs/sr/formula/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { keys, values } from './data'
export { Calculator } from './calculator'
export type { SrcCondInfo } from './calculator'
export * from './data/util'
export * from './meta'
export * from './util'

export function srCalculatorWithValues(extras: TagMapEntries<number>) {
Expand Down
10 changes: 10 additions & 0 deletions libs/sr/stats/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import type {
NonTrailblazerCharacterKey,
TrailblazerGenderedKey,
} from '@genshin-optimizer/sr/consts'
import * as allStat_gen from './allStat_gen.json'
import type { AllStats } from './executors/gen-stats/executor'

Expand All @@ -14,3 +18,9 @@ const allStats = allStat_gen as AllStats

export { allStats }
export type { AllStats }

export function getCharStat(
ck: NonTrailblazerCharacterKey | TrailblazerGenderedKey
) {
return allStats.char[ck]
}
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"libs/sr/dm-localization/src/index.ts"
],
"@genshin-optimizer/sr/formula": ["libs/sr/formula/src/index.ts"],
"@genshin-optimizer/sr/formula-ui": ["libs/sr/formula-ui/src/index.ts"],
"@genshin-optimizer/sr/i18n": ["libs/sr/i18n/src/index.ts"],
"@genshin-optimizer/sr/i18n-node": ["libs/sr/i18n-node/src/index.ts"],
"@genshin-optimizer/sr/page-characters": [
Expand Down

0 comments on commit a609eea

Please sign in to comment.