Skip to content

Commit

Permalink
Track already searched events
Browse files Browse the repository at this point in the history
  • Loading branch information
0xPxt committed Feb 14, 2025
1 parent fa29747 commit 4a27731
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/Zemu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { ClickNavigation, scheduleToNavElement, TouchNavigation } from "./action
import { getTouchElement } from "./buttons";
import {
ActionKind,
areEventsEqual,
ButtonKind,
SwipeDirection,
type IButton,
Expand Down Expand Up @@ -93,6 +94,7 @@ export default class Zemu {

public mainMenuSnapshot!: ISnapshot;
public initialEvents!: IEvent[];
private searchedEvents: IEvent[] = [];

constructor(
elfPath: string,
Expand Down Expand Up @@ -124,6 +126,7 @@ export default class Zemu {

this.containerName = BASE_NAME + rndstr.generate(8);
this.emuContainer = new EmuContainer(this.elfPath, this.libElfs, emuImage, this.containerName);
this.searchedEvents = [];
}

static LoadPng2RGB(filename: string): PNGWithMetadata {
Expand Down Expand Up @@ -711,11 +714,28 @@ export default class Zemu {
imageIndex += 1;
filename = this.getSnapshotPath(snapshotPrefixTmp, imageIndex, takeSnapshots);

found = events.some((event: IEvent) => textRegex.test(event.text));
if (found) break;
for (let i = 0; i < this.searchedEvents.length; i++) {
if (!areEventsEqual(this.searchedEvents[i], events[i])) {
this.searchedEvents = [];
break;
}
}

const nonSearchedEvents = events.slice(this.searchedEvents.length);

const nav: INavElement = {
type: touchDevice ? ActionKind.Touch : ActionKind.RightClick,
for (const event of nonSearchedEvents) {
this.searchedEvents.push(event);
if (textRegex.test(event.text)) {
found = true;
break;
}
}

if (found)
break;

const nav: INavElement = {
type: touchDevice ? ActionKind.Touch : ActionKind.RightClick,
button:
imageIndex === 1 && isBlindSigning
? getTouchElement(this.startOptions.model, ButtonKind.RejectButton)
Expand Down
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ export interface IEvent {
h: number;
clear: boolean;
}

export function areEventsEqual(event1: IEvent, event2: IEvent): boolean {
return event1.text === event2.text &&
event1.x === event2.x &&
event1.y === event2.y &&
event1.w === event2.w &&
event1.h === event2.h &&
event1.clear === event2.clear;
}

export interface ISwipeCoordinates {
x: number;
y: number;
Expand Down

0 comments on commit 4a27731

Please sign in to comment.