自动地图追踪录制 (#1102)
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
4
repo/js/AutoTranscribePathing/assets/process.json
Normal file
4
repo/js/AutoTranscribePathing/assets/process.json
Normal file
@@ -0,0 +1,4 @@
|
||||
-1.json
|
||||
F
|
||||
-2.json
|
||||
F
|
||||
159
repo/js/AutoTranscribePathing/main.js
Normal file
159
repo/js/AutoTranscribePathing/main.js
Normal file
@@ -0,0 +1,159 @@
|
||||
// 定义识别对象
|
||||
const paimonMenuRo = RecognitionObject.TemplateMatch(
|
||||
file.ReadImageMatSync("assets/RecognitionObject/paimon_menu.png"),
|
||||
0,
|
||||
0,
|
||||
genshin.width / 3.0,
|
||||
genshin.width / 5.0
|
||||
);
|
||||
|
||||
// 判断是否在主界面的函数
|
||||
const isInMainUI = () => {
|
||||
let captureRegion = captureGameRegion();
|
||||
let res = captureRegion.Find(paimonMenuRo);
|
||||
return !res.isEmpty();
|
||||
};
|
||||
|
||||
|
||||
// 获取设置
|
||||
/*const settings = {
|
||||
questName: "默认委托",
|
||||
questLocation: "默认地点",
|
||||
trackNumber: "1"
|
||||
//runMode: "录制模式",
|
||||
};*/
|
||||
const questName = settings.questName
|
||||
const questLocation = settings.questLocation
|
||||
const trackNumber = settings.trackNumber
|
||||
const runMode = settings.runMode
|
||||
|
||||
|
||||
// 初始化追踪数据
|
||||
let trackData = {
|
||||
"info": {
|
||||
"name": `${settings.questName}-${settings.trackNumber}`,
|
||||
"type": "collect",
|
||||
"author": settings.author,
|
||||
"version": settings.version,
|
||||
"description": settings.description,
|
||||
"map_name": "Teyvat",
|
||||
"bgi_version": "0.45.0"
|
||||
},
|
||||
"positions": []
|
||||
};
|
||||
|
||||
// 检查是否需要创建新文件夹
|
||||
function checkOrCreateFolder() {
|
||||
const folderName = `assets/${settings.questLocation}-${settings.questName}`;
|
||||
/*if (!file.existsSync(folderName)) {
|
||||
file.writeTextSync(folderName, { recursive: true });
|
||||
log.info(`创建文件夹: ${folderName}`);
|
||||
}*/
|
||||
}
|
||||
|
||||
// 保存追踪数据
|
||||
async function saveTrackData() {
|
||||
const filePath = `assets/${settings.questLocation}-${settings.questName}/${settings.questName}-${settings.trackNumber}.json`;
|
||||
//const fileName = `${settings.questName}-${settings.trackNumber}.json`;
|
||||
|
||||
try {
|
||||
await file.writeTextSync(filePath, JSON.stringify(trackData, null, 2));
|
||||
log.info(`追踪数据已保存到: ${filePath}`);
|
||||
} catch (error) {
|
||||
log.error(`保存追踪数据失败: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取当前位置并添加到追踪数据
|
||||
async function recordPosition() {
|
||||
if (isInMainUI()) {
|
||||
try {
|
||||
const position = genshin.getPositionFromMap();
|
||||
log.info(`从小地图获取坐标: X=${position.X}, Y=${position.Y}`);
|
||||
trackData.positions.push({
|
||||
"id": trackData.positions.length + 1,
|
||||
"x": position.X,
|
||||
"y": position.Y,
|
||||
"action": "",
|
||||
"move_mode": "dash",
|
||||
"action_params": "",
|
||||
"type": "path"
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
log.error(`获取坐标失败: ${error.message}`);
|
||||
await sleep(500);
|
||||
return await recordPosition();;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
await genshin.setBigMapZoomLevel(1.0);
|
||||
const position = genshin.getPositionFromBigMap();
|
||||
log.info(`从大地图获取坐标: X=${position.X}, Y=${position.Y}`);
|
||||
trackData.positions.push({
|
||||
"id": trackData.positions.length + 1,
|
||||
"x": position.X,
|
||||
"y": position.Y,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"action_params": "",
|
||||
"type": "target"
|
||||
});
|
||||
log.info("已在大地图界面,已生成地图追踪,脚本结束");
|
||||
await saveTrackData();
|
||||
return false;
|
||||
}
|
||||
catch (error) {
|
||||
log.error(`获取坐标失败: ${error.message}`);
|
||||
await sleep(500);
|
||||
return await recordPosition();;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 主逻辑
|
||||
async function main() {
|
||||
log.info("委托地图追踪录制开始");
|
||||
|
||||
checkOrCreateFolder();
|
||||
|
||||
if (settings.runMode === "运行模式") {
|
||||
const filePath = `assets/${settings.questLocation}-${settings.questName}/${settings.questName}-${settings.trackNumber}.json`;
|
||||
log.info(`正在运行地图追踪任务文件: ${filePath}`);
|
||||
await pathingScript.runFile(filePath);
|
||||
return;
|
||||
}
|
||||
|
||||
let continueRecording = true;
|
||||
let recordCount = 0;
|
||||
if (isInMainUI()) {
|
||||
const position = genshin.getPositionFromMap();
|
||||
log.info(`从小地图获取坐标: X=${position.X}, Y=${position.Y}`);
|
||||
|
||||
trackData.positions.push({
|
||||
"id": trackData.positions.length + 1,
|
||||
"x": position.X,
|
||||
"y": position.Y,
|
||||
"action": "",
|
||||
"move_mode": "walk",
|
||||
"action_params": "",
|
||||
"type": "teleport"
|
||||
});
|
||||
} else {
|
||||
log.info("不在主界面,请返回主界面后重新启动脚本");
|
||||
return;
|
||||
}
|
||||
await sleep(3000);
|
||||
while (continueRecording && recordCount < 999) { // 限制最大录制次数,避免无限循环
|
||||
continueRecording = await recordPosition();
|
||||
if (continueRecording) {
|
||||
recordCount++;
|
||||
await sleep(3000); // 每3秒录制一次
|
||||
}
|
||||
}
|
||||
|
||||
log.info("委托地图追踪录制结束");
|
||||
}
|
||||
|
||||
main();
|
||||
19
repo/js/AutoTranscribePathing/manifest.json
Normal file
19
repo/js/AutoTranscribePathing/manifest.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "地图追踪录制",
|
||||
"version": "1.0",
|
||||
"bgi_version": "0.45.0",
|
||||
"description": "自动地图追踪录制,每3秒从小地图获取一次当前坐标,打开大地图结束录制",
|
||||
"tags": [
|
||||
"工具",
|
||||
"委托"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "星野",
|
||||
"link": "https://github.com/LX666-666"
|
||||
}
|
||||
],
|
||||
"settings_ui": "settings.json",
|
||||
"main": "main.js"
|
||||
}
|
||||
48
repo/js/AutoTranscribePathing/settings.json
Normal file
48
repo/js/AutoTranscribePathing/settings.json
Normal file
@@ -0,0 +1,48 @@
|
||||
[
|
||||
{
|
||||
"name": "questName",
|
||||
"type": "input-text",
|
||||
"label": "委托名称",
|
||||
"default": "默认委托"
|
||||
},
|
||||
{
|
||||
"name": "questLocation",
|
||||
"type": "input-text",
|
||||
"label": "委托地点",
|
||||
"default": "默认地点"
|
||||
},
|
||||
{
|
||||
"name": "trackNumber",
|
||||
"type": "input-text",
|
||||
"label": "地图追踪编号",
|
||||
"default": 1
|
||||
},
|
||||
{
|
||||
"name": "runMode",
|
||||
"type": "select",
|
||||
"label": "运行模式",
|
||||
"options": [
|
||||
"录制模式",
|
||||
"运行模式"
|
||||
],
|
||||
"default": "录制模式"
|
||||
},
|
||||
{
|
||||
"name": "author",
|
||||
"type": "input-text",
|
||||
"label": "作者",
|
||||
"default": "星野工具箱"
|
||||
},
|
||||
{
|
||||
"name": "description",
|
||||
"type": "input-text",
|
||||
"label": "描述",
|
||||
"default": "自动地图追踪录制"
|
||||
},
|
||||
{
|
||||
"name": "version",
|
||||
"type": "input-text",
|
||||
"label": "版本",
|
||||
"default": "1.0"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user