Skip to content

Commit

Permalink
ZO add pipeline for img assets
Browse files Browse the repository at this point in the history
  • Loading branch information
frzyc committed Feb 9, 2025
1 parent 68bbde6 commit efdcf4a
Show file tree
Hide file tree
Showing 42 changed files with 457 additions and 104 deletions.
21 changes: 21 additions & 0 deletions libs/zzz/assets-data/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"parserOptions": {
"project": "libs/zzz/assets-data/tsconfig.eslint.json"
},
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
3 changes: 3 additions & 0 deletions libs/zzz/assets-data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# zzz-assets-data

This library was generated with [Nx](https://nx.dev).
9 changes: 9 additions & 0 deletions libs/zzz/assets-data/executors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"executors": {
"gen-assets-data": {
"implementation": "./src/executors/gen-assets-data/executor",
"schema": "./src/executors/gen-assets-data/schema.json",
"description": "gen-assets-data executor"
}
}
}
6 changes: 6 additions & 0 deletions libs/zzz/assets-data/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@genshin-optimizer/zzz/assets-data",
"version": "0.0.1",
"type": "commonjs",
"executors": "./executors.json"
}
14 changes: 14 additions & 0 deletions libs/zzz/assets-data/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "zzz-assets-data",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/zzz/assets-data/src",
"projectType": "library",
"tags": [],
"// targets": "to see all targets run: nx show project zzz-assets-data --web",
"targets": {
"gen-file": {
"executor": "@genshin-optimizer/zzz/assets-data:gen-assets-data",
"outputs": ["{projectRoot}/src/AssetsData_gen.json"]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { ExecutorContext } from '@nx/devkit'

import executor from './executor'
import type { GenAssetsDataExecutorSchema } from './schema'

const options: GenAssetsDataExecutorSchema = {}
const context: ExecutorContext = {
root: '',
cwd: process.cwd(),
isVerbose: false,
}

describe('GenAssetsData Executor', () => {
it('can run', async () => {
const output = await executor(options, context)
expect(output.success).toBe(true)
})
})
75 changes: 75 additions & 0 deletions libs/zzz/assets-data/src/executors/gen-assets-data/executor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { dumpFile } from '@genshin-optimizer/common/pipeline'
import { objMap } from '@genshin-optimizer/common/util'
import type { CharacterKey, DiscSetKey } from '@genshin-optimizer/zzz/consts'
import {
charactersDetailedJSONData,
discsDetailedJSONData,
} from '@genshin-optimizer/zzz/dm'
import type { PromiseExecutor } from '@nx/devkit'
import { workspaceRoot } from '@nx/devkit'
import type { GenAssetsDataExecutorSchema } from './schema'

export type AssetData = {
discs: Record<
DiscSetKey,
{
circle: string
cd_s: string
cd_a: string
cd_b: string
}
>
chars: Record<
CharacterKey,
{
full: string
circle: string
trap: string
select: string
interknot: string
}
>
}

const runExecutor: PromiseExecutor<GenAssetsDataExecutorSchema> = async (
options
) => {
console.log('Executor ran for GenAssetsData', options)
const assetData: AssetData = {
discs: objMap(discsDetailedJSONData, ({ icon }) => {
const strKey = icon.match(/Suit([^/]+)\.png/)?.[1]
if (!strKey) throw Error('Failed to parse disc icon name')
return {
circle: `Suit${strKey}.png`,
cd_s: `ItemSuit${strKey}_S.png`,
cd_a: `ItemSuit${strKey}_A.png`,
cd_b: `ItemSuit${strKey}_B.png`,
}
}),

chars: objMap(charactersDetailedJSONData, ({ icon }) => {
// get the last 2 digits of the icon name. this will likely break if ZZZ go over 2 digits.
const strKey = icon.slice(-2)
if (!strKey) throw Error('Failed to parse character icon name')
return {
full: `IconRole${strKey}.png`,
circle: `IconRoleCircle${strKey}.png`,
trap: `IconRoleGeneral${strKey}.png`,
select: `IconRoleSelect${strKey}.png`,
interknot: `IconInterKnotRole00${strKey}.png`,
}
}),
} as const

// Dump out the asset List.
dumpFile(
`${workspaceRoot}/libs/zzz/assets-data/src/AssetsData_gen.json`,
assetData
)

return {
success: true,
}
}

export default runExecutor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface GenAssetsDataExecutorSchema {} // eslint-disable-line
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json-schema.org/schema",
"version": 2,
"title": "GenAssetsData executor",
"description": "",
"type": "object",
"properties": {},
"required": []
}
4 changes: 4 additions & 0 deletions libs/zzz/assets-data/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as AssetData_gen from './AssetsData_gen.json'
import type { AssetData as AssetDataType } from './executors/gen-assets-data/executor'
export type { AssetDataType }
export const AssetData = AssetData_gen as AssetDataType
8 changes: 8 additions & 0 deletions libs/zzz/assets-data/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"]
}
19 changes: 19 additions & 0 deletions libs/zzz/assets-data/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
}
]
}
10 changes: 10 additions & 0 deletions libs/zzz/assets-data/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"declaration": true,
"types": ["node", "object-overrides"]
},
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"]
}
11 changes: 10 additions & 1 deletion libs/zzz/assets/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,14 @@
"sourceRoot": "libs/zzz/assets/src",
"projectType": "library",
"tags": [],
"targets": {}
"targets": {
"gen-file": {
"executor": "@genshin-optimizer/zzz/assets:gen-assets",
"options": {
"fetchAssets": "local"
},
"outputs": ["{workspaceRoot}/${projectRoot}/src/gen/**/*"],
"dependsOn": ["zzz-assets-data:gen-file"]
}
}
}
1 change: 0 additions & 1 deletion libs/zzz/assets/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// This is a generated index file.
import discBackdrop from './discBackdrop.png'
import discDrive from './drive.png'

