优化座驾特效入场标题
This commit is contained in:
@@ -221,9 +221,9 @@ const EffectManager = (() => {
|
||||
}
|
||||
|
||||
if (playNext) {
|
||||
const nextType = _dequeueNextType();
|
||||
if (nextType) {
|
||||
play(nextType);
|
||||
const nextEffect = _dequeueNextType();
|
||||
if (nextEffect) {
|
||||
play(nextEffect.type, nextEffect.options || {});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,8 +232,9 @@ const EffectManager = (() => {
|
||||
* 将特效加入有限队列,同类型短时间重复触发时只保留一份。
|
||||
*
|
||||
* @param {string} type 待播放特效类型
|
||||
* @param {object} options 特效附加参数
|
||||
*/
|
||||
function _enqueue(type) {
|
||||
function _enqueue(type, options = {}) {
|
||||
const existingIndex = _queue.findIndex((item) => item.type === type);
|
||||
if (existingIndex !== -1) {
|
||||
_queue.splice(existingIndex, 1);
|
||||
@@ -241,6 +242,7 @@ const EffectManager = (() => {
|
||||
|
||||
_queue.push({
|
||||
type,
|
||||
options,
|
||||
queuedAt: Date.now(),
|
||||
keepUntilPlayed: type === "wedding-fireworks",
|
||||
});
|
||||
@@ -252,7 +254,7 @@ const EffectManager = (() => {
|
||||
/**
|
||||
* 取出下一个仍然有效的排队特效。
|
||||
*
|
||||
* @returns {string|null}
|
||||
* @returns {{type: string, options: object}|null}
|
||||
*/
|
||||
function _dequeueNextType() {
|
||||
const now = Date.now();
|
||||
@@ -260,7 +262,7 @@ const EffectManager = (() => {
|
||||
while (_queue.length > 0) {
|
||||
const next = _queue.shift();
|
||||
if (next.keepUntilPlayed || now - next.queuedAt <= QUEUED_EFFECT_TTL) {
|
||||
return next.type;
|
||||
return next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,14 +332,15 @@ const EffectManager = (() => {
|
||||
* @param {HTMLCanvasElement} canvas 全屏特效画布
|
||||
* @param {Function} finishCurrent 当前特效结束回调
|
||||
* @param {string} startMethod 启动方法名称
|
||||
* @param {object} options 特效附加参数
|
||||
* @returns {boolean} 是否成功找到并启动特效
|
||||
*/
|
||||
function _startEffect(effectObject, canvas, finishCurrent, startMethod = "start") {
|
||||
function _startEffect(effectObject, canvas, finishCurrent, startMethod = "start", options = {}) {
|
||||
if (!effectObject || typeof effectObject[startMethod] !== "function") {
|
||||
return false;
|
||||
}
|
||||
|
||||
_bindEffectController(effectObject[startMethod](canvas, finishCurrent));
|
||||
_bindEffectController(effectObject[startMethod](canvas, finishCurrent, options));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -345,8 +348,9 @@ const EffectManager = (() => {
|
||||
* 播放指定特效
|
||||
*
|
||||
* @param {string} type 特效类型:fireworks / rain / lightning / snow / sakura / meteors / gold-rain / hearts / confetti / fireflies / j35 / 99a / df5c / fujian
|
||||
* @param {object} options 特效附加参数
|
||||
*/
|
||||
function play(type) {
|
||||
function play(type, options = {}) {
|
||||
if (document.hidden) {
|
||||
return;
|
||||
}
|
||||
@@ -358,19 +362,20 @@ const EffectManager = (() => {
|
||||
|
||||
// 防重入:同时只允许一个特效
|
||||
if (_current) {
|
||||
_enqueue(type);
|
||||
_enqueue(type, options);
|
||||
return;
|
||||
}
|
||||
|
||||
_play(type);
|
||||
_play(type, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载模块后播放指定特效。
|
||||
*
|
||||
* @param {string} type 特效类型
|
||||
* @param {object} options 特效附加参数
|
||||
*/
|
||||
async function _play(type) {
|
||||
async function _play(type, options = {}) {
|
||||
_current = type;
|
||||
const token = _playToken;
|
||||
|
||||
@@ -439,16 +444,16 @@ const EffectManager = (() => {
|
||||
started = _startEffect(window.FirefliesEffect, canvas, finishCurrent);
|
||||
break;
|
||||
case "j35":
|
||||
started = _startEffect(window.J35Effect, canvas, finishCurrent);
|
||||
started = _startEffect(window.J35Effect, canvas, finishCurrent, "start", options);
|
||||
break;
|
||||
case "99a":
|
||||
started = _startEffect(window.Type99AEffect, canvas, finishCurrent);
|
||||
started = _startEffect(window.Type99AEffect, canvas, finishCurrent, "start", options);
|
||||
break;
|
||||
case "df5c":
|
||||
started = _startEffect(window.Df5cEffect, canvas, finishCurrent);
|
||||
started = _startEffect(window.Df5cEffect, canvas, finishCurrent, "start", options);
|
||||
break;
|
||||
case "fujian":
|
||||
started = _startEffect(window.FujianEffect, canvas, finishCurrent);
|
||||
started = _startEffect(window.FujianEffect, canvas, finishCurrent, "start", options);
|
||||
break;
|
||||
default:
|
||||
console.warn(`[EffectManager] 未知特效类型:${type}`);
|
||||
|
||||
Reference in New Issue
Block a user