Skip to content

Commit

Permalink
Stream changes from go-next proj to master (#1347)
Browse files Browse the repository at this point in the history
* stream changes from go-next proj to master

* format

* tsx -> ts
  • Loading branch information
frzyc authored Dec 1, 2023
1 parent 140e8ac commit 5f7b1bc
Show file tree
Hide file tree
Showing 75 changed files with 2,785 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export type DropdownButtonProps = Omit<ButtonProps, 'title'> & {
id?: string
children: React.ReactNode
}

/**
* @deprecated use @go/ui-common
* @param param0
* @returns
*/
export default function DropdownButton({
title,
children,
Expand Down
12 changes: 12 additions & 0 deletions libs/consts/src/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export const artifactCircletStatKeys = [
'heal_',
] as const
export type ArtifactCircletStatKey = (typeof artifactCircletStatKeys)[number]

/**
* @deprecated use artSlotMainKeys
*/
export const artSlotsData = {
flower: { name: 'Flower of Life', stats: ['hp'] as readonly MainStatKey[] },
plume: { name: 'Plume of Death', stats: ['atk'] as readonly MainStatKey[] },
Expand All @@ -131,6 +135,14 @@ export const artSlotsData = {
},
} as const

export const artSlotMainKeys = {
flower: ['hp'] as readonly MainStatKey[],
plume: ['atk'] as readonly MainStatKey[],
sands: artifactSandsStatKeys as readonly MainStatKey[],
goblet: artifactGobletStatKeys as readonly MainStatKey[],
circlet: artifactCircletStatKeys as readonly MainStatKey[],
} as const

export const allMainStatKeys = [
'hp',
'hp_',
Expand Down
13 changes: 13 additions & 0 deletions libs/gi-art-scanner/.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"]
}
18 changes: 18 additions & 0 deletions libs/gi-art-scanner/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nx/react", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/gi-art-scanner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# gi-art-scanner

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

## Running unit tests

Run `nx test gi-art-scanner` to execute the unit tests via [Jest](https://jestjs.io).
16 changes: 16 additions & 0 deletions libs/gi-art-scanner/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "gi-art-scanner",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/gi-art-scanner/src",
"projectType": "library",
"tags": [],
"targets": {
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/gi-art-scanner/**/*.{ts,tsx,js,jsx}"]
}
}
}
}
1 change: 1 addition & 0 deletions libs/gi-art-scanner/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/ScanningQueue'
73 changes: 73 additions & 0 deletions libs/gi-art-scanner/src/lib/ScanningQueue.tsx
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()
this.processQueue()
return procesesd
}
clearQueue() {
this.processed = []
this.outstanding = []
this.scanning = []
this.callCB()
}
}
45 changes: 45 additions & 0 deletions libs/gi-art-scanner/src/lib/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { Color } from '@genshin-optimizer/img-util'

/**
* "golden" title
* light: bc6832 rgb(188, 104, 50)
* dark: 915128 rgb(145, 81, 40)
*/
export const goldenTitleDarkerColor: Color = {
r: 145,
g: 81,
b: 40,
}
export const goldenTitleLighterColor: Color = {
r: 188,
g: 104,
b: 50,
}

// The "baige" background of artifact card, ebe4d8 rgb(235, 228, 216)
export const cardWhite: Color = {
r: 235,
g: 228,
b: 216,
}

// the yellow bottom for equipment color rgb(255, 231, 186)
export const equipColor: Color = {
r: 255,
g: 231,
b: 186,
}

// Greentext color
// greenest rgb(93, 178, 87)
// lightgreen rgb(185, 210, 170)
export const greenTextColor: Color = {
r: 93,
g: 178,
b: 87,
}

export const starColor = { r: 255, g: 204, b: 50 } // #FFCC32

export const textColorLight = { r: 131, g: 131, b: 130 } // rgb(131, 131, 130)
export const textColorDark = { r: 74, g: 81, b: 102 } // rgb(74, 81, 102)
40 changes: 40 additions & 0 deletions libs/gi-art-scanner/src/lib/enStringMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { ElementWithPhyKey } from '@genshin-optimizer/consts'

// Store the english translations to use with artifact scanner

const elementalData: Record<ElementWithPhyKey, string> = {
physical: 'Physical',
anemo: 'Anemo',
geo: 'Geo',
electro: 'Electro',
hydro: 'Hydro',
pyro: 'Pyro',
cryo: 'Cryo',
dendro: 'Dendro',
} as const

export const statMap = {
hp: 'HP',
hp_: 'HP',
atk: 'ATK',
atk_: 'ATK',
def: 'DEF',
def_: 'DEF',
eleMas: 'Elemental Mastery',
enerRech_: 'Energy Recharge',
critRate_: 'Crit Rate',
critDMG_: 'Crit DMG',
heal_: 'Healing Bonus',
} as Record<string, string>

Object.entries(elementalData).forEach(([e, name]) => {
statMap[`${e}_dmg_`] = `${name} DMG Bonus`
})

export const artSlotNames = {
flower: 'Flower of Life',
plume: 'Plume of Death',
sands: 'Sands of Eon',
goblet: 'Goblet of Eonothem',
circlet: 'Circlet of Logos',
}
Loading

0 comments on commit 5f7b1bc

Please sign in to comment.