This commit is contained in:
choelzl 2022-02-23 20:41:12 +01:00
parent c6461ddda9
commit b51d1eb1d2
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
2 changed files with 42 additions and 25 deletions

View File

@ -40,7 +40,7 @@
message = event.getMessage(); message = event.getMessage();
tags = event.getTags(); tags = event.getTags();
if(message.indexOf('!')!=0) if(message.indexOf('!')!=0)
sendData('bounce',event.getTags().get('emotes'), getNoTwitchEmotes(event,message).split(/\s+/)) sendData('bounce',event.getTags().get('emotes').split('/'), getNoTwitchEmotes(event,message).split(/\s+/))
}) })
$.bind('command', function(event) { $.bind('command', function(event) {
@ -53,15 +53,15 @@
if (!action) { if (!action) {
$.say($.whisperPrefix(sender) + $.lang.get('ew.help', ' Use "!ew [rain | firework | volcano | bomb | explosion] emote" to render emotes.')); $.say($.whisperPrefix(sender) + $.lang.get('ew.help', ' Use "!ew [rain | firework | volcano | bomb | explosion] emote" to render emotes.'));
} else if (action.equalsIgnoreCase('rain')) { } else if (action.equalsIgnoreCase('rain')) {
sendData('rain',event.getTags().get('emotes'), getNoTwitchEmotes(event,event.getMessage())) sendData('rain',event.getTags().get('emotes').split('/'), getNoTwitchEmotes(event,event.getMessage()).split(/\s+/))
} else if (action.equalsIgnoreCase('firework')) { } else if (action.equalsIgnoreCase('firework')) {
sendData('firework',event.getTags().get('emotes'), getNoTwitchEmotes(event,event.getMessage())) sendData('firework',event.getTags().get('emotes').split('/'), getNoTwitchEmotes(event,event.getMessage()).split(/\s+/))
} else if (action.equalsIgnoreCase('volcano')) { } else if (action.equalsIgnoreCase('volcano')) {
sendData('volcano',event.getTags().get('emotes'), getNoTwitchEmotes(event,event.getMessage())) sendData('volcano',event.getTags().get('emotes').split('/'), getNoTwitchEmotes(event,event.getMessage()).split(/\s+/))
} else if (action.equalsIgnoreCase('bomb')) { } else if (action.equalsIgnoreCase('bomb')) {
sendData('bomb',event.getTags().get('emotes'), getNoTwitchEmotes(event,event.getMessage())) sendData('bomb',event.getTags().get('emotes').split('/'), getNoTwitchEmotes(event,event.getMessage()).split(/\s+/))
} else if (action.equalsIgnoreCase('explosion')) { } else if (action.equalsIgnoreCase('explosion')) {
sendData('explosion',event.getTags().get('emotes'), getNoTwitchEmotes(event,event.getMessage())) sendData('explosion',event.getTags().get('emotes').split('/'), getNoTwitchEmotes(event,event.getMessage()).split(/\s+/))
} else { } else {
$.say($.whisperPrefix(sender) + $.lang.get('ew.help', ' Use "!ew [rain | firework | volcano | bomb | explosion] emote" to render emotes.')); $.say($.whisperPrefix(sender) + $.lang.get('ew.help', ' Use "!ew [rain | firework | volcano | bomb | explosion] emote" to render emotes.'));
} }
@ -77,7 +77,7 @@
}); });
$.bind('initReady', function() { $.bind('initReady', function() {
$.registerChatCommand('./custom/custom/customOverlay.js', 'ew'); $.registerChatCommand('./custom/custom/customEmoteWall.js', 'ew');
$.registerChatSubcommand('ew', 'rain', 2); $.registerChatSubcommand('ew', 'rain', 2);
$.registerChatSubcommand('ew', 'firework', 2); $.registerChatSubcommand('ew', 'firework', 2);
$.registerChatSubcommand('ew', 'volcano', 2); $.registerChatSubcommand('ew', 'volcano', 2);

View File

@ -62,8 +62,13 @@ const canvasSizing = (cnv) => {
resizeCanvas(); resizeCanvas();
} }
function waitFor(conditionFunction) {
const poll = resolve => {
if(conditionFunction()) resolve();
else setTimeout(_ => poll(resolve), 400);
}
return new Promise(poll);
}
@ -95,6 +100,23 @@ $(async function () {
return loadedimages; return loadedimages;
} }
const loadImagesTwitch = async(emotesId) => {
let loadcount = 0, loadtotal = emotesId.length;
let localPreloaded = false;
for (let i=0; i<emotesId.length; i++) {
var image = new Image();
image.onload = function () {
loadcount++;
if (loadcount == loadtotal) localPreloaded = true;
};
image.src = "https://static-cdn.jtvnw.net/emoticons/v2/" + emotesId[i] + "/default/dark/2.0";
img_map[emotesId[i]] = image;
}
await waitFor(_ => localPreloaded === true);
return true;
}
const randEmote = (set) => { const randEmote = (set) => {
if(!Array.isArray(set)) if(!Array.isArray(set))
set = Object.keys(img_map) || [] set = Object.keys(img_map) || []
@ -299,21 +321,6 @@ $(async function () {
}, 100); }, 100);
} }
async function init() {
main(0);
sleep(1000).then(()=>{
createParticule(BounceGP, randEmote(), {}, {})
createParticule(BounceP, randEmote(), {}, {})
createParticule(BounceP, randEmote(), {}, {})
createParticule(BombP, randEmote(), {}, {})
createParticule(FireworkP, randEmote(), {}, {})
genRain();
genVolcano();
})
}
function main(tframe) { function main(tframe) {
window.requestAnimationFrame(main); window.requestAnimationFrame(main);
@ -329,7 +336,17 @@ $(async function () {
} }
} }
init() main(0);
const handleEmoteData = (d) =>{
let te = d.twitch, ce = d.custom.filter(e=> img_map[e]);
if(!te || te.length == 0){
return ce;
}else{
let cleanTE = te.map(e => e.split(":")[0]);
return ce.concat(loadImagesTwitch(cleanTE))
}
}
const handleSocketMessage = (e)=>{ const handleSocketMessage = (e)=>{
try { try {