content/hifi-content/faye/plp/greenButtonEntityScript2.js
2022-02-13 23:26:00 +01:00

51 lines
1.7 KiB
JavaScript

// greenButtonEntityScript.js
//
// Created by Faye Li on November 3, 2016
//
(function() {
print("green button v0.35");
var _this;
var CLICK_SOUND_URL = "http://hifi-content.s3.amazonaws.com/caitlyn/production/gameTable/woodenTapClick.wav";
var myChannel = "MakeStation-Channel";
function GreenButton() {
_this = this;
}
GreenButton.prototype = {
entityID: null,
sound: null,
position: null,
preload: function(entityID) {
print('preload(' + entityID + ')');
_this.entityID = entityID;
_this.sound = SoundCache.getSound(CLICK_SOUND_URL);
var props = Entities.getEntityProperties(_this.entityID);
_this.position = props.position;
},
startNearTrigger: function(entityID) {
print('star near trigger');
_this.click();
},
clickDownOnEntity: function(entityID, mouseEvent) {
print('click down on entity');
_this.click();
},
click: function(){
// plays click sound as audio feedback
var props = Entities.getEntityProperties(_this.entityID);
var options = { position: props.position };
var injector = Audio.playSound(_this.sound,options);
// TODO: add visual feedback ie. animate a button click
var message = {
demoID: 2,
demoPosition: _this.position
};
message = JSON.stringify(message);
Messages.sendMessage(myChannel, message);
}
};
return new GreenButton();
});