Skip to content

Commit

Permalink
fix : explore normal task data parser and make test
Browse files Browse the repository at this point in the history
  • Loading branch information
pur1fying committed Nov 23, 2024
1 parent 45b57b4 commit 0374fab
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 70 deletions.
6 changes: 4 additions & 2 deletions core/Baas_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@

class Baas_thread:
def __init__(self, config, logger_signal=None, button_signal=None, update_signal=None, exit_signal=None):
self.project_dir = os.path.abspath(os.path.dirname(__file__))
self.project_dir = os.path.dirname(self.project_dir)
self.u2_client = None
self.u2 = None
self.dailyGameActivity = None
Expand All @@ -87,7 +89,7 @@ def __init__(self, config, logger_signal=None, button_signal=None, update_signal
self.ratio = None
self.next_time = None
self.task_finish_to_main_page = False
self.static_config = None
self.static_config = self.config_set.static_config
self.ocr = None
self.logger = Logger(logger_signal)
self.last_refresh_u2_time = 0
Expand Down Expand Up @@ -532,7 +534,7 @@ def init_image_resource(self):

def init_rgb(self):
try:
temp = 'src/rgb_feature/rgb_feature_' + self.server + '.json'
temp = self.project_dir + '/src/rgb_feature/rgb_feature_' + self.server + '.json'
self.rgb_feature = json.load(open(temp, 'r', encoding='utf-8'))['rgb_feature']
return True
except Exception as e:
Expand Down
6 changes: 4 additions & 2 deletions core/default_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,14 @@
"push_json":"",
"push_serverchan":"",
"cafe_reward_lowest_affection_first": true,
"cafe_reward_invite1_criterion" : "name",
"cafe_reward_invite1_criterion" : "starred",
"favorStudent1": [
"爱丽丝"
],
"cafe_reward_invite1_starred_student_position" : 1,
"cafe_reward_has_no2_cafe": false,
"cafe_reward_collect_hour_reward": true,
"cafe_reward_invite2_criterion" : "name",
"cafe_reward_invite2_criterion" : "starred",
"favorStudent2": [
"爱丽丝(女仆)"
],
Expand Down Expand Up @@ -533,6 +533,8 @@
'''
STATIC_DEFAULT_CONFIG = '''
{
"explore_normal_task_region_range": [4, 27],
"explore_hard_task_region_range": [1, 27],
"screenshot_methods" : ["adb", "nemu", "uiautomator2"],
"control_methods" : ["adb", "nemu", "uiautomator2"],
"common_shop_price_list": {
Expand Down
4 changes: 3 additions & 1 deletion core/picture.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import time
from core import color, image
from module.main_story import change_acc_auto

from core.exception import RequestHumanTakeOver

def co_detect(self, rgb_ends=None, rgb_possibles=None, img_ends=None, img_possibles=None, skip_first_screenshot=False,
tentitive_click=False, tentitivex=1238, tentitivey=45, max_fail_cnt=10, rgb_pop_ups=None,
Expand Down Expand Up @@ -103,6 +103,8 @@ def co_detect(self, rgb_ends=None, rgb_possibles=None, img_ends=None, img_possib
self.click(tentitivex, tentitivey)
time.sleep(self.screenshot_interval)
fail_cnt = 0
if not self.flag_run:
raise RequestHumanTakeOver


def deal_with_pop_ups(self, rgb_pop_ups, img_pop_ups):
Expand Down
2 changes: 1 addition & 1 deletion core/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, update_signal, path):
super().__init__()
self.event_map = {}
self.first_waiting = None
self.event_config_path = "./config/" + path + "/event.json"
self.event_config_path = path + "/event.json"
self.update_signal = update_signal
self._event_config = []
self._current_task = None
Expand Down
12 changes: 12 additions & 0 deletions develop_tools/config/gui.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"MainWindow": {
"configLoadType": "Card",
"DpiScale": 1,
"Language": "zh_CN",
"MicaEnabled": true
},
"QFluentWidgets": {
"ThemeColor": "#ff0078d4",
"ThemeMode": "Light"
}
}
47 changes: 47 additions & 0 deletions develop_tools/test_explore_task_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from module.explore_normal_task import get_explore_normal_task_missions
from module.explore_hard_task import get_explore_hard_task_data
from core.utils import Logger
from core.Baas_thread import Baas_thread
from gui.util.config_set import ConfigSet
from main import Main

t = Main(ocr_needed=[])
config = ConfigSet(config_dir="D:\\github\\bass\\blue_archive_auto_script\\config\\1708148000")
tt = Baas_thread(config, None, None, None)
tt.init_all_data()

st = [
1,
4,
26,
99,
"6,7",
"1,2,3",
"18,19,20",
"18,19,20",
[18, 19, 20],
"5,19,21",
[4, 23, -1],
"5,16,q9,",
[5, 16, "q9"]
]
expected_1 = [
[],
[[4, 1], [4, 2], [4, 3], [4, 4], [4, 5]],
[[26, 1], [26, 2], [26, 3], [26, 4], [26, 5]],
[],
[[6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5]],
[],
[[18, 1], [18, 2], [18, 3], [18, 4], [18, 5], [19, 1], [19, 2], [19, 3], [19, 4], [19, 5], [20, 1], [20, 2], [20, 3], [20, 4], [20, 5]],
[[18, 1], [18, 2], [18, 3], [18, 4], [18, 5], [19, 1], [19, 2], [19, 3], [19, 4], [19, 5], [20, 1], [20, 2], [20, 3], [20, 4], [20, 5]],
[[18, 1], [18, 2], [18, 3], [18, 4], [18, 5], [19, 1], [19, 2], [19, 3], [19, 4], [19, 5], [20, 1], [20, 2], [20, 3], [20, 4], [20, 5]],
[[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [19, 1], [19, 2], [19, 3], [19, 4], [19, 5], [21, 1], [21, 2], [21, 3], [21, 4], [21, 5]],
[[4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [23, 1], [23, 2], [23, 3], [23, 4], [23, 5]],
[[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [16, 1], [16, 2], [16, 3], [16, 4], [16, 5]],
[[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [16, 1], [16, 2], [16, 3], [16, 4], [16, 5]]
]

for i in range(len(st)):
ret = get_explore_normal_task_missions(tt, st[i], True)
print(ret)
assert ret == expected_1[i]
4 changes: 2 additions & 2 deletions gui/components/expand/featureSwitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ def _init_components(self, config_list):
self.config_buttons.append(cfbs_wrapper)

def _read_config(self):
with open('./config/' + self.config.config_dir + '/event.json', 'r', encoding='utf-8') as f:
with open(self.config.config_dir + '/event.json', 'r', encoding='utf-8') as f:
s = f.read()
if s == '':
return
self._event_config = json.loads(s)

def _save_config(self):
with open('./config/' + self.config.config_dir + '/event.json', 'w', encoding='utf-8') as f:
with open(self.config.config_dir + '/event.json', 'w', encoding='utf-8') as f:
json.dump(self._event_config, f, ensure_ascii=False, indent=2)

def _sort(self):
Expand Down
2 changes: 1 addition & 1 deletion gui/fragments/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def resizeEvent(self, event):
def call_update(self, data=None, parent=None):
try:
if self.event_map == {}:
with open('./config/' + self.config.config_dir + '/event.json', 'r', encoding='utf-8') as f:
with open(self.config.config_dir + '/event.json', 'r', encoding='utf-8') as f:
event_config = json.load(f)
for item in event_config:
self.event_map[item['func_name']] = item['event_name']
Expand Down
6 changes: 3 additions & 3 deletions gui/fragments/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ def _create_card(self, name: str, tip: str, setting_name: str) -> Union[

def _commit_change(self):
with lock:
with open('./config/' + self.config.config_dir + '/event.json', 'w', encoding='utf-8') as f:
with open(self.config.config_dir + '/event.json', 'w', encoding='utf-8') as f:
json.dump(self._event_config, f, ensure_ascii=False, indent=2) # 将_event_config列表写入配置文件

def _read_config(self):
with lock:
with open('./config/' + self.config.config_dir + '/event.json', 'r', encoding='utf-8') as f:
with open(self.config.config_dir + '/event.json', 'r', encoding='utf-8') as f:
self._event_config = json.load(f) # 从配置文件中读取数据并更新_event_config列表
with open('./config/' + self.config.config_dir + '/switch.json', 'r', encoding='utf-8') as f:
with open(self.config.config_dir + '/switch.json', 'r', encoding='utf-8') as f:
self._switch_config = json.load(f) # 从配置文件中读取数据并更新_switch_config列表

def update_settings(self):
Expand Down
22 changes: 15 additions & 7 deletions gui/util/config_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from qfluentwidgets import qconfig

from gui.util.translator import baasTranslator as bt

import os

class BoundComponent(QObject):
"""
Expand Down Expand Up @@ -54,7 +54,6 @@ def config_updated(self, key):
class ConfigSet:
def __init__(self, config_dir):
super().__init__()
print(config_dir)
self.config = None
self.gui_config = None
self.server_mode = 'CN'
Expand All @@ -63,14 +62,23 @@ def __init__(self, config_dir):
self.window = None
self.main_thread = None
self.static_config = None
self.config_dir = config_dir
self.config_dir = None
self.static_config_path = None
if os.path.exists(f'config/{config_dir}/config.json'): # relative path
self.config_dir = os.path.abspath(f'config/{config_dir}')
self.static_config_path = os.path.dirname(self.config_dir) + '/static.json'
elif os.path.exists(f'{config_dir}/config.json'): # absolute path
self.config_dir = config_dir
self.static_config_path = os.path.abspath(os.path.dirname(config_dir) + '/static.json')
else:
raise FileNotFoundError(f'config/{config_dir}/config.json not found')
self.signals = {}
self._init_config()

def _init_config(self):
with open(f'./config/{self.config_dir}/config.json', 'r', encoding='utf-8') as f:
with open(self.config_dir + "\\config.json", 'r', encoding='utf-8') as f:
self.config = json.load(f)
with open("config/static.json", 'r', encoding='utf-8') as f:
with open(self.static_config_path, 'r', encoding='utf-8') as f:
self.static_config = json.load(f)
if self.config['server'] == '国服' or self.config['server'] == 'B服':
self.server_mode = 'CN'
Expand All @@ -92,7 +100,7 @@ def set(self, key, value):
self._init_config()
value = bt.undo(value)
self.config[key] = value
with open(f'./config/{self.config_dir}/config.json', 'w', encoding='utf-8') as f:
with open(self.config_dir + "\\config.json", 'w', encoding='utf-8') as f:
json.dump(self.config, f, indent=4, ensure_ascii=False)
self.dynamic_update(key)

Expand All @@ -108,7 +116,7 @@ def __getitem__(self, item: str):
return self.config[item]

def check(self, key, value):
with open(f'./config/{self.config_dir}/config.json', 'r', encoding='utf-8') as f:
with open(self.config_dir + "\\config.json", 'r', encoding='utf-8') as f:
new_config = json.load(f)
return new_config.get(key) == value

Expand Down
12 changes: 7 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import json
import os
from core.utils import Logger
from core.ocr import ocr
from gui.util.config_set import ConfigSet
from core.Baas_thread import Baas_thread


class Main:
def __init__(self, logger_signal=None, ocr_needed=None):
self.ocr_needed = ocr_needed
self.ocr = None
self.static_config = None
self.logger = Logger(logger_signal)
self.project_dir = os.path.abspath(os.path.dirname(__file__))
self.logger.info(self.project_dir)
self.init_all_data()
self.threads = {}

Expand All @@ -30,7 +34,6 @@ def init_ocr(self):
def get_thread(self, config, name="1", logger_signal=None, button_signal=None, update_signal=None,
exit_signal=None):
t = Baas_thread(config, logger_signal, button_signal, update_signal, exit_signal)
t.static_config = self.static_config
t.ocr = self.ocr
self.threads.setdefault(name, t)
return t
Expand All @@ -45,7 +48,7 @@ def stop_script(self, name):

def init_static_config(self):
try:
self.static_config = self.operate_dict(json.load(open('config/static.json', 'r', encoding='utf-8')))
self.static_config = self.operate_dict(json.load(open(self.project_dir + "/config/static.json", 'r', encoding='utf-8')))
return True
except Exception as e:
self.logger.error("Static Config initialization failed")
Expand Down Expand Up @@ -95,7 +98,6 @@ def operate_item(self, item):

if __name__ == '__main__':
t = Main(ocr_needed=["NUM", "CN", "Global"])
t.init_static_config()
config = ConfigSet(config_dir="1708148000")
tt = Baas_thread(config, None, None, None)
tt.static_config = t.static_config
Expand All @@ -112,7 +114,7 @@ def operate_item(self, item):
# tt.solve("total_assault")
# tt.solve("cafe_reward")
# tt.solve("momo_talk")
# tt.solve("explore_normal_task")
tt.solve("explore_normal_task")
# tt.solve("explore_hard_task")
# tt.solve("normal_task")
# tt.solve("hard_task")
Expand All @@ -130,4 +132,4 @@ def operate_item(self, item):
# tt.solve("create")
# tt.solve("dailyGameActivity")
# tt.solve("friend")
tt.solve("joint_firing_drill")
# tt.solve("joint_firing_drill")
Loading

0 comments on commit 0374fab

Please sign in to comment.