Skip to content

Commit

Permalink
cooldown fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jg committed May 25, 2017
1 parent ab3a817 commit 8f68d8a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 50 deletions.
77 changes: 39 additions & 38 deletions lib/interactive/control-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,46 @@ function controlRouter(mouseevent, mixerControls, mixerControl, gameJson, inputE
if(mouseevent == "mousedown"){
// Mouse Down event called.

// Loop through effects for this button.
for (var item in effects){
var effect = effects[item];
var effectType = effect.type;

// For each effect, send it off to the appropriate handler.
switch(effectType){
case "API Button":
apiHandler.go(effect);
break;
case "Change Group":
changeGroupHandler.go(participant, effect)
break;
case "Chat":
chatHandler.send(effect, participant);
break;
case "Cooldown":
cdHandler.go(mixerControls, mixerControl, effect)
break;
case "Celebration":
celebration.play(effect);
break;
case "Game Control":
controlHandler.press('mousedown', effect, control);
break;
case "Play Sound":
media.play(effect);
break;
case "Show Image":
media.show(effect);
break;
default:
renderWindow.webContents.send('error', "Oops! This effect type doesnt exist: "+effectType);
console.log('Oops! This effect type doesnt exist: '+effectType);
// Cooldown Button or Buttons
cooldown.router(mixerControls, mixerControl, firebot, control, function(response){

// Loop through effects for this button.
for (var item in effects){
var effect = effects[item];
var effectType = effect.type;

// For each effect, send it off to the appropriate handler.
switch(effectType){
case "API Button":
apiHandler.go(effect);
break;
case "Change Group":
changeGroupHandler.go(participant, effect)
break;
case "Chat":
chatHandler.send(effect, participant);
break;
case "Cooldown":
cdHandler.go(mixerControls, mixerControl, effect)
break;
case "Celebration":
celebration.play(effect);
break;
case "Game Control":
controlHandler.press('mousedown', effect, control);
break;
case "Play Sound":
media.play(effect);
break;
case "Show Image":
media.show(effect);
break;
default:
renderWindow.webContents.send('error', "Oops! This effect type doesnt exist: "+effectType);
console.log('Oops! This effect type doesnt exist: '+effectType);
}
}
}
}) // end cooldown function
} else {
// Mouse up event called.

Expand All @@ -84,9 +88,6 @@ function controlRouter(mouseevent, mixerControls, mixerControl, gameJson, inputE
// Throw this information into the moderation panel.
renderWindow.webContents.send('eventlog', {username: participant.username, event: "pressed the "+controlID+" button."});

// Cooldown Button or Buttons
cooldown.router(mixerControls, mixerControl, firebot, control);

// Charge sparks for the button that was pressed.
if (inputEvent.transactionID) {
// This will charge the user.
Expand Down
19 changes: 9 additions & 10 deletions lib/interactive/cooldowns.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const JsonDB = require('node-json-db');

// Cooldown Router
function cooldownRouter(mixerControls, mixerControl, firebot, control){
function cooldownRouter(mixerControls, mixerControl, firebot, control, callback){
var cooldown = control.cooldown;
var groupName = control.cooldownGroup;

Expand All @@ -10,8 +10,10 @@ function cooldownRouter(mixerControls, mixerControl, firebot, control){
var groupsJson = firebot.cooldownGroups[groupName];
var buttons = groupsJson.buttons;
var cooldown = parseInt( groupsJson['length'] ) * 1000;

// For each button in the cooldown group...
console.log(groupsJson);
console.log(buttons);
groupCooldown(buttons, cooldown, mixerControls)
} else {
// Button doesn't have a cooldown group, so let's just cool down this one button.
Expand All @@ -22,27 +24,24 @@ function cooldownRouter(mixerControls, mixerControl, firebot, control){
mixerControl.setCooldown(cooldown);
}
}

// Callback
callback('finished');
}

// Group Cooldown
// Buttons should be an array of controlIDs that should be cooled down.
function groupCooldown(buttons, cooldown, mixerControls){

var buttonArray = buttons;

for (var i = buttonArray.length - 1; i >= 0; i--) {
var button = buttonArray[i];
// Loop through and find button to cool down.
for(button of buttons){
for (mixerControl of mixerControls){
var controlID = mixerControl.controlID;

// This is a matching control! Send cooldown.
if (button == controlID){
console.log(button, controlID);
console.log('-------'+controlID+' is cooling down. --------')
mixerControl.setCooldown(cooldown);

// Remove from array.
buttonArray.splice(i, 1);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/interactive/mixer-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ function makeScene(sceneName){
});
control.on('move', (inputEvent, participant) => {
// Send control on to the control router.
console.log('JOYSTICK MOVING!', inputEvent)
joystick.go(inputEvent);
});
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Firebot",
"version": "3.0.0-beta.1",
"version": "3.0.0-beta.2",
"description": "An application for mixer.com that celebrates and promotes interactive controls.",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 8f68d8a

Please sign in to comment.