From d32922bf205cfda43f6e504aef92e7be7f8061d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Sat, 26 Mar 2022 01:31:44 +0100 Subject: [PATCH] fix: moved some function to utils --- src/garage.py | 48 ++++++++++++++++++++---------------------------- src/main.py | 6 +++--- src/utils.py | 12 ++++++++++-- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/garage.py b/src/garage.py index c3e98f9..b3d056e 100644 --- a/src/garage.py +++ b/src/garage.py @@ -1,10 +1,10 @@ import itertools import logging -from time import sleep +import time import numpy as np -import init +from utils import motion, tap CENTER = (1000, 500) @@ -32,7 +32,7 @@ NB_WHEELS = 23 NB_HATS = 20 NB_TEAMS = 2 -DELAY = 0.01 +DELAY = 0.1 NB_PRIMARY_COLORS = 3 NB_SECONDARY_COLORS = 1 @@ -47,14 +47,6 @@ old_secondary_color = [None, None] old_team = None -def tap(pos): - init.device.shell(f"input tap {pos[0]} {pos[1]}") - - -def motion(pos, type): - init.device.shell(f"input motionevent {type} {pos[0]} {pos[1]}") - - def selectColor(team: int, primary_color: float, secondary_color: float): global old_team @@ -87,13 +79,13 @@ def selectColor(team: int, primary_color: float, secondary_color: float): def rotate(x, y): motion(CENTER, "DOWN") motion(np.array(CENTER) + np.array((x, y)), "MOVE") - sleep(DELAY) + # time.sleep(0) motion(np.array(CENTER) + np.array((x, y)), "UP") def selectItem(kind, i): tap(kind) - sleep(DELAY) + time.sleep(DELAY) col = i % 3 row = i // 3 @@ -125,7 +117,7 @@ def selectModel(model: int): motion(CENTER, "DOWN") motion(np.array(CENTER) + np.array((1000, 0)), "MOVE") motion(np.array(CENTER) + np.array((1000, 0)), "UP") - sleep(1) + time.sleep(1) tap(SELECT_CAR_BTN) old_model = 0 @@ -143,7 +135,7 @@ def selectModel(model: int): motion(CENTER, "DOWN") motion(np.array(CENTER) + np.array((1000, 0)), "MOVE") motion(np.array(CENTER) + np.array((1000, 0)), "UP") - sleep(1) + time.sleep(1) tap(SELECT_CAR_BTN) @@ -157,39 +149,37 @@ def newCar(model: int, sticker: int, wheel: int, hat: int, team: int, primary_co global old_secondary_color global old_team - sleep(0.5) - # goto garage menu tap(GARAGE_BTN) - sleep(DELAY) + time.sleep(DELAY) # select new model, if necessary if model != old_model: selectModel(model) old_model = model - sleep(DELAY) + time.sleep(DELAY) # goto loadout editor tap(EDIT_LOADOUT_BTN) - sleep(DELAY) + time.sleep(DELAY) # select sticker, if necessary if sticker != old_sticker: selectItem(STICKER_MENU_BTN, sticker) old_sticker = sticker - sleep(DELAY) + time.sleep(DELAY) # select wheel, if necessary if wheel != old_wheel: selectItem(WHEEL_MENU_BTN, wheel) old_wheel = wheel - sleep(DELAY) + time.sleep(DELAY) # select hat, if necessary if hat != old_hat: selectItem(HAT_MENU_BTN, hat) old_hat = hat - sleep(DELAY) + time.sleep(DELAY) # select color, if necessary if team != old_team or primary_color != old_primary_color[team] or secondary_color != old_secondary_color[team]: @@ -197,13 +187,15 @@ def newCar(model: int, sticker: int, wheel: int, hat: int, team: int, primary_co old_team = team old_primary_color[old_team] = primary_color old_secondary_color[old_team] = secondary_color - sleep(DELAY) + time.sleep(DELAY) # goto main menu tap(BACK_BTN) - sleep(DELAY) + time.sleep(DELAY) + tap(BACK_BTN) + time.sleep(DELAY) + tap(BACK_BTN) tap(BACK_BTN) - sleep(DELAY) def generate_loadouts(): @@ -230,12 +222,12 @@ def generate_loadouts(): logging.debug(f"number of loadouts: {nb_loadouts}") - return loadouts + return loadouts, nb_loadouts if __name__ == "__main__": - loadouts = generate_loadouts() + loadouts, _ = generate_loadouts() for ((model, sticker), wheel, hat, team, primary_color, secondary_color) in loadouts: print(f"next loadout: {((model, sticker), wheel, hat, team, primary_color, secondary_color)}") newCar(model, sticker, wheel, hat, team, primary_color, secondary_color) diff --git a/src/main.py b/src/main.py index e0a27da..6bb75fb 100644 --- a/src/main.py +++ b/src/main.py @@ -66,15 +66,15 @@ if __name__ == "__main__": for x_rotation in range(NB_ROTATIONS): uuid = utils.screenshot() utils.insert(db, uuid, loadout, x_rotation, 0) - garage.rotate(130, 0) + # garage.rotate(130, 0) # tac elapsed = time.time() - elapsed eta_list[i % NB_ETA] = elapsed - estimation = (nb_loadouts - i) * sum(eta_list) / NB_ETA + estimation = int((nb_loadouts - i) * sum(eta_list) / NB_ETA) logging.debug( - f"loadout {str(i).zfill(digits_loadout)}/{nb_loadouts} ({elapsed:.02f}s, ETA: {estimation:.02f}s): {loadout}" + f"loadout {str(i).zfill(digits_loadout)}/{nb_loadouts} ({elapsed:.02f}s, ETA: {estimation}s): {loadout}" ) # fermeture de la db sqlite3 diff --git a/src/utils.py b/src/utils.py index 3996c27..652b65d 100644 --- a/src/utils.py +++ b/src/utils.py @@ -25,6 +25,14 @@ DATA_FOLDER = "data/" UserList = list[tuple[int, str]] +def tap(pos): + device.shell(f"input tap {pos[0]} {pos[1]}") + + +def motion(pos, type): + device.shell(f"input motionevent {type} {pos[0]} {pos[1]}") + + def connect_adb() -> ppadb.device.Device: client: ppadb.client.Client = ppadb.client.Client(host=ADB_HOST, port=ADB_PORT) devices: list[ppadb.device.Device] = client.devices() @@ -32,6 +40,7 @@ def connect_adb() -> ppadb.device.Device: devices_names: list[ppadb.command.serial.Serial] = list(map(lambda d: d.serial, devices)) logging.debug(f"detected devices: {devices_names}") + global device if len(devices) == 1: device = devices[0] elif len(devices) == 0: @@ -78,7 +87,6 @@ def start_game(device: ppadb.device.Device, users: UserList) -> None: logging.debug(f"selected user: {user_name}") - logging.debug("game activity started") device.shell(f"am start --user {user_id} -n {PSYONIX_PACKAGE_NAME}/{PSYONIX_ACTIVITY_NAME}") logging.debug("game activity started") @@ -108,7 +116,7 @@ def startup() -> None: users = detect_game(device, users) start_game(device, users) - while not (detect_zen_mode(device) and detect_focus(device)): + while not (detect_zen_mode(device) or detect_focus(device)): time.sleep(DELAY_DETECT) time.sleep(DELAY_DETECT)