fix: moved some function to utils

This commit is contained in:
Laureηt 2022-03-26 01:31:44 +01:00
parent e9f0667291
commit d32922bf20
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
3 changed files with 33 additions and 33 deletions

View file

@ -1,10 +1,10 @@
import itertools import itertools
import logging import logging
from time import sleep import time
import numpy as np import numpy as np
import init from utils import motion, tap
CENTER = (1000, 500) CENTER = (1000, 500)
@ -32,7 +32,7 @@ NB_WHEELS = 23
NB_HATS = 20 NB_HATS = 20
NB_TEAMS = 2 NB_TEAMS = 2
DELAY = 0.01 DELAY = 0.1
NB_PRIMARY_COLORS = 3 NB_PRIMARY_COLORS = 3
NB_SECONDARY_COLORS = 1 NB_SECONDARY_COLORS = 1
@ -47,14 +47,6 @@ old_secondary_color = [None, None]
old_team = 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): def selectColor(team: int, primary_color: float, secondary_color: float):
global old_team global old_team
@ -87,13 +79,13 @@ def selectColor(team: int, primary_color: float, secondary_color: float):
def rotate(x, y): def rotate(x, y):
motion(CENTER, "DOWN") motion(CENTER, "DOWN")
motion(np.array(CENTER) + np.array((x, y)), "MOVE") motion(np.array(CENTER) + np.array((x, y)), "MOVE")
sleep(DELAY) # time.sleep(0)
motion(np.array(CENTER) + np.array((x, y)), "UP") motion(np.array(CENTER) + np.array((x, y)), "UP")
def selectItem(kind, i): def selectItem(kind, i):
tap(kind) tap(kind)
sleep(DELAY) time.sleep(DELAY)
col = i % 3 col = i % 3
row = i // 3 row = i // 3
@ -125,7 +117,7 @@ def selectModel(model: int):
motion(CENTER, "DOWN") motion(CENTER, "DOWN")
motion(np.array(CENTER) + np.array((1000, 0)), "MOVE") motion(np.array(CENTER) + np.array((1000, 0)), "MOVE")
motion(np.array(CENTER) + np.array((1000, 0)), "UP") motion(np.array(CENTER) + np.array((1000, 0)), "UP")
sleep(1) time.sleep(1)
tap(SELECT_CAR_BTN) tap(SELECT_CAR_BTN)
old_model = 0 old_model = 0
@ -143,7 +135,7 @@ def selectModel(model: int):
motion(CENTER, "DOWN") motion(CENTER, "DOWN")
motion(np.array(CENTER) + np.array((1000, 0)), "MOVE") motion(np.array(CENTER) + np.array((1000, 0)), "MOVE")
motion(np.array(CENTER) + np.array((1000, 0)), "UP") motion(np.array(CENTER) + np.array((1000, 0)), "UP")
sleep(1) time.sleep(1)
tap(SELECT_CAR_BTN) 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_secondary_color
global old_team global old_team
sleep(0.5)
# goto garage menu # goto garage menu
tap(GARAGE_BTN) tap(GARAGE_BTN)
sleep(DELAY) time.sleep(DELAY)
# select new model, if necessary # select new model, if necessary
if model != old_model: if model != old_model:
selectModel(model) selectModel(model)
old_model = model old_model = model
sleep(DELAY) time.sleep(DELAY)
# goto loadout editor # goto loadout editor
tap(EDIT_LOADOUT_BTN) tap(EDIT_LOADOUT_BTN)
sleep(DELAY) time.sleep(DELAY)
# select sticker, if necessary # select sticker, if necessary
if sticker != old_sticker: if sticker != old_sticker:
selectItem(STICKER_MENU_BTN, sticker) selectItem(STICKER_MENU_BTN, sticker)
old_sticker = sticker old_sticker = sticker
sleep(DELAY) time.sleep(DELAY)
# select wheel, if necessary # select wheel, if necessary
if wheel != old_wheel: if wheel != old_wheel:
selectItem(WHEEL_MENU_BTN, wheel) selectItem(WHEEL_MENU_BTN, wheel)
old_wheel = wheel old_wheel = wheel
sleep(DELAY) time.sleep(DELAY)
# select hat, if necessary # select hat, if necessary
if hat != old_hat: if hat != old_hat:
selectItem(HAT_MENU_BTN, hat) selectItem(HAT_MENU_BTN, hat)
old_hat = hat old_hat = hat
sleep(DELAY) time.sleep(DELAY)
# select color, if necessary # select color, if necessary
if team != old_team or primary_color != old_primary_color[team] or secondary_color != old_secondary_color[team]: 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_team = team
old_primary_color[old_team] = primary_color old_primary_color[old_team] = primary_color
old_secondary_color[old_team] = secondary_color old_secondary_color[old_team] = secondary_color
sleep(DELAY) time.sleep(DELAY)
# goto main menu # goto main menu
tap(BACK_BTN) tap(BACK_BTN)
sleep(DELAY) time.sleep(DELAY)
tap(BACK_BTN)
time.sleep(DELAY)
tap(BACK_BTN)
tap(BACK_BTN) tap(BACK_BTN)
sleep(DELAY)
def generate_loadouts(): def generate_loadouts():
@ -230,12 +222,12 @@ def generate_loadouts():
logging.debug(f"number of loadouts: {nb_loadouts}") logging.debug(f"number of loadouts: {nb_loadouts}")
return loadouts return loadouts, nb_loadouts
if __name__ == "__main__": if __name__ == "__main__":
loadouts = generate_loadouts() loadouts, _ = generate_loadouts()
for ((model, sticker), wheel, hat, team, primary_color, secondary_color) in 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)}") print(f"next loadout: {((model, sticker), wheel, hat, team, primary_color, secondary_color)}")
newCar(model, sticker, wheel, hat, team, primary_color, secondary_color) newCar(model, sticker, wheel, hat, team, primary_color, secondary_color)

