Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· openaiHugging Face Suzhen/CodeChat

export async function goTo(page, path, current={x,y}) { console.log('trasa smieciu',…

  1. User

    export async function goTo(page, path, current={x,y}) { console.log('trasa smieciu', path); for (let i = 0; i < path.length - 1; i++) { const next = path[i]; let direction;

    if (next.x > current.x) {
      direction = 'KeyD';
      current.x++;
    } else if (next.x < current.x) {
      direction = 'KeyA';
      current.x--;
    } else if (next.y > current.y) {
      direction = 'KeyS';
      current.y++;
    } else if (next.y < current.y) {
      direction = 'KeyW';
      current.y--;
    }
    if (direction) {
      await moveHero(page, direction);
    }
    async function moveHero(page, direct) {
    await page.focus('body');
    await page.keyboard.down(direct);
    setTimeout(async() => {
      await page.keyboard.up(direct);
    }, 100);
    await new Promise(resolve => setTimeout(resolve, 200));
    

    } } } /*

    Zamień tą funkcje na taką, która jeżeli w którąś strone jest więcej niż 2 kroki to zamiast osobno klikać keydown i keyup na każdej to trzyma keydown przez x kroków gdzie x>2 i dopiero wtedy zwalnia i kontynuuje reszte kroków

  2. Assistant

    Zmodyfikowałem funkcję, aby obsługiwała dłuższe trzymania klawiszy w przypadku większej liczby kroków w jednym kierunku. Teraz, gdy jest więcej niż 2 kroki w jednym kierunku, funkcja trzyma wciśnięty klawisz przez całą potrzebną ilość kroków, a potem go zwalnia.

    export async function goTo(page, path, current = { x, y }) {
      console.log("trasa smieciu", path);
      let direction, steps = 0;
    
      for (let i = 0; i < path.length - 1; i++) {
        const next = path[i];
        let newDirection;
    
        if (next.x > current.x) {
          newDirection = "KeyD";
          current.x++;
        } else if (next.x < current.x) {
          newDirection = "KeyA";
          current.x--;
        } else if (next.y > current.y) {
          newDirection = "KeyS";
          current.y++;
        } else if (next.y < current.y) {
          newDirection = "KeyW";
          current.y--;
        }
    
        if (direction === newDirection) {
          steps++;
        } else {
          if (direction) {
            await moveHero(page, direction, steps);
          }
          direction = newDirection;
          steps = 1;
        }
      }
    
      if (direction) {
        await moveHero(page, direction, steps);
      }
    
      async function moveHero(page, direct, steps) {
        const delay = 100;
        const delayBetweenSteps = 200;
        
        await page.focus("body");
        
        if (steps > 2) {
          await page.keyboard.down(direct);
          await new Promise(resolve => setTimeout(resolve, steps * delay));
          await page.keyboard.up(direct);
          await new Promise(resolve => setTimeout(resolve, delayBetweenSteps));
        } else {
          while (steps > 0) {
            await page.keyboard.down(direct);
            await new Promise(resolve => setTimeout(resolve, delay));
            await page.keyboard.up(direct);
            await new Promise(resolve => setTimeout(resolve, delayBetweenSteps));
            steps--;
          }
        }
      }
    }
    

    Teraz funkcja sprawdzi, czy następna komórka ścieżki ma ten sam kierunek. Jeśli tak, zwiększa liczbę kroków. Jeśli kierunek się zmienia, zostanie wykonana funkcja moveHero. W funkcji moveHero dodano również zmienne delay i delayBetweenSteps, które można łatwo dostosować do potrzeb.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.