From eda9ac0c7961d1c457d741037effb470c75f256e Mon Sep 17 00:00:00 2001 From: xpadev Date: Sat, 15 Jul 2023 01:05:57 +0900 Subject: [PATCH 1/4] feat: add nico:fill command --- src/@types/types.d.ts | 3 +++ src/comments/BaseComment.ts | 20 ++++++++++++++++++++ src/utils/comment.ts | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/src/@types/types.d.ts b/src/@types/types.d.ts index 0176acd8..0d765ea9 100755 --- a/src/@types/types.d.ts +++ b/src/@types/types.d.ts @@ -17,6 +17,7 @@ export type FormattedCommentWithFont = { color: string; strokeColor?: string; wakuColor?: string; + fillColor?: string; full: boolean; ender: boolean; _live: boolean; @@ -51,6 +52,7 @@ export type ParseCommandAndNicoScriptResult = { color: string; strokeColor?: string; wakuColor?: string; + fillColor?: string; font: CommentFont; full: boolean; ender: boolean; @@ -155,6 +157,7 @@ export type ParsedCommand = { color: string | undefined; strokeColor?: string; wakuColor?: string; + fillColor?: string; font: CommentFont | undefined; full: boolean; ender: boolean; diff --git a/src/comments/BaseComment.ts b/src/comments/BaseComment.ts index 449120f6..688eb6b2 100755 --- a/src/comments/BaseComment.ts +++ b/src/comments/BaseComment.ts @@ -152,6 +152,7 @@ class BaseComment implements IComment { this.comment.loc === "shita" ? config.canvasHeight - this.posY - this.comment.height : this.posY; + this._drawBackgroundColor(posX, posY); this._draw(posX, posY); this._drawRectColor(posX, posY); this._drawCollision(posX, posY, showCollision); @@ -198,6 +199,25 @@ class BaseComment implements IComment { } } + /** + * コメントの背景を描画する + * @param posX 描画位置 + * @param posY 描画位置 + */ + protected _drawBackgroundColor(posX: number, posY: number) { + if (this.comment.fillColor) { + this.context.save(); + this.context.fillStyle = this.comment.fillColor; + this.context.fillRect( + posX, + posY, + this.comment.width, + this.comment.height + ); + this.context.restore(); + } + } + /** * コメントのメタデータを描画する * @param posX 描画位置 diff --git a/src/utils/comment.ts b/src/utils/comment.ts index 8e947828..a99b8786 100755 --- a/src/utils/comment.ts +++ b/src/utils/comment.ts @@ -140,6 +140,7 @@ const parseCommandAndNicoScript = ( invisible: commands.invisible, strokeColor: commands.strokeColor, wakuColor: commands.wakuColor, + fillColor: commands.fillColor, }; }; @@ -439,6 +440,11 @@ const parseCommand = ( result.wakuColor ??= rectColor; return; } + const fillColor = getColor(command.match(/^nico:fill:(.+)$/)); + if (fillColor) { + result.fillColor ??= fillColor; + return; + } if (typeGuard.comment.loc(command)) { result.loc ??= command; return; From eb2ac62467a6a48242c85587804fc812b65b4172 Mon Sep 17 00:00:00 2001 From: xpadev Date: Sat, 15 Jul 2023 01:06:27 +0900 Subject: [PATCH 2/4] fix: script link of sample --- docs/sample/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sample/index.html b/docs/sample/index.html index 774df36f..a4f1af49 100755 --- a/docs/sample/index.html +++ b/docs/sample/index.html @@ -6,7 +6,7 @@ - +