This commit is contained in:
yinsx
2025-12-25 09:46:16 +08:00
parent 48d587c1ff
commit e56f47076c
4 changed files with 36 additions and 19 deletions

View File

@ -131,6 +131,7 @@ const ExpressionLibrary = {
enabled: false,
timeout: null,
currentExpression: null,
lastExpressionKey: null,
intervalMin: 3000,
intervalMax: 8000,
@ -170,7 +171,10 @@ const ExpressionLibrary = {
return;
}
const randomKey = enabledKeys[Math.floor(Math.random() * enabledKeys.length)];
const availableKeys = enabledKeys.length > 1 && this.lastExpressionKey
? enabledKeys.filter(key => key !== this.lastExpressionKey)
: enabledKeys;
const randomKey = availableKeys[Math.floor(Math.random() * availableKeys.length)];
const expression = ExpressionLibrary.expressions[randomKey];
this.play(expression);
@ -178,6 +182,9 @@ const ExpressionLibrary = {
play: function(expression) {
this.currentExpression = expression;
this.lastExpressionKey = Object.keys(ExpressionLibrary.expressions).find(
key => ExpressionLibrary.expressions[key] === expression
);
// 从主页面获取动画速度参数
const speed = window.expressionParams?.speed || 400;
@ -189,17 +196,13 @@ const ExpressionLibrary = {
}
}
// 获取表情的key
const expressionKey = Object.keys(ExpressionLibrary.expressions).find(
key => ExpressionLibrary.expressions[key] === expression
);
// 使用用户设置的持续时间,如果没有则使用表情默认时间
const duration = (window.expressionDurations && window.expressionDurations[expressionKey])
const duration = (window.expressionDurations && window.expressionDurations[this.lastExpressionKey])
|| expression.duration;
setTimeout(() => {
this.reset();
if (!this.enabled) return;
this.scheduleNext();
}, duration);
},