This commit is contained in:
Harvey Zack committed 2022-05-01 15:02:30 +08:00
1 parent 632e88ae0b
commit 755c6dc36a
3 files changed
+58 -48

No files matched your search

@@ -1,36 +1,41 @@
function getData(clientWidth, item) {
const top = item.$ref.offsetTop;
const left = item.$ref.offsetLeft;
const height = item.$ref.clientHeight;
const width = item.$ref.clientWidth;
const distance = left + width;
const right = clientWidth - distance;
const speed = distance / item.$restTime;
const mode = item.mode;
return {
mode,
top,
left,
height,
width,
right,
speed,
distance,
};
}
export default function getDanmuTop(ins, danmu) {
const { clientWidth, clientHeight } = ins.$player;
const { marginBottom, marginTop } = ins;
const { antiOverlap } = ins.option;
const { marginBottom, marginTop } = ins;
const target = getData(clientWidth, danmu);
const danmus = ins.queue
.filter((item) => {
return (
item.$ref &&
item.$state === 'emit' &&
item.mode === danmu.mode &&
item.mode === target.mode &&
item.$ref.offsetTop <= clientHeight - marginBottom
);
})
.map((item) => {
const top = item.$ref.offsetTop;
const left = item.$ref.offsetLeft;
const height = item.$ref.clientHeight;
const width = item.$ref.clientWidth;
const distance = left + width;
const right = clientWidth - distance;
const speed = distance / item.$restTime;
return {
top,
left,
height,
width,
right,
speed,
distance,
};
})
.map((item) => getData(clientWidth, item))
.sort((prev, next) => prev.top - next.top);
if (danmus.length === 0) {
@@ -62,7 +67,7 @@ export default function getDanmuTop(ins, danmu) {
const prev = danmus[index - 1];
const prevBottom = prev.top + prev.height;
const diff = item.top - prevBottom;
if (diff >= danmu.$ref.clientHeight) {
if (diff >= target.height) {
return prevBottom;
}
}
@@ -83,7 +88,7 @@ export default function getDanmuTop(ins, danmu) {
}
if (antiOverlap) {
switch (danmu.mode) {
switch (target.mode) {
case 0:
break;
case 1:
@@ -92,7 +97,7 @@ export default function getDanmuTop(ins, danmu) {
break;
}
} else {
switch (danmu.mode) {
switch (target.mode) {
case 0:
topMap.sort((prev, next) => {
const nextMinRight = Math.min(...next.map((item) => item.right));