mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-16 06:25:24 +00:00
Add: [ALAS] Save tracking screenshots
This commit is contained in:
parent
7d09a4c5cf
commit
d5ab439de2
@ -65,6 +65,7 @@ class AzurLaneAutoScript:
|
||||
def run(self, command):
|
||||
try:
|
||||
self.device.screenshot()
|
||||
self.device.screenshot_tracking.clear()
|
||||
self.__getattribute__(command)()
|
||||
return True
|
||||
except TaskEnd:
|
||||
@ -139,15 +140,19 @@ class AzurLaneAutoScript:
|
||||
from module.base.utils import save_image
|
||||
from module.handler.sensitive_info import (handle_sensitive_image, handle_sensitive_logs)
|
||||
if self.config.Error_SaveError:
|
||||
if not os.path.exists('./log/error'):
|
||||
os.mkdir('./log/error')
|
||||
folder = f'./log/error/{int(time.time() * 1000)}'
|
||||
logger.warning(f'Saving error: {folder}')
|
||||
os.mkdir(folder)
|
||||
os.makedirs(folder, exist_ok=True)
|
||||
for data in self.device.screenshot_deque:
|
||||
image_time = datetime.strftime(data['time'], '%Y-%m-%d_%H-%M-%S-%f')
|
||||
image = handle_sensitive_image(data['image'])
|
||||
save_image(image, f'{folder}/{image_time}.png')
|
||||
if self.device.screenshot_tracking:
|
||||
os.makedirs(f'{folder}/tracking', exist_ok=True)
|
||||
for data in self.device.screenshot_tracking:
|
||||
image_time = datetime.strftime(data['time'], '%Y-%m-%d_%H-%M-%S-%f')
|
||||
with open(f'{folder}/tracking/{image_time}.png', 'wb') as f:
|
||||
f.write(data['image'].getvalue())
|
||||
with open(logger.log_file, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
start = 0
|
||||
|
@ -1,3 +1,5 @@
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
import module.config.server as server_
|
||||
from module.base.button import Button, ButtonWrapper, ClickButton, match_template
|
||||
from module.base.timer import Timer
|
||||
@ -5,6 +7,7 @@ from module.base.utils import *
|
||||
from module.config.config import AzurLaneConfig
|
||||
from module.device.device import Device
|
||||
from module.logger import logger
|
||||
from module.webui.setting import cached_class_property
|
||||
|
||||
|
||||
class ModuleBase:
|
||||
@ -45,6 +48,15 @@ class ModuleBase:
|
||||
|
||||
self.interval_timer = {}
|
||||
|
||||
@cached_class_property
|
||||
def worker(self) -> ThreadPoolExecutor:
|
||||
"""
|
||||
A thread pool to run things at background
|
||||
"""
|
||||
logger.hr('Creating worker')
|
||||
pool = ThreadPoolExecutor(1)
|
||||
return pool
|
||||
|
||||
def match_template(self, button, interval=0, similarity=0.85):
|
||||
"""
|
||||
Args:
|
||||
@ -281,3 +293,28 @@ class ModuleBase:
|
||||
"""
|
||||
server_.set_lang(lang)
|
||||
logger.attr('Lang', self.config.LANG)
|
||||
|
||||
def screenshot_tracking_add(self):
|
||||
"""
|
||||
Add a tracking image, image will be saved
|
||||
"""
|
||||
logger.info('screenshot_tracking_add')
|
||||
data = self.device.screenshot_deque[-1]
|
||||
image = data['image']
|
||||
now = data['time']
|
||||
|
||||
def image_encode(im, ti):
|
||||
import io
|
||||
from module.handler.sensitive_info import handle_sensitive_image
|
||||
|
||||
output = io.BytesIO()
|
||||
im = handle_sensitive_image(im)
|
||||
Image.fromarray(im, mode='RGB').save(output, format='png')
|
||||
output.seek(0)
|
||||
|
||||
self.device.screenshot_tracking.append({
|
||||
'time': ti,
|
||||
'image': output
|
||||
})
|
||||
|
||||
ModuleBase.worker.submit(image_encode, image, now)
|
||||
|
@ -100,6 +100,10 @@ class Screenshot(Adb, WSA, DroidCast, AScreenCap, Scrcpy):
|
||||
def screenshot_deque(self):
|
||||
return deque(maxlen=int(self.config.Error_ScreenshotLength))
|
||||
|
||||
@cached_property
|
||||
def screenshot_tracking(self):
|
||||
return []
|
||||
|
||||
def save_screenshot(self, genre='items', interval=None, to_base_folder=False):
|
||||
"""Save a screenshot. Use millisecond timestamp as file name.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user