-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
457 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
libs/zzz/assets-data/src/executors/gen-assets-data/executor.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
75
libs/zzz/assets-data/src/executors/gen-assets-data/executor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export interface GenAssetsDataExecutorSchema {} // eslint-disable-line |
9 changes: 9 additions & 0 deletions
9
libs/zzz/assets-data/src/executors/gen-assets-data/schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface GenAssetsExecutorSchema { | ||
fetchAssets: 'none' | 'local' | ||
} // eslint-disable-line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
Oops, something went wrong.