content/hifi-content/Content/Scripted/ControlPad/launchPadButton.js
2022-02-13 22:31:32 +01:00

106 lines
No EOL
3.8 KiB
JavaScript

(function() {
var _this;
var _buttonName;
function launchPadButton() {
_this = this;
}
/*
[1_3] [1_2] [1_1] [1_0]
[2_3] [2_2] [2_1] [2_0]
[3_3] [3_2] [3_1] [3_0]
[4_3] [4_2] [4_1] [4_0]
These are the button names how they appear on the tablet.
With the parseButtonPresses() code below, put in any code you wish to
happen inside the if() checks relative to the button you want programmed.
Eg: [1_3] up above is top left, so I'd go to line 33 and add in my code.
*/
function parseButtonPresses() {
var sound = SoundCache.getSound("https://cain.sh/i/button-sound.wav");
Audio.playSound(sound);
if (_this.buttonName == "Launchpad_button_1_0") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_1_1") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_1_2") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_1_3") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_2_0") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_2_1") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_2_2") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_2_3") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_3_0") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_3_1") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_3_2") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_3_3") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_4_0") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_4_1") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_4_2") {
Script.include("//path//to//script.js");
}
if (_this.buttonName == "Launchpad_button_4_3") {
Script.include("//path//to//script.js");
}
}
function pressButtonEffect() {
var buttonEntity = _buttonName;
var entProp = Entities.getEntityProperties(_this.entityID);
entProp.color = { red: 120, green: 120, blue: 120 };
Entities.editEntity(_this.entityID, entProp);
Script.setTimeout(function() {
entProp.color = { red: 255, green: 255, blue: 255 };
Entities.editEntity(_this.entityID, entProp);
}, 500);
}
launchPadButton.prototype = {
isWaiting: false,
preload: function(entityID) {
_this.entityID = entityID;
_this.buttonName = Entities.getEntityProperties(entityID).name;
},
clickDownOnEntity: function(otherEntity) {
pressButtonEffect();
_this.hit(otherEntity);
},
hit: function(otherEntity) {
if (!_this.isWaiting) {
_this.isWaiting = true;
parseButtonPresses();
_this.isWaiting = false;
}
}
};
return new launchPadButton();
});