From 767c999077d5596bef7b8e83ea0518bbeedff81e Mon Sep 17 00:00:00 2001 From: Dongw Date: Sat, 23 Sep 2023 23:08:07 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E9=80=82=E9=85=8Dschema?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/resource/pipeline.schema.json | 619 +++++++++++++++++++++- assets/resource/pipeline/awards.json | 5 +- assets/resource/pipeline/end_to_do.json | 1 + assets/resource/pipeline/homeland.json | 6 +- assets/resource/pipeline/startup.json | 35 +- assets/resource/pipeline/story_sweep.json | 1 + 6 files changed, 621 insertions(+), 46 deletions(-) diff --git a/assets/resource/pipeline.schema.json b/assets/resource/pipeline.schema.json index b04a548..e4508b4 100644 --- a/assets/resource/pipeline.schema.json +++ b/assets/resource/pipeline.schema.json @@ -2,15 +2,23 @@ "$schema": "https://json-schema.org/draft-07/schema", "type": "object", "patternProperties": { - "^.*$": { + "^(?!.*?\\$schema).*$": { "type": "object", + "patternProperties": { + ".*_doc$": { + "type": "string" + } + }, "properties": { "recognition": { "description": "识别算法类型。可选,默认 DirectHit。", "enum": [ "DirectHit", "TemplateMatch", + "ColorMatch", "OCR", + "Classify", + "Detect", "Custom" ], "default": "DirectHit" @@ -22,7 +30,6 @@ "Click", "Swipe", "Key", - "WaitFreezes", "StartApp", "StopApp", "Custom" @@ -82,23 +89,448 @@ }, "pre_wait_freezes": { "description": "识别到 到 执行动作前,等待画面不动了的时间,毫秒。可选,默认 0,即不等待。", - "type": "integer", - "minimum": 0, - "default": 0 + "$ref": "#/definitions/wait_freezes_type" }, "post_wait_freezes": { "description": "行动动作后 到 识别 next,等待画面不动了的时间,毫秒。可选,默认 0,即不等待。", - "type": "integer", + "$ref": "#/definitions/wait_freezes_type" + }, + "focus": { + "description": "产生同步回调消息。可选,默认空,即不产生。", + "type": "boolean", + "default": false + }, + "roi": { + "description": "识别区域坐标。可选,默认 [0, 0, 0, 0],即全屏。", + "$ref": "#/definitions/rectlist", + "default": [ + 0, + 0, + 0, + 0 + ] + }, + "template": { + "description": "模板图片路径,需要 image 文件夹的相对路径。必选。", + "$ref": "#/definitions/tasklist", + "default": "" + }, + "threshold": { + "description": "模板匹配阈值。可选,默认 0.7 。", + "type": "number", + "default": 0.7, "minimum": 0, + "maximum": 1 + }, + "method": { + "description": "模板匹配算法,即 cv::TemplateMatchModes。可选,默认 5 ", + "enum": [ + 1, + 3, + 5 + ], + "default": 5 + }, + "green_mask": { + "description": "是否进行绿色掩码。可选,默认 false。", + "type": "boolean", + "default": false + }, + "lower": { + "description": "颜色下限值。必选。最内层 list 长度需和 method 的通道数一致。", + "$ref": "#/definitions/colorlist" + }, + "upper": { + "description": "颜色上限值。必选。最内层 list 长度需和 method 的通道数一致。", + "$ref": "#/definitions/colorlist" + }, + "count": { + "description": "符合的点的数量要求。可选,默认 1。", + "type": "integer", + "default": 1 + }, + "connected": { + "description": "是否是相连的点才会被计数。可选,默认否。", + "type": "boolean", + "default": false + }, + "text": { + "description": "要匹配的文字,支持正则。必选(除非通过接口单独设置)。", + "$ref": "#/definitions/tasklist", + "default": "" + }, + "replace": { + "description": "部分文字识别结果不准确,进行替换。可选。", + "$ref": "#/definitions/replace_type", + "default": [] + }, + "only_rec": { + "description": "是否仅识别(不进行检测,需要精确设置 roi)。可选,默认 false。", + "type": "boolean", + "default": false + }, + "model": { + "description": "模型 文件夹 路径。使用 model/ocr 文件夹的相对路径。可选,默认为空。", + "type": "string", + "default": "" + }, + "cls_size": { + "description": "总分类数,必选。", + "type": "integer", + "default": 2 + }, + "labels": { + "description": "标注,即每个分类的名字。可选。", + "type": "array", + "items": { + "type": "string" + } + }, + "expected": { + "description": "期望的分类下标。必选", + "$ref": "#/definitions/expected_type" + }, + "custom_recognizer": { + "description": "任务名,同 MaaRegisterCustomRecognizer 接口传入的识别器名。必选。", + "type": "string", + "default": "" + }, + "custom_recognizer_param": { + "description": "任务参数,任意类型,会在执行时透传。可选,默认空 json,即 {}", + "default": {} + }, + "target": { + "description": "等待的目标。可选,默认 true。", + "$ref": "#/definitions/target_type", + "default": true + }, + "target_offset": { + "description": "在 target 的基础上额外移动再作为等待目标,四个值分别相加。可选,默认 [0, 0, 0, 0]。", + "$ref": "#/definitions/rect", + "default": [ + 0, + 0, + 0, + 0 + ] + }, + "begin": { + "description": "滑动起点。可选,默认 true。", + "$ref": "#/definitions/target_type", + "default": true + }, + "begin_offset": { + "description": "在 begin 的基础上额外移动再作为起点,四个值分别相加。可选,默认 [0, 0, 0, 0]。", + "$ref": "#/definitions/rect", + "default": [ + 0, + 0, + 0, + 0 + ] + }, + "end": { + "description": "滑动终点。必选,默认 true。", + "$ref": "#/definitions/target_type", + "default": true + }, + "end_offset": { + "description": "在 end 的基础上额外移动再作为终点,四个值分别相加。可选,默认 [0, 0, 0, 0]。", + "$ref": "#/definitions/rect", + "default": [ + 0, + 0, + 0, + 0 + ] + }, + "duration": { + "description": "滑动持续时间,单位毫秒。可选,默认 200", + "type": "integer", + "default": 200 + }, + "key": { + "description": "要按的键,仅支持 ascii。", + "$ref": "#/definitions/keylist", "default": 0 }, - "notify": { - "description": "产生同步回调消息。可选,默认空,即不产生。", + "package": { + "description": "启动入口。可选,默认空。", "type": "string", - "default": false + "default": "" + }, + "custom_action": { + "description": "任务名,同 MaaRegisterCustomAction 接口传入的动作名。必选。", + "type": "string", + "default": "" + }, + "custom_action_param": { + "description": "任务参数,任意类型,通过 MaaCustomRecognizerAPI 传入 json string。可选,默认空 json,即 {}", + "default": {} } }, - "additionalProperties": false + "additionalProperties": false, + "dependenciesSchemas": { + "recognition": { + "oneOf": [ + { + "$comment": "TemplateMatch", + "if": { + "required": [ + "recognition" + ], + "properties": { + "recognition": { + "enum": [ + "TemplateMatch" + ] + } + } + }, + "then": { + "required": [ + "template" + ] + } + }, + { + "$comment": "ColorMatch", + "if": { + "required": [ + "recognition" + ], + "properties": { + "recognition": { + "enum": [ + "ColorMatch" + ] + } + } + }, + "then": { + "required": [ + "lower", + "upper" + ], + "properties": { + "method": { + "description": "颜色匹配方式。即 cv::ColorConversionCodes。可选,默认 4 (RGB)。\n常用值:4 (RGB, 3 通道), 40 (HSV, 3 通道), 6 (GRAY, 1 通道)。", + "type": "integer", + "default": 4 + } + } + } + }, + { + "$comment": "OCR", + "if": { + "required": [ + "recognition" + ], + "properties": { + "recognition": { + "enum": [ + "OCR" + ] + } + }, + "not": { + "required": [ + "text_doc" + ] + } + }, + "then": { + "required": [ + "text" + ] + } + }, + { + "$comment": "Classify", + "if": { + "required": [ + "recognition" + ], + "properties": { + "recognition": { + "enum": [ + "Classify" + ] + } + } + }, + "then": { + "required": [ + "cls_size", + "model", + "expected" + ], + "properties": { + "model": { + "description": "模型文件路径。使用 model/classify 文件夹的相对路径。必选。", + "type": "string", + "default": "" + } + } + } + }, + { + "$comment": "Detect", + "if": { + "required": [ + "recognition" + ], + "properties": { + "recognition": { + "enum": [ + "Detect" + ] + } + } + }, + "then": { + "required": [ + "cls_size", + "model", + "expected" + ], + "properties": { + "model": { + "description": "模型文件路径。使用 model/detect 文件夹的相对路径。必选。", + "type": "string", + "default": "" + }, + "threshold": { + "description": "模型置信度阈值。可选,默认 0.3 。", + "anyOf": [ + { + "type": "number" + }, + { + "type": "array", + "items": { + "type": "number" + }, + "minItems": 1 + } + ], + "default": 0.3 + } + } + } + }, + { + "$comment": "Custom", + "if": { + "required": [ + "recognition" + ], + "properties": { + "recognition": { + "enum": [ + "Custom" + ] + } + } + }, + "then": { + "required": [ + "custom_recognizer" + ] + } + } + ] + }, + "action": { + "oneOf": [ + { + "$comment": "Swipe", + "if": { + "required": [ + "action" + ], + "properties": { + "action": { + "enum": [ + "Swipe" + ] + } + } + }, + "then": { + "required": [ + "end" + ] + } + }, + { + "$comment": "Key", + "if": { + "required": [ + "action" + ], + "properties": { + "action": { + "enum": [ + "Key" + ] + } + } + }, + "then": { + "required": [ + "key" + ] + } + }, + { + "$comment": "StopApp", + "if": { + "required": [ + "action" + ], + "properties": { + "action": { + "enum": [ + "StopApp" + ] + } + } + }, + "then": { + "properties": { + "package": { + "description": "关闭要关闭的程序。可选,默认空。", + "type": "string", + "default": "" + } + } + } + }, + { + "$comment": "Custom", + "if": { + "required": [ + "action" + ], + "properties": { + "action": { + "enum": [ + "Custom" + ] + } + } + }, + "then": { + "required": [ + "custom_action" + ] + } + } + ] + } + } } }, "definitions": { @@ -110,6 +542,30 @@ "minItems": 4, "maxItems": 4 }, + "rectlist": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "number" + }, + "minItems": 4, + "maxItems": 4 + }, + { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "number" + }, + "minItems": 4, + "maxItems": 4 + }, + "minItems": 1 + } + ] + }, "tasklist": { "anyOf": [ { @@ -122,6 +578,149 @@ } } ] + }, + "colorlist": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "integer" + }, + "minItems": 1 + }, + { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "integer" + }, + "minItems": 1 + }, + "minItems": 1 + } + ] + }, + "replace_type": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 2, + "maxItems": 2 + }, + { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string" + }, + "minItems": 2, + "maxItems": 2 + }, + "minItems": 1 + } + ] + }, + "expected_type": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "array", + "items": { + "type": "integer" + }, + "minItems": 1 + } + ] + }, + "keylist": { + "anyOf": [ + { + "type": "integer", + "minimum": 0, + "maximum": 127 + }, + { + "type": "array", + "items": { + "type": "integer", + "minimum": 0, + "maximum": 127 + }, + "minItems": 1 + } + ] + }, + "target_type": { + "anyOf": [ + { + "type": "boolean" + }, + { + "type": "string" + }, + { + "$ref": "#/definitions/rect" + } + ] + }, + "wait_freezes_type": { + "anyOf": [ + { + "type": "integer", + "minimum": 0, + "default": 1 + }, + { + "type": "object", + "properties": { + "time": { + "description": "连续 time 毫秒 画面 没有较大变化 才会退出动作。可选,默认 1。", + "type": "integer", + "minimum": 0, + "default": 1 + }, + "target": { + "description": "等待的目标。可选,默认 true。", + "$ref": "#/definitions/target_type", + "default": true + }, + "target_offset": { + "description": "在 target 的基础上额外移动再作为等待目标,四个值分别相加。可选,默认 [0, 0, 0, 0]。", + "$ref": "#/definitions/rect", + "default": [ + 0, + 0, + 0, + 0 + ] + }, + "threshold": { + "description": "判断“没有较大变化”的模板匹配阈值。可选,默认 0.95 。", + "type": "number", + "minimum": 0, + "maximum": 1, + "default": 0.95 + }, + "method": { + "description": "判断“没有较大变化”的模板匹配算法,即 cv::TemplateMatchModes。可选,默认 5 。", + "type": "integer", + "enum": [ + 1, + 3, + 5 + ], + "default": 5 + } + } + } + ] } } } \ No newline at end of file diff --git a/assets/resource/pipeline/awards.json b/assets/resource/pipeline/awards.json index 6587c83..8f948b8 100644 --- a/assets/resource/pipeline/awards.json +++ b/assets/resource/pipeline/awards.json @@ -4,10 +4,7 @@ "next": [ "EnterAwards", "Sub_StartUp" - ], - "editor_info": { - "path": "/awards.json/" - } + ] }, "EnterAwards": { "recognition": "OCR", diff --git a/assets/resource/pipeline/end_to_do.json b/assets/resource/pipeline/end_to_do.json index 7c74988..bfbd86b 100644 --- a/assets/resource/pipeline/end_to_do.json +++ b/assets/resource/pipeline/end_to_do.json @@ -1,4 +1,5 @@ { + "$schema": "../pipeline.schema.json", "EndToDo": { "next": [ "CloseBH3", diff --git a/assets/resource/pipeline/homeland.json b/assets/resource/pipeline/homeland.json index 744ef41..74667b6 100644 --- a/assets/resource/pipeline/homeland.json +++ b/assets/resource/pipeline/homeland.json @@ -1,4 +1,5 @@ { + "$schema": "../pipeline.schema.json", "Homeland": { "next": [ "Sub_HomeButton", @@ -11,10 +12,7 @@ "CollectAP", "EnterQuest", "Sub_StartUp" - ], - "editor_info": { - "path": "/homeland.json/" - } + ] }, "EnterHomeland": { "recognition": "OCR", diff --git a/assets/resource/pipeline/startup.json b/assets/resource/pipeline/startup.json index ea6c66b..238107e 100644 --- a/assets/resource/pipeline/startup.json +++ b/assets/resource/pipeline/startup.json @@ -1,4 +1,5 @@ { + "$schema": "../pipeline.schema.json", "Sub_StartUp": { "is_sub": true, "next": [ @@ -15,18 +16,12 @@ "GameLoading", "HomeFlag", "Sub_StartBH3" - ], - "editor_info": { - "path": "/startup.json/" - } + ] }, "Sub_StartBH3": { "is_sub": true, "action": "StartApp", - "package_doc": "set in code.", - "editor_info": { - "path": "/startup.json/" - } + "package_doc": "set in code." }, "RestartBH3": { "action": "StopApp", @@ -66,10 +61,7 @@ "GameIdentifying", "Sub_CloseAnnouncement", "HomeFlag" - ], - "editor_info": { - "path": "/startup.json/" - } + ] }, "GameIdentifying": { "recognition": "TemplateMatch", @@ -106,10 +98,7 @@ 109, 133 ], - "action": "Click", - "editor_info": { - "path": "/startup.json/" - } + "action": "Click" }, "StartGame": { "recognition": "OCR", @@ -129,9 +118,6 @@ "timeout_next": [ "RestartBH3" ], - "editor_info": { - "path": "/startup.json/" - }, "roi": [ 458, 458, @@ -152,16 +138,9 @@ 584, 141, 136 - ], - "editor_info": { - "path": "/startup.json/" - } - }, - "Stop": { - "editor_info": { - "path": "/startup.json/" - } + ] }, + "Stop": {}, "Sub_CollectDailyLoginReward": { "is_sub": true, "recognition": "TemplateMatch", diff --git a/assets/resource/pipeline/story_sweep.json b/assets/resource/pipeline/story_sweep.json index f3feba4..f53568b 100644 --- a/assets/resource/pipeline/story_sweep.json +++ b/assets/resource/pipeline/story_sweep.json @@ -1,4 +1,5 @@ { + "$schema": "../pipeline.schema.json", "StorySweep": { "next": [ "StorySweepEnterHomeland",