Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[修正] 位置計算ロジックを改善 #94

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/comments/BaseComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BaseComment implements IComment {
*/
constructor(comment: FormattedComment, renderer: IRenderer, index: number) {
this.renderer = renderer;
this.posY = 0;
this.posY = -1;
this.pos = { x: 0, y: 0 };
comment.content = comment.content.replace(/\t/g, "\u2003\u2003");
this.comment = this.convertComment(comment);
Expand Down
2 changes: 1 addition & 1 deletion src/comments/HTML5Comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HTML5Comment extends BaseComment {
override readonly pluginName: string = "HTML5Comment";
constructor(comment: FormattedComment, context: IRenderer, index: number) {
super(comment, context, index);
this.posY = 0;
this.posY = -1;
}

override get content() {
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class NiconiComments {
const getCommentPosStart = performance.now();
if (this.processedCommentIndex + 1 >= end) return;
for (const comment of data.slice(this.processedCommentIndex, end)) {
if (comment.invisible) continue;
if (comment.invisible || (comment.posY > -1 && !lazy)) continue;
if (comment.loc === "naka") {
processMovableComment(comment, this.collision, this.timeline, lazy);
} else {
Expand Down
17 changes: 13 additions & 4 deletions src/utils/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ const processMovableComment = (
for (let j = beforeVpos, n = comment.long + 125; j < n; j++) {
const vpos = comment.vpos + j;
const leftPos = getPosX(comment.comment, vpos);
if (timeline[vpos]?.includes(comment)) break;
arrayPush(timeline, vpos, comment);
if (
leftPos + comment.width + config.collisionPadding >=
Expand Down Expand Up @@ -668,19 +669,24 @@ const getMovablePosY = (
}
let posY = 0;
let isChanged = true;
let lastUpdatedIndex: number | undefined = undefined;
while (isChanged) {
isChanged = false;
for (let j = beforeVpos, n = comment.long + 125; j < n; j++) {
for (let j = beforeVpos, n = comment.long + 125; j < n; j += 5) {
const vpos = comment.vpos + j;
const leftPos = getPosX(comment.comment, vpos);
let isBreak = false;
if (lastUpdatedIndex !== undefined && lastUpdatedIndex === vpos) {
return posY;
}
if (
leftPos + comment.width >= config.collisionRange.right &&
leftPos <= config.collisionRange.right
) {
const result = getPosY(posY, comment, collision.right[vpos]);
posY = result.currentPos;
isChanged ||= result.isChanged;
if (result.isChanged) lastUpdatedIndex = vpos;
isBreak = result.isBreak;
}
if (
Expand All @@ -690,6 +696,7 @@ const getMovablePosY = (
const result = getPosY(posY, comment, collision.left[vpos]);
posY = result.currentPos;
isChanged ||= result.isChanged;
if (result.isChanged) lastUpdatedIndex = vpos;
isBreak = result.isBreak;
}
if (isBreak) return posY;
Expand All @@ -715,11 +722,13 @@ const getPosY = (
let isBreak = false;
if (!collision) return { currentPos, isChanged, isBreak };
for (const collisionItem of collision) {
if (collisionItem.index === targetComment.index || collisionItem.posY < 0)
continue;
if (
currentPos < collisionItem.posY + collisionItem.height &&
currentPos + targetComment.height > collisionItem.posY &&
collisionItem.owner === targetComment.owner &&
collisionItem.layer === targetComment.layer
collisionItem.layer === targetComment.layer &&
currentPos < collisionItem.posY + collisionItem.height &&
currentPos + targetComment.height > collisionItem.posY
) {
if (collisionItem.posY + collisionItem.height > currentPos) {
currentPos = collisionItem.posY + collisionItem.height;
Expand Down
Loading