content/hifi-content/liv/Production/avatarScaler.js
2022-02-14 02:04:11 +01:00

70 lines
No EOL
2 KiB
JavaScript

//
// sizeChanger.js
//
// created by Rebecca Stankus on 07/19/18
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
var _this;
var AUDIO_VOLUME_LEVEL = 1;
var CHANGE_SOUND = SoundCache.getSound("/sounds/change.wav");
var HOPI_SCALE = 0.65;
var originalScale;
var SizeChanger = function() {
_this = this;
};
SizeChanger.prototype = {
preload: function(entityID) {
_this.entityID = entityID;
},
playSound: function() {
if (CHANGE_SOUND.downloaded) {
Audio.playSound(CHANGE_SOUND, {
position: MyAvatar.position,
volume: AUDIO_VOLUME_LEVEL
});
}
},
clickReleaseOnEntity: function(entityID, mouseEvent) {
if (mouseEvent.isLeftButton) {
this.playSound();
if (MyAvatar.scale.toFixed(1) == HOPI_SCALE) {
if (originalScale) {
MyAvatar.scale = originalScale;
} else {
MyAvatar.scale = 1;
}
} else {
originalScale = MyAvatar.scale;
MyAvatar.scale = HOPI_SCALE;
}
}
},
stopFarTrigger: function() {
this.playSound();
if (MyAvatar.scale.toFixed(1) == HOPI_SCALE) {
if (originalScale) {
MyAvatar.scale = originalScale;
} else {
MyAvatar.scale = 1;
}
} else {
originalScale = MyAvatar.scale;
MyAvatar.scale = HOPI_SCALE;
}
}
};
return new SizeChanger();
});