View file

@ -66,15 +66,15 @@ if __name__ == "__main__":
for x_rotation in range(NB_ROTATIONS): for x_rotation in range(NB_ROTATIONS):
uuid = utils.screenshot() uuid = utils.screenshot()
utils.insert(db, uuid, loadout, x_rotation, 0) utils.insert(db, uuid, loadout, x_rotation, 0)
garage.rotate(130, 0) # garage.rotate(130, 0)
# tac # tac
elapsed = time.time() - elapsed elapsed = time.time() - elapsed
eta_list[i % NB_ETA] = 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( 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 # fermeture de la db sqlite3

View file

@ -25,6 +25,14 @@ DATA_FOLDER = "data/"
UserList = list[tuple[int, str]] 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: def connect_adb() -> ppadb.device.Device:
client: ppadb.client.Client = ppadb.client.Client(host=ADB_HOST, port=ADB_PORT) client: ppadb.client.Client = ppadb.client.Client(host=ADB_HOST, port=ADB_PORT)
devices: list[ppadb.device.Device] = client.devices() 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)) devices_names: list[ppadb.command.serial.Serial] = list(map(lambda d: d.serial, devices))
logging.debug(f"detected devices: {devices_names}") logging.debug(f"detected devices: {devices_names}")
global device
if len(devices) == 1: if len(devices) == 1:
device = devices[0] device = devices[0]
elif len(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(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}") device.shell(f"am start --user {user_id} -n {PSYONIX_PACKAGE_NAME}/{PSYONIX_ACTIVITY_NAME}")
logging.debug("game activity started") logging.debug("game activity started")
@ -108,7 +116,7 @@ def startup() -> None:
users = detect_game(device, users) users = detect_game(device, users)
start_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)
time.sleep(DELAY_DETECT) time.sleep(DELAY_DETECT)