content/hifi-content/brosche/StudioFurniture/physButton.js
2022-02-13 21:50:01 +01:00

89 lines
No EOL
3.1 KiB
JavaScript

// physButton.js
(function(){
var _this;
var ringID;
var ringAction = null;
var buttonAction = null;
var RADIUS = 10000;
var position;
var pressDepth;
var physButton = function() {
_this = this;
};
physButton.prototype = {
preload: function(entityID) {
_this.entityID = entityID;
_this.getButtonData();
ringAction = Entities.addAction("slider", _this.entityID, {
axis: { x: 0, y: 1, z: 0 },
linearLow: 0,
linearHigh: 0
});
Entities.editEntity(ringID, {locked: true});
buttonAction = Entities.addAction("slider", _this.entityID, {
axis: { x: 0, y: 1, z: 0 },
otherEntityID: ringID,
otherPoint: { x: 0, y: -pressDepth, z: 0 },
otherAxis: { x: 0, y: 1, z: 0 },
linearLow: -pressDepth,
linearHigh: 0
});
},
getButtonData: function() {
buttonProperties = Entities.getEntityProperties(_this.entityID, ["position", "userData"]);
if (!buttonProperties.userData || buttonProperties.userData === "{}") {
print("Button ", _this.entityID, " is missing user data.");
//Script.clearInterval(intervalID);
return;
}
try {
ringID = Entities.findEntitiesByName("Visual_Object_Mark_button-ring", buttonProperties.position, radius);
buttonUserData = JSON.parse(buttonProperties.userData);
soundURL = SoundCache.getSound(buttonUserData.soundURL);
pressDepth = buttonUserData.pressDepth;
soundVolume = !isNaN(buttonUserData.soundVolume) ? buttonUserData.soundVolume : 0.0;
soundLocal = buttonUserData.isLocal ? buttonUserData.isLocal : false;
// verify that settings are legit
} catch (e) {
print("Error in retrieving physButton Data");
return;
}
},
playSound: function() {
if (injector) {
injector.stop();
}
if (soundURL && soundURL.downloaded) {
injector = Audio.playSound(soundURL, {
position: soundPosition,
volume: soundVolume,
loop: soundLoop,
localOnly: soundLocal
});
} else {
print("soundURL not downloaded!");
return;
}
},
enterEntity: function(){
_this.playSound();
},
unload: function(){
Entities.deleteAction(ringID,ringAction);
Entities.deleteAction(_this.entityID, buttonAction);
}
// var switchBaseID = Entities.findEntitiesByName("Visual_Object_Mark_scram-base", worldOriginPos, radius);
// console.log("HELLOOOOOOO ",switchBaseID);
};
return new physButton;
});