mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-08 12:47:32 +08:00
Upd: ALAS framework updates
This commit is contained in:
parent
437dbe6171
commit
4f761b1e6f
@ -710,7 +710,7 @@
|
||||
},
|
||||
"Campaign": {
|
||||
"Name": "D3",
|
||||
"Event": "war_archives_20211028_cn",
|
||||
"Event": "war_archives_20220414_cn",
|
||||
"Mode": "normal",
|
||||
"UseClearMode": true,
|
||||
"UseFleetLock": true,
|
||||
|
@ -21,7 +21,7 @@ class ModuleBase:
|
||||
Args:
|
||||
config (AzurLaneConfig, str):
|
||||
Name of the user config under ./config
|
||||
device (Device):
|
||||
device (Device, str):
|
||||
To reuse a device.
|
||||
If None, create a new Device object.
|
||||
If str, create a new Device object and use the given device as serial.
|
||||
|
@ -218,7 +218,7 @@ class Button(Resource):
|
||||
offset = np.array(offset)
|
||||
else:
|
||||
offset = np.array((-3, -offset, 3, offset))
|
||||
image = crop(image, offset + self.area)
|
||||
image = crop(image, offset + self.area, copy=False)
|
||||
|
||||
if self.is_gif:
|
||||
for template in self.image:
|
||||
@ -256,7 +256,7 @@ class Button(Resource):
|
||||
offset = np.array(offset)
|
||||
else:
|
||||
offset = np.array((-3, -offset, 3, offset))
|
||||
image = crop(image, offset + self.area)
|
||||
image = crop(image, offset + self.area, copy=False)
|
||||
|
||||
if self.is_gif:
|
||||
for template in self.image_binary:
|
||||
@ -304,7 +304,7 @@ class Button(Resource):
|
||||
offset = np.array(offset)
|
||||
else:
|
||||
offset = np.array((-3, -offset, 3, offset))
|
||||
image = crop(image, offset + self.area)
|
||||
image = crop(image, offset + self.area, copy=False)
|
||||
|
||||
if self.is_gif:
|
||||
image_luma = rgb2luma(image)
|
||||
|
@ -194,6 +194,7 @@ def ensure_int(*args):
|
||||
|
||||
def area_offset(area, offset):
|
||||
"""
|
||||
Move an area.
|
||||
|
||||
Args:
|
||||
area: (upper_left_x, upper_left_y, bottom_right_x, bottom_right_y).
|
||||
@ -202,11 +203,14 @@ def area_offset(area, offset):
|
||||
Returns:
|
||||
tuple: (upper_left_x, upper_left_y, bottom_right_x, bottom_right_y).
|
||||
"""
|
||||
return tuple(np.array(area) + np.append(offset, offset))
|
||||
upper_left_x, upper_left_y, bottom_right_x, bottom_right_y = area
|
||||
x, y = offset
|
||||
return upper_left_x + x, upper_left_y + y, bottom_right_x + x, bottom_right_y + y
|
||||
|
||||
|
||||
def area_pad(area, pad=10):
|
||||
"""
|
||||
Inner offset an area.
|
||||
|
||||
Args:
|
||||
area: (upper_left_x, upper_left_y, bottom_right_x, bottom_right_y).
|
||||
@ -215,7 +219,8 @@ def area_pad(area, pad=10):
|
||||
Returns:
|
||||
tuple: (upper_left_x, upper_left_y, bottom_right_x, bottom_right_y).
|
||||
"""
|
||||
return tuple(np.array(area) + np.array([pad, pad, -pad, -pad]))
|
||||
upper_left_x, upper_left_y, bottom_right_x, bottom_right_y = area
|
||||
return upper_left_x + pad, upper_left_y + pad, bottom_right_x - pad, bottom_right_y - pad
|
||||
|
||||
|
||||
def limit_in(x, lower, upper):
|
||||
@ -526,7 +531,7 @@ def save_image(image, file):
|
||||
Image.fromarray(image).save(file)
|
||||
|
||||
|
||||
def crop(image, area):
|
||||
def crop(image, area, copy=True):
|
||||
"""
|
||||
Crop image like pillow, when using opencv / numpy.
|
||||
Provides a black background if cropping outside of image.
|
||||
@ -534,6 +539,7 @@ def crop(image, area):
|
||||
Args:
|
||||
image (np.ndarray):
|
||||
area:
|
||||
copy (bool):
|
||||
|
||||
Returns:
|
||||
np.ndarray:
|
||||
@ -542,9 +548,11 @@ def crop(image, area):
|
||||
h, w = image.shape[:2]
|
||||
border = np.maximum((0 - y1, y2 - h, 0 - x1, x2 - w), 0)
|
||||
x1, y1, x2, y2 = np.maximum((x1, y1, x2, y2), 0)
|
||||
image = image[y1:y2, x1:x2].copy()
|
||||
image = image[y1:y2, x1:x2]
|
||||
if sum(border) > 0:
|
||||
image = cv2.copyMakeBorder(image, *border, borderType=cv2.BORDER_CONSTANT, value=(0, 0, 0))
|
||||
if copy:
|
||||
image = image.copy()
|
||||
return image
|
||||
|
||||
|
||||
@ -656,7 +664,7 @@ def get_color(image, area):
|
||||
Returns:
|
||||
tuple: (r, g, b)
|
||||
"""
|
||||
temp = crop(image, area)
|
||||
temp = crop(image, area, copy=False)
|
||||
color = cv2.mean(temp)
|
||||
return color[:3]
|
||||
|
||||
|
@ -86,9 +86,12 @@ class CodeGenerator:
|
||||
for _ in range(empty):
|
||||
self.Empty()
|
||||
|
||||
def Value(self, key=None, value=None, **kwargs):
|
||||
def Value(self, key=None, value=None, type_=None, **kwargs):
|
||||
if key is not None:
|
||||
self.add(f'{key} = {self._repr(value)}')
|
||||
if type_ is not None:
|
||||
self.add(f'{key}: {type_} = {self._repr(value)}')
|
||||
else:
|
||||
self.add(f'{key} = {self._repr(value)}')
|
||||
for key, value in kwargs.items():
|
||||
self.Value(key, value)
|
||||
|
||||
@ -131,7 +134,7 @@ class CodeGenerator:
|
||||
if key is not None:
|
||||
return TabWrapper(self, prefix=f'{key} = {object_class}(', suffix=')')
|
||||
else:
|
||||
return TabWrapper(self, prefix='(', suffix=')', newline=False)
|
||||
return TabWrapper(self, prefix=f'{object_class}(', suffix=')', newline=False)
|
||||
|
||||
def ObjectAttr(self, key=None, value=None):
|
||||
if isinstance(value, TabWrapper):
|
||||
@ -147,6 +150,15 @@ class CodeGenerator:
|
||||
else:
|
||||
self.add(f'{key}={self._repr(value)},')
|
||||
|
||||
def Class(self, name, inherit=None):
|
||||
if inherit is not None:
|
||||
return TabWrapper(self, prefix=f'class {name}({inherit}):')
|
||||
else:
|
||||
return TabWrapper(self, prefix=f'class {name}:')
|
||||
|
||||
def Def(self, name, args=''):
|
||||
return TabWrapper(self, prefix=f'def {name}({args}):')
|
||||
|
||||
|
||||
generator = CodeGenerator()
|
||||
Import = generator.Import
|
||||
|
@ -33,6 +33,8 @@ class ManualConfig:
|
||||
module.assets
|
||||
"""
|
||||
ASSETS_FOLDER = './assets'
|
||||
ASSETS_MODULE = './module'
|
||||
ASSETS_RESOLUTION = (1280, 720)
|
||||
|
||||
"""
|
||||
module.base
|
||||
|
@ -176,9 +176,9 @@ class SelectedGrids:
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if self:
|
||||
try:
|
||||
return self.grids[0]
|
||||
else:
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
def add(self, grids):
|
||||
|
@ -17,14 +17,11 @@ from module.map.assets import (FLEET_PREPARATION, MAP_PREPARATION,
|
||||
MAP_PREPARATION_CANCEL, WITHDRAW)
|
||||
from module.meowfficer.assets import MEOWFFICER_BUY
|
||||
from module.ocr.ocr import Ocr
|
||||
from module.os_handler.assets import (AUTO_SEARCH_REWARD, EXCHANGE_CHECK,
|
||||
RESET_FLEET_PREPARATION, RESET_TICKET_POPUP)
|
||||
from module.os_handler.assets import (AUTO_SEARCH_REWARD, EXCHANGE_CHECK, RESET_FLEET_PREPARATION, RESET_TICKET_POPUP)
|
||||
from module.raid.assets import RAID_FLEET_PREPARATION
|
||||
from module.ui.assets import (BACK_ARROW, DORM_FEED_CANCEL, DORM_INFO,
|
||||
DORM_TROPHY_CONFIRM, EVENT_LIST_CHECK, GOTO_MAIN,
|
||||
MAIN_GOTO_CAMPAIGN, MEOWFFICER_INFO, MEOWFFICER_GOTO_DORMMENU,
|
||||
META_CHECK, PLAYER_CHECK, RAID_CHECK,
|
||||
SHIPYARD_CHECK, SHOP_GOTO_SUPPLY_PACK)
|
||||
from module.ui.assets import (BACK_ARROW, DORM_FEED_CANCEL, DORM_INFO, DORM_TROPHY_CONFIRM, EVENT_LIST_CHECK, GOTO_MAIN,
|
||||
MAIN_GOTO_CAMPAIGN, MEOWFFICER_GOTO_DORMMENU, MEOWFFICER_INFO, META_CHECK, PLAYER_CHECK,
|
||||
RAID_CHECK, SHIPYARD_CHECK, SHOP_GOTO_SUPPLY_PACK)
|
||||
from module.ui.page import (Page, page_academy, page_archives,
|
||||
page_battle_pass, page_build, page_campaign,
|
||||
page_campaign_menu, page_commission, page_daily,
|
||||
|
Loading…
Reference in New Issue
Block a user