Expand Down
Binary file added libs/zzz/assets/src/common/rarity/RANK_A.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added libs/zzz/assets/src/common/rarity/RANK_B.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added libs/zzz/assets/src/common/rarity/RANK_S.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions libs/zzz/assets/src/common/rarity/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import A from './RANK_A.png'
import B from './RANK_B.png'
import S from './RANK_S.png'

const data = {
S,
A,
B,
} as const
export default data
Binary file added libs/zzz/assets/src/common/skill/SkillCore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added libs/zzz/assets/src/common/skill/SkillEvade.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added libs/zzz/assets/src/common/skill/SkillNormal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added libs/zzz/assets/src/common/skill/SkillQTE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added libs/zzz/assets/src/common/skill/SkillSpecial.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added libs/zzz/assets/src/common/skill/SkillSwitch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions libs/zzz/assets/src/common/skill/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import core from './SkillCore.png'
import evade from './SkillEvade.png'
import normal from './SkillNormal.png'
import chain from './SkillQTE.png'
import skill from './SkillSpecial.png'
import assist from './SkillSwitch.png'

const data = {
evade,
normal,
chain,
skill,
core,
assist,
} as const
export default data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions libs/zzz/assets/src/common/speciality/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import anomaly from './IconAnomaly.png'
import attack from './IconAttack.png'
import defense from './IconDefense.png'
import stun from './IconStun.png'
import support from './IconSupport.png'

const data = {
attack,
anomaly,
defense,
stun,
support,
} as const
export default data
8 changes: 8 additions & 0 deletions libs/zzz/assets/src/executors/gen-assets/executor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import executor from './executor'

describe.skip('GenAssets Executor', () => {
it('can run', async () => {
const output = await executor({})
expect(output.success).toBe(true)
})
})
80 changes: 80 additions & 0 deletions libs/zzz/assets/src/executors/gen-assets/executor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { generateIndexFromObj } from '@genshin-optimizer/common/pipeline'
import { crawlObject, layeredAssignment } from '@genshin-optimizer/common/util'
import { AssetData } from '@genshin-optimizer/zzz/assets-data'
import { DM2D_PATH } from '@genshin-optimizer/zzz/dm'
import { workspaceRoot } from '@nx/devkit'
import * as fs from 'fs'
import * as path from 'path'
import type { GenAssetsExecutorSchema } from './schema'

const DEST_PROJ_PATH = `${workspaceRoot}/libs/zzz/assets/src` as const

export default async function runExecutor(
options: GenAssetsExecutorSchema
): Promise<{ success: boolean }> {
function copyFile(src: string, dest: string) {
if (!fs.existsSync(src)) {
console.warn('Cannot find file', src)
return
}
fs.mkdirSync(path.dirname(dest), { recursive: true })
fs.copyFile(src, dest, (err) => {
if (err) console.error(err)
})
}

// Dump out the asset List.
// Best effort and since most of the time we don't use this
console.log(options)
if (options.fetchAssets === 'local' && fs.existsSync(DM2D_PATH)) {
console.log('Copying files')
crawlObject(
AssetData,
[],
(s) => typeof s === 'string' || Array.isArray(s),
(filePath: string | string[], keys) => {
const fileName = keys.slice(-1)[0]
const folderPath = keys.slice(0, -1).join('/')
if (typeof filePath === 'string') {
copyFile(
`${DM2D_PATH}/${filePath.toLocaleLowerCase()}`,
`${DEST_PROJ_PATH}/gen/${folderPath}/${fileName}.png`
)
} else {
filePath.forEach((fp, index) =>
copyFile(
`${DM2D_PATH}/${fp.toLocaleLowerCase()}`,
`${DEST_PROJ_PATH}/gen/${folderPath}/${fileName}_${index}.png`
)
)
}
}
)
} else {
console.log('No assets will be copied.')
}
console.log('Generating index')
// Extract just the filename for the index files
const indexData = {}
crawlObject(
AssetData,
[],
(s) => typeof s === 'string' || Array.isArray(s),
(filePath: string | string[], keys) => {
const fileName = keys.slice(-1)[0]
if (typeof filePath === 'string') {
layeredAssignment(indexData, keys, fileName)
} else {
filePath.forEach((_, index) => {
const newKeys = [...keys]
newKeys[newKeys.length - 1] = `${
newKeys[newKeys.length - 1]
}_${index}`
layeredAssignment(indexData, newKeys, `${fileName}_${index}`)
})
}
}
)
await generateIndexFromObj(indexData, `${DEST_PROJ_PATH}/gen`)
return { success: true }
}
3 changes: 3 additions & 0 deletions libs/zzz/assets/src/executors/gen-assets/schema.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface GenAssetsExecutorSchema {
fetchAssets: 'none' | 'local'
} // eslint-disable-line
11 changes: 11 additions & 0 deletions libs/zzz/assets/src/executors/gen-assets/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "http://json-schema.org/schema",
"version": 2,
"title": "GenAssets executor",
"description": "",
"type": "object",
"properties": {
"fetchAssets": "Flag to specify where to fetch assets from. 'none' for no asset copying/fetching, 'local' to copy from 'libs/sr/dm/assets', 'yatta' to fetch from yatta.top"
},
"required": []
}
Loading

0 comments on commit efdcf4a

Please sign in to comment.