修复单次多个礼物bug

* 强度增减数值与赠送礼物数量相同
* 波形时长改为 `5*礼物数量`
This commit is contained in:
Fang_Zhijian 2024-05-27 17:20:40 +08:00
parent c6d0c24b90
commit 9100d2d431
2 changed files with 24 additions and 20 deletions

View File

@ -146,31 +146,37 @@ function sendWsMsg(messageObj) {
messageObj.targetId = targetWSId; messageObj.targetId = targetWSId;
if (!messageObj.hasOwnProperty('type')) if (!messageObj.hasOwnProperty('type'))
messageObj.type = "msg"; messageObj.type = "msg";
wsConn.send(JSON.stringify((messageObj))); wsConn.send(JSON.stringify((messageObj)))
} }
function addOrIncrease(type, channelIndex, strength) { function addOrIncrease(type, channelIndex, strength) {
// 1 减少 2 增加 3 设置到 // 1 减少 2 增加 3 设置到
// channel:1-A 2-B // channel:1-A 2-B
// 获取当前频道元素和当前值 // 获取当前通道的当前值
let channelStrength = channelIndex === 1 ? channelAStrength.value : channelBStrength.value; let channelStrength = channelIndex === 1 ? channelAStrength.value : channelBStrength.value;
// 如果是设置操作 // 如果是设置操作
if (type === 3) { if (type === 3) {
channelStrength = strength; //固定为0 channelStrength = strength
} }
// 减少 // 减少
else if (type === 1) { else if (type === 1) {
channelStrength = Math.max(channelStrength - strength, 0); channelStrength = Math.max(channelStrength - strength, 0)
} }
// 增加 // 增加
else if (type === 2) { else if (type === 2) {
channelStrength = Math.min(channelStrength + strength, 200); channelStrength = Math.min(channelStrength + strength, 200)
} }
// 构造消息对象并发送 // 构造消息对象并发送
const data = { type, strength: channelStrength, message: "set channel", channel: channelIndex }; let data = {}
console.log(data) if (type === 3) {
data = { type, strength: channelStrength, message: "set channel", channel: channelIndex }
} else {
// 这里用 type 4 可以自定义增加减小是数值type 2/3 固定是 1
data = { type: 4, message: "strength-" + channelIndex + "+" + (type - 1) + "+" + strength }
}
sendWsMsg(data); sendWsMsg(data);
} }

View File

@ -93,11 +93,9 @@ function createSocket(authBody: string, wssLinks: string[]) {
if (settings && res.data.gift_id.toString() === settings.value.strengthData[0]) { if (settings && res.data.gift_id.toString() === settings.value.strengthData[0]) {
// 加强度1 // 加强度1
try { try {
console.log("开始操作") addOrIncrease(2, 1, res.data.gift_num)
addOrIncrease(2, 1, 1) addOrIncrease(2, 2, res.data.gift_num)
addOrIncrease(2, 2, 1) notyf.success("收到" + res.data.gift_name + ",强度+" + res.data.gift_num)
console.log("结束操作")
notyf.success("收到" + res.data.gift_name + ",强度+1")
} }
catch (e) { catch (e) {
console.log(e) console.log(e)
@ -106,9 +104,9 @@ function createSocket(authBody: string, wssLinks: string[]) {
} else if (settings && res.data.gift_id.toString() === settings.value.strengthData[1]) { } else if (settings && res.data.gift_id.toString() === settings.value.strengthData[1]) {
// 减强度1 // 减强度1
try { try {
addOrIncrease(1, 1, 1) addOrIncrease(1, 1, res.data.gift_num)
addOrIncrease(1, 2, 1) addOrIncrease(1, 2, res.data.gift_num)
notyf.success("收到" + res.data.gift_name + ",强度-1") notyf.success("收到" + res.data.gift_name + ",强度-" + res.data.gift_num)
} }
catch (e) { catch (e) {
console.log(e) console.log(e)
@ -117,8 +115,8 @@ function createSocket(authBody: string, wssLinks: string[]) {
} else if(settings && settings.value.waveData[res.data.gift_id]) { } else if(settings && settings.value.waveData[res.data.gift_id]) {
// 其他礼物,发送波形数据 // 其他礼物,发送波形数据
try { try {
sendWaveData(5, 5, settings.value.waveData[res.data.gift_id], settings.value.waveData[res.data.gift_id]) sendWaveData(5 * res.data.gift_num, 5 * res.data.gift_num, settings.value.waveData[res.data.gift_id], settings.value.waveData[res.data.gift_id])
notyf.success("收到礼物" + res.data.gift_name) notyf.success("收到礼物" + res.data.gift_name + "*"+res.data.gift_num)
} }
catch (e) { catch (e) {
console.log(e) console.log(e)