Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xpadev-net committed Jul 14, 2023
2 parents 4f4c738 + d9aad43 commit b4b31cb
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 2 deletions.
18 changes: 18 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,24 @@ <h4>example</h4>
<p>カラーコードは透明度も指定可能です</p>
</div>
</div>
<h3 id="c_fill">Fill</h3>
<div class="item">
<h4>format</h4>
<div class="item">
<pre><code>nico:fill:(color|color code)</code></pre>
</div>
<h4>example</h4>
<div class="item">
<pre><code>nico:fill:red
nico:fill:#f0f
nico:fill:#fff5</code></pre>
</div>
<div class="item" data-i18n="c_fill">
<p>コメント単位で背景色の表示を制御できます</p>
<p>色の指定は色コマンドまたはカラーコードで行ってください</p>
<p>カラーコードは透明度も指定可能です</p>
</div>
</div>
</section>
</main>
</body>
Expand Down
8 changes: 8 additions & 0 deletions docs/localize.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ const localize = {
<p>Color code can also specify transparency</p>`,
`<p>コメント単位で枠の表示を制御できます</p>
<p>色の指定は色コマンドまたはカラーコードで行ってください</p>
<p>カラーコードは透明度も指定可能です</p>`
],
c_fill: [
`<p>You can control the background color per comment.</p>
<p>Colors can be specified with the color command or color code</p>
<p>Color code can also specify transparency</p>`,
`<p>コメント単位で背景色の表示を制御できます</p>
<p>色の指定は色コマンドまたはカラーコードで行ってください</p>
<p>カラーコードは透明度も指定可能です</p>`
]
};
Expand Down
2 changes: 1 addition & 1 deletion docs/sample/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<title></title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/i18next.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/i18nextBrowserLanguageDetector.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@xpadev-net/niconicomments@latest/dist/bundle.min.js"></script>
<script type="text/javascript" src="../../dist/bundle.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@xpadev-net/niconicomments-plugin-niwango@latest/dist/bundle.min.js"></script>
<script
type="text/javascript"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xpadev-net/niconicomments",
"version": "0.2.53",
"version": "0.2.54",
"description": "NiconiComments is a comment drawing library that is somewhat compatible with the official Nico Nico Douga player.",
"main": "dist/bundle.js",
"types": "dist/bundle.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/@types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type FormattedCommentWithFont = {
color: string;
strokeColor?: string;
wakuColor?: string;
fillColor?: string;
full: boolean;
ender: boolean;
_live: boolean;
Expand Down Expand Up @@ -51,6 +52,7 @@ export type ParseCommandAndNicoScriptResult = {
color: string;
strokeColor?: string;
wakuColor?: string;
fillColor?: string;
font: CommentFont;
full: boolean;
ender: boolean;
Expand Down Expand Up @@ -155,6 +157,7 @@ export type ParsedCommand = {
color: string | undefined;
strokeColor?: string;
wakuColor?: string;
fillColor?: string;
font: CommentFont | undefined;
full: boolean;
ender: boolean;
Expand Down
20 changes: 20 additions & 0 deletions src/comments/BaseComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 描画位置
Expand Down
6 changes: 6 additions & 0 deletions src/utils/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const parseCommandAndNicoScript = (
invisible: commands.invisible,
strokeColor: commands.strokeColor,
wakuColor: commands.wakuColor,
fillColor: commands.fillColor,
};
};

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b4b31cb

Please sign in to comment.