Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

养成出现选项时,在终端选择时出错 #85

Closed
WisdomDevils opened this issue Jun 30, 2021 · 19 comments
Closed

养成出现选项时,在终端选择时出错 #85

WisdomDevils opened this issue Jun 30, 2021 · 19 comments
Labels
question Further information is requested

Comments

@WisdomDevils
Copy link

Choose event option(1/2/3/4/5):3
ERROR [12:55:28]:main:119: unexpected exception
Traceback (most recent call last):
File "C:\Users\WisdomDevil\Desktop\auto-derby-master\auto_derby_main_.py", line 115, in
main()
File "C:\Users\WisdomDevil\Desktop\auto-derby-master\auto_derby_main_.py", line 87, in main
job()
File "C:\Users\WisdomDevil\Desktop\auto-derby-master\auto_derby\jobs\nurturing.py", line 326, in nurturing
_handle_option()
File "C:\Users\WisdomDevil\Desktop\auto-derby-master\auto_derby\jobs\nurturing.py", line 241, in _handle_option
ans = choice.get(template.screenshot())
File "C:\Users\WisdomDevil\Desktop\auto-derby-master\auto_derby\single_mode\choice.py", line 80, in get
g.choices[event_id] = int(ans)
TypeError: list indices must be integers or slices, not str

以上为错误信息

@NateScarlet
Copy link
Owner

你的single_mode_choices.json 格式不对

@WisdomDevils
Copy link
Author

是文件格式的问题吗

@WisdomDevils
Copy link
Author

没有找到匹配的项

@NateScarlet
Copy link
Owner

NateScarlet commented Jun 30, 2021

https://github.com/NateScarlet/auto-derby#%E9%97%AE%E9%A2%98%E5%8F%8D%E9%A6%88

在 launcher.log 里面找你的数据路径 然后把 single_mode_choices.json 发上来

GitHub
🐎🖥《赛马娘》(ウマ娘: Pretty Derby)辅助脚本 . Contribute to NateScarlet/auto-derby development by creating an account on GitHub.

@WisdomDevils
Copy link
Author

WisdomDevils commented Jun 30, 2021

# -*- coding=UTF-8 -*- # pyright: strict

import json
import logging
from typing import Dict, Text

import cv2
import numpy as np
from auto_derby import imagetools, window
from PIL.Image import Image
import os
from .. import mathtools

LOGGER = logging.getLogger(name)

class g:
event_image_path: str = ""
data_path: str = ""
choices: Dict[Text, int] = {}

def reload() -> None:
try:
with open(g.data_path, "r", encoding="utf-8") as f:
g.choices = json.load(f)
except OSError:
pass

def _save() -> None:
with open(g.data_path, "w", encoding="utf-8") as f:
json.dump(g.choices, f, indent=2)

def get(event_screen: Image) -> int:
rp = mathtools.ResizeProxy(event_screen.width)
b_img = np.zeros((event_screen.height, event_screen.width))
event_name_bbox = rp.vector4((75, 155, 305, 180), 466)
options_bbox = rp.vector4((50, 200, 400, 570), 466)
cv_event_name_img = np.asarray(event_screen.crop(event_name_bbox).convert("L"))
_, cv_event_name_img = cv2.threshold(cv_event_name_img, 220, 255, cv2.THRESH_TOZERO)

l, t, r, b = event_name_bbox
b_img[t:b, l:r] = cv_event_name_img

cv_options_img = np.asarray(event_screen.crop(options_bbox).convert("L"))

option_rows = (cv2.reduce(cv_options_img, 1, cv2.REDUCE_MAX) == 255).astype(
    np.uint8
)

option_mask = np.repeat(option_rows, cv_options_img.shape[1], axis=1)

cv_options_img = 255 - cv_options_img
cv_options_img *= option_mask

_, cv_options_img = cv2.threshold(cv_options_img, 128, 255, cv2.THRESH_BINARY)

l, t, r, b = options_bbox
b_img[t:b, l:r] = cv_options_img

event_id = imagetools.md5(b_img, save_path=g.event_image_path)

if os.getenv("DEBUG") == __name__:
    cv2.imshow("option_mask", option_mask)
    cv2.imshow("cv_event_name_img", cv_event_name_img)
    cv2.imshow("cv_options_img", cv_options_img)
    cv2.imshow("b_img", b_img)
    cv2.waitKey()
    cv2.destroyAllWindows()

