Continuously play the first Python Sukusta MV

First time python

Until now, I used UWSC exclusively for PC automation work, so I was interested in Python, but I didn't have a chance to learn it, but I thought that I would not start somewhere due to the current situation of UWSC, so I started it the other day Thanks to Sukusta (love live sound social game), I got the motivation to automatically play the MV of the game, so I took this opportunity to start Python.

For the convenience of the content, it is almost about the automation macro of social games using Android emulation such as Nox and Bluestacks.

environment

Windows10 64bit Python3.8 64bit Bluestacks4

I was at a loss with Nox for Android emulation, but I used Bluestacks for Nox because the lip sync is off by about 10 frames.

Install pyautogui

pip install pyautogui

It seems that it cannot be excluded from automation with Python.

design

The operation is simply to press the MV button on the screen below and 名称未設定.jpg Press the play button at the point where the screen changes. 2.jpg After that, loop until the song is over and the MV button in image 1 is displayed.

code

Constant declaration part

MAIN_PATH=".\\MVPlay\\"
FILE_TYPE="*.png "
X:int=0
Y:int=1

Main code

 coding:utf-8
import pyautogui
import glob
import time
from pydef import*

def counterModeSerial(i:int,maxcount:int):
    if i>=maxcount:
        return 0
    else:
        return i+1

def main(files:list,loopmode:int,waittime:int):
    i:int=0

    while True:
        loc=pyautogui.locateCenterOnScreen(files[i])
        if not(loc==None):
            time.sleep(waittime)
            pyautogui.click(loc[X],loc[Y])
            i=counterModeSerial(i,len(files)-1)
        time.sleep(waittime)

flist=glob.glob(MAIN_PATH+FILE_TYPE)
main(flist,0,0.5)

Crop the image of the component you want to tap and put it in the folder so that it will be executed sequentially. In this case, it will be an image of a MV or a play button. If you create an MVPlay folder and put a png file in it, "Recognize-> Tap-> Next file-> Recognize ... Return to the beginning when the last image is recognized" is repeated in the order sorted by file name. Since the termination process is not included, you need to kill the process from the task manager unless you start it with the debugger.

If you put an image in a folder, it will recognize the image, click it, and transition to the next state, so it seems that it will be enough for 2D social network games as it is.

Miscellaneous feelings

Except for references and variable declarations, I think it's a good idea to work with about 10 lines of code, and I think it's just said to be simple and powerful. The locateOnScreen function does not support multi-display and only checks the primary display (I managed to replace the work monitor with the secondary), but there were some complaints such as slow image recognition, but overall It was easy to use. Isn't it because the old man thinks it's a little scary to express nesting with indentation, but is there an advantage that readability is improved because clean indentation is forced?

Finally

The goal was achieved for the time being, but with this, only one song can be looped, and the mouse cursor and active window are brought when the button is pressed, so we improved things such as sending commands via ADB. I would like to go.

Recommended Posts

Continuously play the first Python Sukusta MV
Continuously play the first Python Sukusta MV-Scrolling the song list-
First Python 3 ~ The beginning of repetition ~
See python for the first time
The first step in Python Matplotlib
Play by hitting the Riot Games API in Python First half
MongoDB for the first time in Python
First time python
First Python 3 ~ First comparison ~
The first web app created by Python beginners
The first step in the constraint satisfaction problem in Python
Play Python async
Play with 2016-Python
I tried python programming for the first time.
First time python
First Python ~ Coding 2 ~
First python [O'REILLY]
What I got into Python for the first time
I tried Python on Mac for the first time.
The first algorithm to learn with Python: FizzBuzz problem
I tried python on heroku for the first time
The first step to getting Blender available from Python
Why is the first argument of [Python] Class self?
Find the maximum Python
First Python 3rd Edition
The first GOLD "JDBC"
PyQ ~ Python First Steps ~
First Python image processing
Play youtube in python
the zen of Python
[Python] Python / Scikit-learn's first SVM
The first GOLD "Function"
First Python miscellaneous notes
[Python] Split the date
[Python] Chapter 01-01 About Python (First Python)
Python hand play (division)
The first API to make with python Djnago REST framework
[Python] Which is executed first, the class variable or __init__?
[Python] The first step to making a game with Pyxel
Play with the password mechanism of GitHub Webhook and Python