mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-22 00:35:34 +00:00
Fix: InventoryManager.set() was using outdated items
This commit is contained in:
parent
7e14bde267
commit
f4afb86d0e
@ -4,10 +4,9 @@ from scipy import signal
|
||||
|
||||
from module.base.base import ModuleBase
|
||||
from module.base.button import ButtonWrapper
|
||||
from module.base.decorator import cached_property, del_cached_property
|
||||
from module.base.decorator import cached_property
|
||||
from module.base.timer import Timer
|
||||
from module.base.utils import Lines, area_center, area_offset, color_similarity_2d
|
||||
from module.exception import ScriptError
|
||||
from module.logger import logger
|
||||
|
||||
|
||||
@ -71,6 +70,8 @@ class InventoryManager:
|
||||
ERROR_LINES_TOLERANCE = (-10, 10)
|
||||
COINCIDENT_POINT_ENCOURAGE_DISTANCE = 1.
|
||||
|
||||
MAXIMUM_ITEMS = 30
|
||||
|
||||
def __init__(self, main: ModuleBase, inventory: ButtonWrapper):
|
||||
"""
|
||||
max_count: expected max count of this inventory page
|
||||
@ -248,7 +249,10 @@ class InventoryManager:
|
||||
else:
|
||||
self.selected = selected[0]
|
||||
|
||||
logger.info(f'Inventory: {len(self.items)} items, selected {self.selected}')
|
||||
count = len(self.items)
|
||||
logger.info(f'Inventory: {count} items, selected {self.selected}')
|
||||
if count > self.MAXIMUM_ITEMS:
|
||||
logger.warning('Too many inventory items detected')
|
||||
|
||||
def get_row_first(self, row=1, first=0) -> InventoryItem | None:
|
||||
"""
|
||||
@ -292,12 +296,9 @@ class InventoryManager:
|
||||
def select(self, item, skip_first_screenshot=True):
|
||||
logger.info(f'Inventory select {item}')
|
||||
if isinstance(item, InventoryItem):
|
||||
pass
|
||||
loca = item.loca
|
||||
else:
|
||||
try:
|
||||
item = self.items[item]
|
||||
except KeyError:
|
||||
raise ScriptError(f'Inventory select {item} but is not in current items')
|
||||
loca = item
|
||||
|
||||
interval = Timer(2, count=6)
|
||||
while 1:
|
||||
@ -306,8 +307,16 @@ class InventoryManager:
|
||||
else:
|
||||
self.main.device.screenshot()
|
||||
|
||||
self.update()
|
||||
if len(self.items) > self.MAXIMUM_ITEMS:
|
||||
continue
|
||||
try:
|
||||
item = self.items[loca]
|
||||
except KeyError:
|
||||
logger.warning(f'Item {loca} is not in inventory, cannot select')
|
||||
continue
|
||||
|
||||
# End
|
||||
del_cached_property(item, 'is_selected')
|
||||
if item.is_selected:
|
||||
logger.info('Inventory item selected')
|
||||
break
|
||||
@ -315,8 +324,7 @@ class InventoryManager:
|
||||
if interval.reached():
|
||||
self.main.device.click(item)
|
||||
interval.reset()
|
||||
|
||||
self.update()
|
||||
continue
|
||||
|
||||
def wait_selected(self, skip_first_screenshot=True):
|
||||
"""
|
||||
@ -334,8 +342,10 @@ class InventoryManager:
|
||||
self.main.device.screenshot()
|
||||
|
||||
self.update()
|
||||
if self.selected is not None:
|
||||
return True
|
||||
if timeout.reached():
|
||||
logger.warning('Wait inventory selected timeout')
|
||||
return False
|
||||
if len(self.items) > self.MAXIMUM_ITEMS:
|
||||
continue
|
||||
if self.selected is not None:
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user