mirror of
https://github.com/fishyboteso/fishyboteso.git
synced 2024-08-30 18:32:13 +00:00
#185 re did the auto switching screenshot lib with the fix
This commit is contained in:
parent
773f05ebae
commit
d262885afa
@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import subprocess
|
||||
import traceback
|
||||
from abc import ABC, abstractmethod
|
||||
from functools import partial
|
||||
from typing import Optional
|
||||
@ -98,7 +99,24 @@ class D3DShot(IScreenShot):
|
||||
LIBS = [PyAutoGUI, MSS, D3DShot]
|
||||
|
||||
|
||||
def create() -> IScreenShot:
|
||||
lib = LIBS[config.get("sslib", 0)]
|
||||
logging.debug(f"Using {lib.__name__} screenshot lib")
|
||||
return lib()
|
||||
# noinspection PyBroadException
|
||||
def create() -> Optional[IScreenShot]:
|
||||
# Initialize a variable to hold the preferred library index
|
||||
preferred_lib_index = config.get("sslib", 0)
|
||||
# Create a list of library indices to try, starting with the preferred one
|
||||
lib_indices = [preferred_lib_index] + [i for i in range(len(LIBS)) if i != preferred_lib_index]
|
||||
|
||||
for index in lib_indices:
|
||||
lib = LIBS[index]
|
||||
try:
|
||||
lib_instance = lib()
|
||||
if lib_instance.setup():
|
||||
# testing grab once
|
||||
ss = lib_instance.grab()
|
||||
if ss.shape:
|
||||
logging.debug(f"Using {lib.__name__} as the screenshot library.")
|
||||
return lib_instance
|
||||
except Exception:
|
||||
logging.warning(f"Setup failed for {lib.__name__} with error: {traceback.format_exc()}. Trying next library...")
|
||||
|
||||
return None
|
||||
|
@ -42,14 +42,15 @@ def init():
|
||||
WindowServer.status = Status.CRASHED
|
||||
return
|
||||
|
||||
WindowServer.status = Status.RUNNING
|
||||
WindowServer.crop = os_services.get_game_window_rect()
|
||||
|
||||
if WindowServer.crop is None or not WindowServer.sslib.setup():
|
||||
crop = os_services.get_game_window_rect()
|
||||
if crop is None or not WindowServer.sslib.setup():
|
||||
logging.error("Game window not found by window_server")
|
||||
WindowServer.status = Status.CRASHED
|
||||
return
|
||||
|
||||
WindowServer.crop = crop
|
||||
WindowServer.status = Status.RUNNING
|
||||
|
||||
|
||||
def get_cropped_screenshot():
|
||||
ss = WindowServer.sslib.grab()
|
||||
|
@ -1 +1 @@
|
||||
0.5.25
|
||||
0.5.26
|
||||
|
Loading…
Reference in New Issue
Block a user