dsh-workbench-danmaku 0.2.13 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- import { configState, loadConfig, resetConfig, writeConfig } from "../config.js";
3
+ import { configState, loadConfig, resetConfig, schemeActivate, schemeCreate, schemeDelete, schemeRename, writeConfig } from "../config.js";
4
4
 
5
5
  export function registerConfigActions(api, deps) {
6
6
  const db = api.db;
@@ -13,7 +13,7 @@ export function registerConfigActions(api, deps) {
13
13
  });
14
14
 
15
15
  api.action("danmaku.configSet", {
16
- description: "写入弹幕配置;值会做类型与范围校验,写入后立即影响调度节奏与显示层",
16
+ description: "把弹幕配置写入当前方案;值会做类型与范围校验,写入后立即影响调度节奏与显示层",
17
17
  input: {
18
18
  type: "object",
19
19
  properties: {
@@ -22,8 +22,8 @@ export function registerConfigActions(api, deps) {
22
22
  required: ["values"],
23
23
  additionalProperties: false,
24
24
  },
25
- execute: (args) => {
26
- const out = writeConfig(db, args.values);
25
+ execute: (args, ctx) => {
26
+ const out = writeConfig(db, args.values, ctx && ctx.origin);
27
27
  if (out.changed.length) deps.changed("config", out.changed.join(","));
28
28
  return { changed: out.changed, values: out.state.values, overrides: out.state.overrides };
29
29
  },
@@ -47,6 +47,34 @@ export function registerConfigActions(api, deps) {
47
47
  render: () => "弹幕配置已恢复默认",
48
48
  });
49
49
 
50
+ api.action("danmaku.configSchemeCreate", {
51
+ description: "新建配置方案并立即切换过去;from=current 复制当前值,from=default 从插件默认值开始",
52
+ input: { type: "object", properties: { name: { type: "string", description: "方案名称,1–64 个字符" }, from: { type: "string", enum: ["current", "default"] } }, required: ["name"], additionalProperties: false },
53
+ execute: (args, ctx) => schemeCreate(db, args.name, args.from, ctx && ctx.origin),
54
+ render: (r) => `已新建并启用配置方案:${r.state.scheme.name}`,
55
+ });
56
+
57
+ api.action("danmaku.configSchemeRename", {
58
+ description: "重命名配置方案",
59
+ input: { type: "object", properties: { id: { type: "string" }, name: { type: "string" } }, required: ["id", "name"], additionalProperties: false },
60
+ execute: (args) => schemeRename(db, args.id, args.name),
61
+ render: (r) => `配置方案已改名:${r.state.scheme.name}`,
62
+ });
63
+
64
+ api.action("danmaku.configSchemeDelete", {
65
+ description: "软删除配置方案;删除的是当前方案时回到「不使用方案」",
66
+ input: { type: "object", properties: { id: { type: "string" } }, required: ["id"], additionalProperties: false },
67
+ execute: (args) => schemeDelete(db, args.id),
68
+ render: () => "配置方案已删除",
69
+ });
70
+
71
+ api.action("danmaku.configSchemeActivate", {
72
+ description: "切换当前设备的配置方案;id 传空表示不使用方案、回到插件默认配置",
73
+ input: { type: "object", properties: { id: { type: "string" } }, additionalProperties: false },
74
+ execute: (args) => schemeActivate(db, args.id),
75
+ render: (r) => (r.id ? "已切换配置方案" : "已改为不使用方案(插件默认配置)"),
76
+ });
77
+
50
78
  api.action("danmaku.theme", {
51
79
  description: "由界面层上报当前 DSH 主题色,桌面透明窗据此换色;不写库",
52
80
  input: {