-
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.
* zo disc scanner * fix lint + feedback * refactor substat key detection
- Loading branch information
Showing
27 changed files
with
1,066 additions
and
280 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
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
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 |
---|---|---|
@@ -1,12 +1,5 @@ | ||
import type { IDisc, ISubstat } from './IDisc' | ||
import type { IDisc } from './IDisc' | ||
|
||
export interface ICachedDisc extends IDisc { | ||
id: string | ||
mainStatVal: number | ||
substats: ICachedSubstat[] | ||
} | ||
|
||
export interface ICachedSubstat extends ISubstat { | ||
rolls: number | ||
accurateValue: number | ||
} |
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
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"] | ||
} |
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": ["plugin:@nx/react", "../../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"parserOptions": { | ||
"project": "libs/zzz/disc-scanner/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,7 @@ | ||
# zzz-disc-scanner | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Running unit tests | ||
|
||
Run `nx test zzz-disc-scanner` to execute the unit tests via [Jest](https://jestjs.io). |
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 @@ | ||
{ | ||
"name": "zzz-disc-scanner", | ||
"$schema": "../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "libs/zzz/disc-scanner/src", | ||
"projectType": "library", | ||
"tags": [], | ||
"targets": {} | ||
} |
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 * from './lib/ScanningQueue' |
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,73 @@ | ||
import type { Outstanding, Processed } from './processImg' | ||
import { processEntry } from './processImg' | ||
|
||
export type ScanningData = { | ||
processedNum: number | ||
outstandingNum: number | ||
scanningNum: number | ||
} | ||
export type { Processed } | ||
|
||
const maxProcessingCount = 3, | ||
maxProcessedCount = 16 | ||
|
||
type textsFromImageFunc = ( | ||
imageData: ImageData, | ||
options?: object | undefined | ||
) => Promise<string[]> | ||
|
||
export class ScanningQueue { | ||
private debug: boolean | ||
private textsFromImage: textsFromImageFunc | ||
constructor(textsFromImage: textsFromImageFunc, debug = false) { | ||
this.textsFromImage = textsFromImage | ||
this.debug = debug | ||
} | ||
private processed = [] as Processed[] | ||
private outstanding = [] as Outstanding[] | ||
private scanning = [] as Promise<Processed>[] | ||
callback = (() => {}) as (data: ScanningData) => void | ||
|
||
addFiles(files: Outstanding[]) { | ||
this.outstanding.push(...files) | ||
this.processQueue() | ||
} | ||
processQueue() { | ||
const numProcessing = Math.min( | ||
maxProcessedCount - this.processed.length - this.scanning.length, | ||
maxProcessingCount - this.scanning.length, | ||
this.outstanding.length | ||
) | ||
numProcessing && | ||
this.outstanding.splice(0, numProcessing).map((p) => { | ||
const prom = processEntry(p, this.textsFromImage, this.debug) | ||
this.scanning.push(prom) | ||
prom.then((procesResult) => { | ||
const index = this.scanning.indexOf(prom) | ||
if (index === -1) return // probably because the queue has been cleared. | ||
this.scanning.splice(index, 1) | ||
this.processed.push(procesResult) | ||
this.processQueue() | ||
}) | ||
}) | ||
this.callCB() | ||
} | ||
private callCB() { | ||
this.callback({ | ||
processedNum: this.processed.length, | ||
outstandingNum: this.outstanding.length, | ||
scanningNum: this.scanning.length, | ||
}) | ||
} | ||
shiftProcessed(): Processed | undefined { | ||
const procesesd = this.processed.shift() | ||
if (procesesd) this.processQueue() | ||
return procesesd | ||
} | ||
clearQueue() { | ||
this.processed = [] | ||
this.outstanding = [] | ||
this.scanning = [] | ||
this.callCB() | ||
} | ||
} |
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 type { Color } from '@genshin-optimizer/common/img-util' | ||
|
||
export const misreadCharactersInSubstatMap = [ | ||
{ | ||
pattern: /#/, | ||
replacement: '+', | ||
}, | ||
] | ||
|
||
export const blackColor: Color = { | ||
r: 0, | ||
g: 0, | ||
b: 0, | ||
} |
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,31 @@ | ||
// Store the english translations to use with scanner | ||
|
||
const elementalData: Record<string, string> = { | ||
electric: 'Electric', | ||
fire: 'Fire', | ||
ice: 'Ice', | ||
frost: 'Frost', | ||
physical: 'Physical', | ||
ether: 'Ether', | ||
} as const | ||
|
||
export const statMapEngMap = { | ||
hp: 'HP', | ||
hp_: 'HP', | ||
atk: 'ATK', | ||
atk_: 'ATK', | ||
def: 'DEF', | ||
def_: 'DEF', | ||
pen: 'PEN', | ||
pen_: 'PEN Ratio', | ||
crit_: 'CRIT Rate', | ||
crit_dmg_: 'CRIT DMG', | ||
enerRegen_: 'Energy Regen', | ||
impact_: 'Impact', | ||
anomMas_: 'Anomaly Mastery', | ||
anomProf: 'Anomaly Proficiency', | ||
} as Record<string, string> | ||
|
||
Object.entries(elementalData).forEach(([e, name]) => { | ||
statMapEngMap[`${e}_dmg_`] = `${name} DMG Bonus` | ||
}) |
Oops, something went wrong.