Skip to content

Commit

Permalink
新增 ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
sheep-realms committed May 24, 2024
1 parent 05ebbaa commit bdd181f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
| pause | Number | 当前文本输出完毕后的停顿时间。( `Echo.printSpeed * pause` ms ) |
| speed | Number | 当前文本的打印速度,即每个打印循环所用时间(ms)。 |
| typewrite | String | 模拟打字动作。在输出 `text` 字段的内容之前先打印此字段的内容,随后被 `text` 字段的内容替换。 |
| ruby | String | 文本顶部注释。 |
| event | String | 自定义事件名。 |
| data | Object | 自定义数据。 |

Expand Down Expand Up @@ -56,6 +57,7 @@
| printSpeedChange | Number | 打印过程中的打印速度。 | 30 |
| state | String | 运行状态。 | 'stop' |
| typewrite | String | 打字动作状态。 | 'none' |
| ruby | Boolean | 是否正在打印包含注释的内容。 | false |
| filter | Object | 过滤器状态开关。 | 见下文。 |
| event | Object | 用于绑定事件。 ||

Expand Down
14 changes: 14 additions & 0 deletions doc/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@
## printStart
打印开始事件,由 `print()` 方法触发。打印过程开始时触发。

## rubyStart
包含注释内容的文本开始打印事件,由 `groupStart()` 方法触发。

| 参数类型 | 描述 |
| - | - |
| String | 注释内容。 |

## rubyEnd
包含注释内容的文本打印结束事件,由 `groupEnd()` 方法触发。

| 参数类型 | 描述 |
| - | - |
| String | 注释内容。 |

## send
发送消息事件,由 `send()` 方法触发。发送消息时触发,在 `printStart` 事件之前。

Expand Down
15 changes: 14 additions & 1 deletion js/echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Echo {
this.printSpeedChange = 30;
this.state = 'stop';
this.typewrite = 'none';
this.ruby = false;
this.filter = {
HTMLFormat: true
};
Expand All @@ -33,6 +34,8 @@ class Echo {
print: function() {},
printEnd: function() {},
printStart: function() {},
rubyEnd: function() {},
rubyStart: function() {},
send: function() {},
sendList: function() {},
skip: function() {},
Expand Down Expand Up @@ -83,6 +86,10 @@ class Echo {
groupNow: n
}

if (obj?.ruby != undefined) {
this.ruby = false;
this.event.rubyEnd(obj.ruby);
}
if (obj?.typewrite != undefined) {
this.typewrite = 'ready';
}
Expand Down Expand Up @@ -112,6 +119,10 @@ class Echo {
this.event.customData(obj?.data);
}
this.event.groupStart(e);
if (obj?.ruby != undefined) {
this.ruby = true;
this.event.rubyStart(obj.ruby);
}
return e;
}

Expand All @@ -134,14 +145,16 @@ class Echo {
class: msg?.class,
style: msg?.style,
typewrite: msg?.typewrite,
ruby: msg?.ruby,
printSpeed: msg?.speed,
event: msg?.event,
data: msg?.data
};

let dataAfter = {
action: 'group_end',
typewrite: msg?.typewrite
typewrite: msg?.typewrite,
ruby: msg?.ruby
};

let dataContent, data;
Expand Down

0 comments on commit bdd181f

Please sign in to comment.