From 05027bfd448f9007f8e4b4b9ba1a2dd584e0365b Mon Sep 17 00:00:00 2001 From: Marcin Cichocki Date: Wed, 19 Oct 2022 20:41:25 +0200 Subject: [PATCH] chore: organize imports and entry files --- src/common/node/index.ts | 1 + src/common/node/robot/auto-hotkey.ts | 2 +- src/common/node/robot/nircmd.ts | 2 +- src/common/node/robot/robot.ts | 2 +- src/common/node/robot/xdotool.ts | 2 +- src/core/index.ts | 3 ++ src/core/ocr/ocr.test.ts | 6 ++- src/core/solver/breach-protocol.ts | 4 +- .../hierarchy/focus-hierarchy-provider.ts | 2 +- .../hierarchy/index-hierarchy-provider.ts | 2 +- .../hierarchy/types-hierarchy-provider.ts | 2 +- src/electron/common/options.ts | 2 +- .../renderer/components/DaemonPriority.tsx | 49 ++++++++++++------- .../renderer/components/HistoryViewer.tsx | 6 +-- .../components/RecognitionSettings.tsx | 2 +- src/electron/worker/autosolver.ts | 4 +- src/electron/worker/worker.ts | 6 +-- 17 files changed, 59 insertions(+), 38 deletions(-) diff --git a/src/common/node/index.ts b/src/common/node/index.ts index 8eaa9a91..0827a2f6 100644 --- a/src/common/node/index.ts +++ b/src/common/node/index.ts @@ -1,3 +1,4 @@ export * from './resolver'; export * from './robot'; export * from './sharp-image-container'; +export { WasmBreachProtocolRecognizer } from './recognizer-wasm'; diff --git a/src/common/node/robot/auto-hotkey.ts b/src/common/node/robot/auto-hotkey.ts index 082b687e..f1d1a798 100644 --- a/src/common/node/robot/auto-hotkey.ts +++ b/src/common/node/robot/auto-hotkey.ts @@ -1,4 +1,4 @@ -import { sleep } from '@/common/util'; +import { sleep } from '@/common'; import { BreachProtocolRobotKeys } from './robot'; import { WindowsRobot } from './win32'; diff --git a/src/common/node/robot/nircmd.ts b/src/common/node/robot/nircmd.ts index 741fcf88..d664b512 100644 --- a/src/common/node/robot/nircmd.ts +++ b/src/common/node/robot/nircmd.ts @@ -1,4 +1,4 @@ -import { sleep } from '@/common/util'; +import { sleep } from '@/common'; import { BreachProtocolRobotKeys } from './robot'; import { WindowsRobot } from './win32'; diff --git a/src/common/node/robot/robot.ts b/src/common/node/robot/robot.ts index bec46011..4c028429 100644 --- a/src/common/node/robot/robot.ts +++ b/src/common/node/robot/robot.ts @@ -1,5 +1,5 @@ +import { sleep } from '@/common'; import * as k from '@/common/keyboard'; -import { sleep } from '@/common/util'; import { execFile } from 'child_process'; import { join } from 'path'; import sanitize from 'sanitize-filename'; diff --git a/src/common/node/robot/xdotool.ts b/src/common/node/robot/xdotool.ts index 58bc359a..8773ba37 100644 --- a/src/common/node/robot/xdotool.ts +++ b/src/common/node/robot/xdotool.ts @@ -1,5 +1,5 @@ +import { sleep } from '@/common'; import * as k from '@/common/keyboard'; -import { sleep } from '@/common/util'; import { BreachProtocolRobot, BreachProtocolRobotKeys, diff --git a/src/core/index.ts b/src/core/index.ts index 0474eac7..99387130 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -7,7 +7,10 @@ export type { BreachProtocolResultJSON, BreachProtocolStrategy, } from './solver/breach-protocol'; +export { HexCodeSequence } from './solver/hex-code-sequence'; export { FocusHierarchyProvider } from './solver/hierarchy/focus-hierarchy-provider'; export type { HierarchyProvider } from './solver/hierarchy/hierarchy-provider'; export { IndexHierarchyProvider } from './solver/hierarchy/index-hierarchy-provider'; +export { TypesHierarchyProvider } from './solver/hierarchy/types-hierarchy-provider'; export type { SequenceJSON } from './solver/sequence'; +export * from './daemons'; diff --git a/src/core/ocr/ocr.test.ts b/src/core/ocr/ocr.test.ts index 98dc92f2..91a99adf 100644 --- a/src/core/ocr/ocr.test.ts +++ b/src/core/ocr/ocr.test.ts @@ -1,5 +1,7 @@ -import { SharpImageContainer } from '@/common/node'; -import { WasmBreachProtocolRecognizer } from '@/common/node/recognizer-wasm'; +import { + SharpImageContainer, + WasmBreachProtocolRecognizer, +} from '@/common/node'; import type { BreachProtocolLanguage } from '@/core'; import { AppSettings } from '@/electron/common'; import { join } from 'path'; diff --git a/src/core/solver/breach-protocol.ts b/src/core/solver/breach-protocol.ts index 4aed8f73..454e40f1 100644 --- a/src/core/solver/breach-protocol.ts +++ b/src/core/solver/breach-protocol.ts @@ -62,9 +62,9 @@ export class BreachProtocolResult implements Serializable { // since in very rare cases longer daemon could create // better sequence than its shorter peers(bigger overlap). const shouldForceClose = daemons - .filter((d, i) => !this.sequence.indexes.includes(i)) + .filter((_, i) => !this.sequence.indexes.includes(i)) .some((d) => { - const daemon = d.map(fromHex).join(''); + const daemon = HexCodeSequence.fromHex(d); const r = memoizedFindOverlap(base, daemon); // If potential result(which will never happen) will diff --git a/src/core/solver/hierarchy/focus-hierarchy-provider.ts b/src/core/solver/hierarchy/focus-hierarchy-provider.ts index 187bd193..a00234a8 100644 --- a/src/core/solver/hierarchy/focus-hierarchy-provider.ts +++ b/src/core/solver/hierarchy/focus-hierarchy-provider.ts @@ -1,4 +1,4 @@ -import { BreachProtocolRawData } from '@/core/common'; +import { BreachProtocolRawData } from '../../common'; import { HierarchyProvider } from './hierarchy-provider'; /** Focuses one daemon, and applies index to others. */ diff --git a/src/core/solver/hierarchy/index-hierarchy-provider.ts b/src/core/solver/hierarchy/index-hierarchy-provider.ts index f05c2749..e517ffa5 100644 --- a/src/core/solver/hierarchy/index-hierarchy-provider.ts +++ b/src/core/solver/hierarchy/index-hierarchy-provider.ts @@ -1,4 +1,4 @@ -import { BreachProtocolRawData } from '@/core/common'; +import { BreachProtocolRawData } from '../../common'; import { HierarchyProvider } from './hierarchy-provider'; /** Marks each daemon with its index. */ diff --git a/src/core/solver/hierarchy/types-hierarchy-provider.ts b/src/core/solver/hierarchy/types-hierarchy-provider.ts index e135ed59..78298be8 100644 --- a/src/core/solver/hierarchy/types-hierarchy-provider.ts +++ b/src/core/solver/hierarchy/types-hierarchy-provider.ts @@ -1,4 +1,4 @@ -import { BreachProtocolRawData } from '@/core/common'; +import { BreachProtocolRawData } from '../../common'; import { HierarchyProvider } from './hierarchy-provider'; import { IndexHierarchyProvider } from './index-hierarchy-provider'; diff --git a/src/electron/common/options.ts b/src/electron/common/options.ts index a0d87e67..428c0e7e 100644 --- a/src/electron/common/options.ts +++ b/src/electron/common/options.ts @@ -22,7 +22,7 @@ import { DAEMON_OPTICS_JAMMER, DAEMON_TURRET_SHUTDOWN, DAEMON_WEAPONS_JAMMER, -} from '@/core/daemons'; +} from '@/core'; import { AppSettings } from './common'; interface BreachProtocolOption { diff --git a/src/electron/renderer/components/DaemonPriority.tsx b/src/electron/renderer/components/DaemonPriority.tsx index f4f7a5a9..ff2daa7e 100644 --- a/src/electron/renderer/components/DaemonPriority.tsx +++ b/src/electron/renderer/components/DaemonPriority.tsx @@ -1,6 +1,21 @@ -import { DaemonId } from '@/core'; -import * as d from '@/core/daemons'; -import { eng } from '@/core/daemons-i18n'; +import { + DaemonId, + DAEMON_CAMERA_SHUTDOWN, + DAEMON_DATAMINE_COPY_MALWARE, + DAEMON_DATAMINE_CRAFTING_SPECS, + DAEMON_DATAMINE_V1, + DAEMON_DATAMINE_V2, + DAEMON_DATAMINE_V3, + DAEMON_FRIENDLY_TURRETS, + DAEMON_GAIN_ACCESS, + DAEMON_ICEPICK, + DAEMON_MASS_VULNERABILITY, + DAEMON_NEUTRALIZE_MALWARE, + DAEMON_OPTICS_JAMMER, + DAEMON_TURRET_SHUTDOWN, + DAEMON_WEAPONS_JAMMER, + eng, +} from '@/core'; import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { flushSync } from 'react-dom'; import styled from 'styled-components'; @@ -46,29 +61,29 @@ function moveInArray(data: T[], from: number, to: number) { } const commonDaemons: ReadonlySet = new Set([ - d.DAEMON_DATAMINE_V1, - d.DAEMON_DATAMINE_V2, - d.DAEMON_DATAMINE_V3, - d.DAEMON_ICEPICK, + DAEMON_DATAMINE_V1, + DAEMON_DATAMINE_V2, + DAEMON_DATAMINE_V3, + DAEMON_ICEPICK, ]); const perkDaemons: ReadonlySet = new Set([ - d.DAEMON_MASS_VULNERABILITY, - d.DAEMON_CAMERA_SHUTDOWN, - d.DAEMON_FRIENDLY_TURRETS, - d.DAEMON_TURRET_SHUTDOWN, + DAEMON_MASS_VULNERABILITY, + DAEMON_CAMERA_SHUTDOWN, + DAEMON_FRIENDLY_TURRETS, + DAEMON_TURRET_SHUTDOWN, ]); const legendaryDaemons: ReadonlySet = new Set([ - d.DAEMON_OPTICS_JAMMER, - d.DAEMON_WEAPONS_JAMMER, + DAEMON_OPTICS_JAMMER, + DAEMON_WEAPONS_JAMMER, ]); const specialDaemons: ReadonlySet = new Set([ - d.DAEMON_DATAMINE_COPY_MALWARE, - d.DAEMON_NEUTRALIZE_MALWARE, - d.DAEMON_GAIN_ACCESS, - d.DAEMON_DATAMINE_CRAFTING_SPECS, + DAEMON_DATAMINE_COPY_MALWARE, + DAEMON_NEUTRALIZE_MALWARE, + DAEMON_GAIN_ACCESS, + DAEMON_DATAMINE_CRAFTING_SPECS, ]); function getDaemonType(id: DaemonId): DaemonType { diff --git a/src/electron/renderer/components/HistoryViewer.tsx b/src/electron/renderer/components/HistoryViewer.tsx index 98bea9bf..c352c761 100644 --- a/src/electron/renderer/components/HistoryViewer.tsx +++ b/src/electron/renderer/components/HistoryViewer.tsx @@ -2,7 +2,7 @@ import { BreachProtocolResultJSON, BUFFER_SIZE_MIN, DaemonsRawData, - fromHex, + HexCodeSequence, isBufferSizeFragment, isDaemonsFragment, isGridFragment, @@ -33,11 +33,11 @@ function getDaemonBounds(daemons: DaemonsRawData, sequence?: SequenceJSON) { return []; } - const st = sequence.value.map(fromHex).join('') ?? ''; + const st = HexCodeSequence.fromHex(sequence?.value ?? []); return daemons .map((daemon) => { - const dt = daemon.map(fromHex).join(''); + const dt = HexCodeSequence.fromHex(daemon); const start = st.indexOf(dt); if (start === -1) { diff --git a/src/electron/renderer/components/RecognitionSettings.tsx b/src/electron/renderer/components/RecognitionSettings.tsx index ed8695e8..e34f4a55 100644 --- a/src/electron/renderer/components/RecognitionSettings.tsx +++ b/src/electron/renderer/components/RecognitionSettings.tsx @@ -1,5 +1,5 @@ +import type { BreachProtocolLanguage } from '@/core'; import { BUFFER_SIZE_MAX } from '@/core'; -import type { BreachProtocolLanguage } from '@/core/daemons-i18n'; import { AppSettings } from '@/electron/common'; import type { ScreenshotDisplayOutput } from 'screenshot-desktop'; import { getDisplayName, nativeDialog } from '../common'; diff --git a/src/electron/worker/autosolver.ts b/src/electron/worker/autosolver.ts index 695b9cc3..dbcb1048 100644 --- a/src/electron/worker/autosolver.ts +++ b/src/electron/worker/autosolver.ts @@ -1,12 +1,12 @@ -import { BitMask, sleep, uniqueWith } from '@/common'; +import { BitMask, sleep } from '@/common'; import { BreachProtocolKeyboardResolver, BreachProtocolMouseResolver, BreachProtocolResolver, BreachProtocolRobot, SharpImageContainer, + WasmBreachProtocolRecognizer, } from '@/common/node'; -import { WasmBreachProtocolRecognizer } from '@/common/node/recognizer-wasm'; import { BreachProtocol, breachProtocolOCR, diff --git a/src/electron/worker/worker.ts b/src/electron/worker/worker.ts index cbd1b632..9284b254 100644 --- a/src/electron/worker/worker.ts +++ b/src/electron/worker/worker.ts @@ -3,9 +3,9 @@ import { BreachProtocolRobot, NirCmdRobot, SharpImageContainer, + WasmBreachProtocolRecognizer, XDoToolRobot, } from '@/common/node'; -import { WasmBreachProtocolRecognizer } from '@/common/node/recognizer-wasm'; import { BreachProtocolBufferSizeFragment, BreachProtocolDaemonsFragment, @@ -15,10 +15,10 @@ import { BreachProtocolResultJSON, BreachProtocolTypesFragment, FocusHierarchyProvider, + HierarchyProvider, IndexHierarchyProvider, + TypesHierarchyProvider, } from '@/core'; -import { HierarchyProvider } from '@/core/solver/hierarchy/hierarchy-provider'; -import { TypesHierarchyProvider } from '@/core/solver/hierarchy/types-hierarchy-provider'; import { Action, ActionTypes,