diff --git a/docs/3.4-任务流程协议.md b/docs/3.4-任务流程协议.md index 87931361b1..aba51a6fcc 100644 --- a/docs/3.4-任务流程协议.md +++ b/docs/3.4-任务流程协议.md @@ -170,10 +170,10 @@ Base task 的逻辑优先于 template task。这意味着 `"B@A": { "baseTask": #### 多文件任务 -- 后加载的任务文件 (例如外服 `tasks.json`; 下称文件二) 中定义的同名任务直接继承先加载的任务文件 (例如国服 `tasks.json`; 下称文件一) 的参数。 +- 后加载的任务文件 (例如外服 `tasks.json`; 下称文件二) 中定义的同名任务直接继承先加载的任务文件 (例如国服 `tasks.json`; 下称文件一) 的字段。 - 如果文件二中定义的任务在文件一中也定义了同名任务,那么: - 1. 如果文件二中任务没有 `baseTask` 字段,则直接继承文件一中同名任务的参数。 - 2. 如果文件二中任务有字段 `"baseTask": "#none"`,则不继承文件一中同名任务的参数。 + 1. 如果文件二中任务没有 `baseTask` 字段,则直接继承文件一中同名任务的字段。 + 2. 如果文件二中任务有字段 `"baseTask": "#none"`,则不继承文件一中同名任务的字段。 - **若有定义任务 "A",则以 template task 的逻辑处理 "B@A"** - 若未定义任务 "A",则以普通任务的逻辑处理 "B@A" diff --git a/docs/en-us/3.4-TASK_SCHEMA.md b/docs/en-us/3.4-TASK_SCHEMA.md index e0ba8b37cb..cb2b37933a 100644 --- a/docs/en-us/3.4-TASK_SCHEMA.md +++ b/docs/en-us/3.4-TASK_SCHEMA.md @@ -163,10 +163,10 @@ Any parameter that is not explicitly defined uses the value of the `baseTask` pa #### Multi-File Task -- A task with the same name defined in a later loaded task file (e.g. `tasks.json` for foreign services; hereinafter called File 2) inherits directly from the parameters of the first loaded task file (e.g. `tasks.json` for official services; hereinafter called File 1). +- A task with the same name defined in a later loaded task file (e.g. `tasks.json` for foreign services; hereinafter called File 2) inherits directly from the fields of the first loaded task file (e.g. `tasks.json` for official services; hereinafter called File 1). - If a task defined in File 2 also has a task of the same name defined in File 1, then. - 1. if the task in File 2 does not have a `baseTask` field, then it inherits the parameters of the task with the same name in File 1 directly. - 2. If the task in File 2 has the field `"baseTask": "#none"`, then it does not inherit the parameters of the task with the same name in File 1. + 1. if the task in File 2 does not have a `baseTask` field, then it inherits the fields of the task with the same name in File 1 directly. + 2. If the task in File 2 has the field `"baseTask": "#none"`, then it does not inherit the fields of the task with the same name in File 1. - **If task "A" is defined, then "B@A" will be treated as template task** - If task "A" is not defined, then "B@A" will be treated as a normal task diff --git a/docs/ja-jp/3.4-タスクAPI.md b/docs/ja-jp/3.4-タスクAPI.md index f2f176eed0..cb2b37933a 100644 --- a/docs/ja-jp/3.4-タスクAPI.md +++ b/docs/ja-jp/3.4-タスクAPI.md @@ -157,16 +157,18 @@ Base task and template task are collectively called **template task**. A task with the field `baseTask` is a base task. -Any parameter that is not explicitly defined uses the parameter of the corresponding task if `baseTask` is not explicitly defined, except for `template` which remains `"taskName.png"`. (without prefix) +Base task takes precedence over template task. This means that `"B@A": { "baseTask": "C", ... }` has no relevance to task A. -#### Other related +Any parameter that is not explicitly defined uses the value of the `baseTask` parameter for the corresponding task without a prefix, except for `template` which remains `"taskName.png"` if it is not explicitly defined. -- Tasks with the same name defined in `tasks.json` in foreign service inherit directly from `tasks.json` in national service, equivalent to `"A": { "baseTask": "A in national service" }` -- If task "B@A" is defined in national service `tasks.json` and "B@A" is defined in foreign service `tasks.json`, then - 1. if foreign service "B@A" has field `"baseTask": ""`, then it does not inherit from national service "B@A" - - If there is a defined task "A", then "B@A" is handled with the logic of template task - - If there is no defined task "A", then handle "B@A" with the logic of normal task - 2. If there is no `baseTask` for foreign "B@A", then inherit the parameters of national "B@A" directly +#### Multi-File Task + +- A task with the same name defined in a later loaded task file (e.g. `tasks.json` for foreign services; hereinafter called File 2) inherits directly from the fields of the first loaded task file (e.g. `tasks.json` for official services; hereinafter called File 1). +- If a task defined in File 2 also has a task of the same name defined in File 1, then. + 1. if the task in File 2 does not have a `baseTask` field, then it inherits the fields of the task with the same name in File 1 directly. + 2. If the task in File 2 has the field `"baseTask": "#none"`, then it does not inherit the fields of the task with the same name in File 1. + - **If task "A" is defined, then "B@A" will be treated as template task** + - If task "A" is not defined, then "B@A" will be treated as a normal task ### Virtual Task @@ -224,6 +226,19 @@ Task.get_raw("B@Loading")->next = { "B#self", "B#next", "B#back" }; In this case above, `"C@B" -> next` (i.e. `C@A#next`) is `["N1"]` instead of `["C@N0"]`. +## Expression Calculation + +| Symbol | Meaning | Example | +|:---------:|:---:|:--------:| +| `@` | Template task | `Fight@ReturnTo` | +| `#` (unary) | Virtual task | `#self` | +| `#` (binary) | Virtual task | `StartUpThemes#next` | +| `*` | Repeat tasks | `(ClickCornerAfterPRTS+ClickCorner)*5` | +| `+` | Task list merge | `A+B` | +| `^` | Task list difference (in the former but not in the latter, the order remains the same) | `(A+A+B+C)^(A+B+D)` (= `C`) | + +The operators `@`, `#`, `*`, `+`, `^` have priority: `#` (unary) > `@` = `#` (binary) > `*` > `+` = `^`. + ## Schema Check This project configures a json schema check for `tasks.json`, the schema file is `docs/maa_tasks_schema.json`. diff --git a/docs/zh-tw/3.4-任務流程協議.md b/docs/zh-tw/3.4-任務流程協議.md index f5cdf368f1..294ecb441f 100644 --- a/docs/zh-tw/3.4-任務流程協議.md +++ b/docs/zh-tw/3.4-任務流程協議.md @@ -170,10 +170,10 @@ Base task 的邏輯優先於 template task。這代表 `"B@A": { "baseTask": "C" #### 多檔任務 -- 後載入的任務檔案(例如外服 `tasks.json`,下稱文件二)中定義的同名任務直接繼承先載入的任務檔案(例如國服 `tasks.json`,下稱文件一)的參數。 +- 後載入的任務檔案(例如外服 `tasks.json`,下稱文件二)中定義的同名任務直接繼承先載入的任務檔案(例如國服 `tasks.json`,下稱文件一)的欄位。 - 如果文件二中定義的任務在文件一中也定義了同名任務,那麼: - 1. 如果文件二中任務沒有 `baseTask` 欄位,則直接繼承文件一中同名任務的參數。 - 2. 如果文件二中任務有欄位 `"baseTask": "#none"`,則不繼承文件一中同名任務的參數。 + 1. 如果文件二中任務沒有 `baseTask` 欄位,則直接繼承文件一中同名任務的欄位。 + 2. 如果文件二中任務有欄位 `"baseTask": "#none"`,則不繼承文件一中同名任務的欄位。 - **若有定義任務 "A",則以 template task 的邏輯處理 "B@A"** - 若未定義任務 "A",則以普通任務的邏輯處理 "B@A" diff --git a/src/MaaCore/Config/TaskData.cpp b/src/MaaCore/Config/TaskData.cpp index c3e5fa939b..9b76993209 100644 --- a/src/MaaCore/Config/TaskData.cpp +++ b/src/MaaCore/Config/TaskData.cpp @@ -79,13 +79,19 @@ bool asst::TaskData::parse(const json::value& json) std::unordered_map task_status; for (const auto& [name, task_json] : json.as_object()) { + std::string_view name_view = task_name_view(name); if (task_json.get("baseTask", "") == "#none") { // 不继承同名任务参数 - m_json_all_tasks_info[name] = task_json.as_object(); + m_json_all_tasks_info[name_view] = task_json.as_object(); + m_json_all_tasks_info[name_view].erase("baseTask"); + continue; + } + if (m_json_all_tasks_info.find(name_view) == m_json_all_tasks_info.cend()) { + m_json_all_tasks_info.emplace(name_view, task_json.as_object()); continue; } for (const auto& [key, value] : task_json.as_object()) { - m_json_all_tasks_info[task_name_view(name)][key] = value; + m_json_all_tasks_info[name_view][key] = value; } }