if event_id not in g.choices:
    close = window.info("New event encountered\nplease choose option in terminal")
    try:
        while True:
            ans = input("Choose event option(1/2/3/4/5):")
            if ans in ["1", "2", "3", "4", "5"]:
                g.choices[event_id] = int(ans)
                _save()
                break
    finally:
        close()
ret = g.choices[event_id]
LOGGER.info("event: id=%s choice=%d", event_id, ret)
return ret

@NateScarlet
Copy link
Owner

你确定你的.json 是个python 脚本?

@NateScarlet
Copy link
Owner

launcher.log 发一下

@WisdomDevils
Copy link
Author


Windows PowerShell 脚本开始
开始时间: 20210630130404
用户名: LAPTOP-BABJAENJ\WisdomDevil
RunAs 用户: LAPTOP-BABJAENJ\WisdomDevil
配置名称:
计算机: LAPTOP-BABJAENJ (Microsoft Windows NT 10.0.19042.0)
主机应用程序: PowerShell -Version 3 -NoProfile -ExecutionPolicy Bypass C:\Users\WisdomDevil\Desktop\auto-derby-master\auto_derby\launcher\launcher.ps1
进程 ID: 9768
PSVersion: 5.1.19041.1023
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.19041.1023
BuildVersion: 10.0.19041.1023
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1


已启动脚本,输出文件为 C:\Users\WisdomDevil\Desktop\auto-derby-master\launcher.log

Job : nurturing
Debug : False
PythonExecutablePath : D:\Program Files (x86)\Python\Python38\python.exe
SingleModeChoicesDataPath : C:\Users\WisdomDevil\Desktop\auto-derby-master\single_mode_races.json
PauseIfRaceOrderGt : 5
Plugins :
TargetTrainingLevels : 5,3,3,0,
ADBAddress :
Version : 2021-06-30 13:04
Python Version : Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)]

command:
title auto-derby: 2021-06-30 13:04
cd /d "C:\Users\WisdomDevil\Desktop\auto-derby-master"
set "DEBUG="
set "AUTO_DERBY_LAST_SCREENSHOT_SAVE_PATH="
set "AUTO_DERBY_OCR_IMAGE_PATH="
set "AUTO_DERBY_SINGLE_MODE_EVENT_IMAGE_PATH="
set "AUTO_DERBY_SINGLE_MODE_CHOICE_PATH=C:\Users\WisdomDevil\Desktop\auto-derby-master\single_mode_races.json"
set "AUTO_DERBY_PAUSE_IF_RACE_ORDER_GT=5"
set "AUTO_DERBY_PLUGINS="
set "AUTO_DERBY_SINGLE_MODE_TARGET_TRAINING_LEVELS=5,3,3,0,"
set "AUTO_DERBY_ADB_ADDRESS="
"D:\Program Files (x86)\Python\Python38\python.exe" -m auto_derby nurturing
exit


Windows PowerShell 脚本结束
结束时间: 20210630130409


@WisdomDevils
Copy link
Author

json格式的只找到了single_mode_races

@NateScarlet
Copy link
Owner

因为 single_mode_choices 是自动创建的 你把single_mode_races 还原 然后指定一个别的路径或者用默认路径

@WisdomDevils
Copy link
Author

在哪里指定呢?

@NateScarlet
Copy link
Owner

启动器上面不是有选择 python 下面那个

@NateScarlet
Copy link
Owner

这个明显是你手动改了 默认设置就是好的 然后你现在问我在哪改……

@WisdomDevils
Copy link
Author

抱歉......我还原一下

@NateScarlet NateScarlet changed the title [DEV]养成出现选项时,在终端选择时出错 养成出现选项时,在终端选择时出错 Jun 30, 2021
@NateScarlet NateScarlet added the question Further information is requested label Jun 30, 2021
@WisdomDevils
Copy link
Author

还原了还是不行

@WisdomDevils
Copy link
Author

single mode choices的默认路径就是C:\Users\WisdomDevil\Desktop\auto-derby-master\single_mode_races.json

@NateScarlet
Copy link
Owner

默认路径是你把它清空之后的路径 启动器会记住你的设置

@NateScarlet
Copy link
Owner

你手动打字改成 single_mode_choices.json 也行

@WisdomDevils
Copy link
Author

可以了!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants