Skip to content

Commit

Permalink
feat(core): add ability to order sequences by types
Browse files Browse the repository at this point in the history
fixes #249
  • Loading branch information
marcincichocki committed Oct 15, 2022
1 parent 94f667b commit 1ab78a3
Show file tree
Hide file tree
Showing 13 changed files with 490 additions and 49 deletions.
13 changes: 6 additions & 7 deletions src/core/solver/hierarchy/focus-hierarchy-provider.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { BreachProtocolRawData } from '@/core/common';
import { HierarchyProvider } from './hierarchy-provider';
import { IndexHierarchyProvider } from './index-hierarchy-provider';

/** Focuses one daemon, and applies index to others. */
export class FocusHierarchyProvider
extends IndexHierarchyProvider
implements HierarchyProvider<BreachProtocolRawData>
{
constructor(private readonly focusedDaemonIndex: number) {
super();
}
constructor(
private readonly focusedDaemonIndex: number,
private readonly base: HierarchyProvider<BreachProtocolRawData>
) {}

override provide(rawData: BreachProtocolRawData) {
const hierarchy = super.provide(rawData);
provide(rawData: BreachProtocolRawData) {
const hierarchy = this.base.provide(rawData);

if (this.focusedDaemonIndex in hierarchy) {
hierarchy[this.focusedDaemonIndex] = Number.POSITIVE_INFINITY;
Expand Down
21 changes: 21 additions & 0 deletions src/core/solver/hierarchy/types-hierarchy-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { BreachProtocolRawData } from '@/core/common';
import { HierarchyProvider } from './hierarchy-provider';
import { IndexHierarchyProvider } from './index-hierarchy-provider';

export class TypesHierarchyProvider
implements HierarchyProvider<BreachProtocolRawData>
{
private readonly fallback = new IndexHierarchyProvider();

constructor(private readonly typesHierarchy: string[]) {}

provide(data: BreachProtocolRawData): number[] {
if (data.types) {
return data.types.map((type) =>
this.typesHierarchy.findIndex((d) => d === type)
);
}

return this.fallback.provide(data);
}
}
3 changes: 2 additions & 1 deletion src/core/solver/sequence-factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ describe('Sequence factory', () => {

describe('Focus hierarchy', () => {
it('should return sequences sorted by selected daemon', () => {
const provider = new FocusHierarchyProvider(0);
const base = new IndexHierarchyProvider();
const provider = new FocusHierarchyProvider(0, base);
const rawData: BreachProtocolRawData = {
grid: [],
bufferSize: 5,
Expand Down
3 changes: 3 additions & 0 deletions src/electron/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
BreachProtocolOCROptions,
BreachProtocolOptions,
BreachProtocolResultJSON,
DaemonId,
FragmentId,
} from '@/core';
import type { ScreenshotDisplayOutput } from 'screenshot-desktop';
Expand Down Expand Up @@ -96,6 +97,8 @@ export interface AppSettings
focusOnError: boolean;
gameLang: BreachProtocolLanguage;
sortDaemonsBySequence: boolean;
hierarchy: 'index' | 'types';
daemonPriority: DaemonId[];
}

export interface AppStats {
Expand Down
45 changes: 44 additions & 1 deletion src/electron/common/options.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import {
JSONValue,
VK_ARROW_DOWN,
VK_ARROW_LEFT,
VK_ARROW_RIGHT,
VK_ARROW_UP,
VK_ENTER,
VK_ESCAPE,
} from '@/common';
import {
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,
} from '@/core/daemons';
import { AppSettings } from './common';

interface BreachProtocolOption {
id: keyof AppSettings;
description: string;
defaultValue: boolean | string | number;
defaultValue: JSONValue;
}

export const options: BreachProtocolOption[] = [
Expand Down Expand Up @@ -290,6 +307,32 @@ export const options: BreachProtocolOption[] = [
description: 'Sort daemons in history viewer by order in the sequence.',
defaultValue: false,
},
{
id: 'hierarchy',
description:
'Hierarchy determines order of generated sequences. In index hierarchy each daemon is more important than daemons above it. In types hierarchy type of a daemon determines its value(requires types to be recognized).',
defaultValue: 'index',
},
{
id: 'daemonPriority',
description: 'Specifiy priority of each daemon.',
defaultValue: [
DAEMON_DATAMINE_COPY_MALWARE,
DAEMON_NEUTRALIZE_MALWARE,
DAEMON_GAIN_ACCESS,
DAEMON_DATAMINE_CRAFTING_SPECS,
DAEMON_OPTICS_JAMMER,
DAEMON_WEAPONS_JAMMER,
DAEMON_CAMERA_SHUTDOWN,
DAEMON_MASS_VULNERABILITY,
DAEMON_FRIENDLY_TURRETS,
DAEMON_TURRET_SHUTDOWN,
DAEMON_ICEPICK,
DAEMON_DATAMINE_V3,
DAEMON_DATAMINE_V2,
DAEMON_DATAMINE_V1,
],
},
];

function optionsToObject<T>(cb: (option: BreachProtocolOption) => T) {
Expand Down
32 changes: 31 additions & 1 deletion src/electron/renderer/components/AutoSolverSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { AppSettings, WorkerStatus } from '@/electron/common';
import { useState } from 'react';
import { nativeDialog, updateWorkerStatus } from '../common';
import { FlatButton } from './Buttons';
import { DaemonPriority } from './DaemonPriority';
import { File } from './File';
import { Spacer } from './Flex';
import { Field, Label, useForm } from './Form';
import { Section } from './Section';
import { Select } from './Select';
import { Select, SelectOption } from './Select';
import { ShallowKeyBind } from './ShallowKeyBind';
import { Switch } from './Switch';

const inputDeviceOptions = [
{ name: 'Keyboard(recommended)', value: 'keyboard' },
{ name: 'Mouse', value: 'mouse' },
];
const hierarchyOptions: SelectOption[] = [
{ name: 'Index', value: 'index' },
{ name: 'Types', value: 'types' },
];

const engineOptions =
BUILD_PLATFORM === 'win32'
Expand All @@ -22,6 +30,7 @@ const engineOptions =

export const AutoSolverSettings = () => {
const { values } = useForm<AppSettings>();
const [isOpen, setIsOpen] = useState(false);

function changeEngine(engine: string) {
if (engine === 'ahk') {
Expand Down Expand Up @@ -86,6 +95,27 @@ export const AutoSolverSettings = () => {
<Label>Auto exit</Label>
<Switch />
</Field>
<Field name="hierarchy">
<Label>Hierarchy</Label>
<Select
options={hierarchyOptions}
disabled={values.skipTypesFragment}
/>
</Field>
{values.hierarchy === 'types' && (
<Field name="daemonPriority">
<Label>Daemon priority</Label>
<Spacer />
<FlatButton
color="accent"
type="button"
onClick={() => setIsOpen(true)}
>
Change priority
</FlatButton>
<DaemonPriority isOpen={isOpen} onClose={() => setIsOpen(false)} />
</Field>
)}
<Field name="engine" onValueChange={changeEngine}>
<Label>Engine</Label>
<Select
Expand Down

0 comments on commit 1ab78a3

Please sign in to comment.