Adding sit and love emotes

This commit is contained in:
Alexia Mandeville 2018-06-26 14:21:10 -07:00
parent 4948ad425e
commit 92acbdbbd7
10 changed files with 51 additions and 47 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

View file

@ -16,7 +16,7 @@
(function() { // BEGIN LOCAL_SCOPE (function() { // BEGIN LOCAL_SCOPE
var EMOTE_ANIMATIONS = ['Cry', 'Surprised', 'Dance', 'Cheer', 'Wave', 'Fall', 'Point', 'Clap', 'Sit1', 'Sit2', 'Sit3', 'Love']; var EMOTE_ANIMATIONS = ['Crying', 'Surprised', 'Dancing', 'Cheering', 'Waving', 'Fall', 'Pointing', 'Clapping', 'Sit1', 'Sit2', 'Sit3', 'Love'];
var ANIMATIONS = Array(); var ANIMATIONS = Array();
var eventMappingName = "io.highfidelity.away"; // restoreAnimation on hand controller button events, too var eventMappingName = "io.highfidelity.away"; // restoreAnimation on hand controller button events, too
@ -36,6 +36,7 @@ var EMOTE_LABEL = "EMOTE";
var EMOTE_APP_SORT_ORDER = 12; var EMOTE_APP_SORT_ORDER = 12;
var FPS = 60; var FPS = 60;
var MSEC_PER_SEC = 1000; var MSEC_PER_SEC = 1000;
var FINISHED = 3; // see ScriptableResource::State
var onEmoteScreen = false; var onEmoteScreen = false;
var button; var button;
@ -73,63 +74,62 @@ function onWebEventReceived(event) {
if (event.type === "click") { if (event.type === "click") {
// Allow for a random sitting animation when a user selects sit
var randSit = Math.floor(Math.random() * 3) + 1;
var emoteName = event.data; var emoteName = event.data;
if (activeTimer !== false) { if (emoteName === "Sit"){
Script.clearTimeout(activeTimer); emoteName = event.data + randSit; // "Sit1, Sit2, Sit3"
} }
// If the activeEmote is different from the chosen emote, then play the new emote. Other wise, if (ANIMATIONS[emoteName].resource.state == FINISHED) {
// This is a second click on the same emote as the activeEmote, and we will just stop it.
if (activeEmote !== emoteName) {
activeEmote = emoteName;
// Allow for a random sitting animation when a user selects sit if (activeTimer !== false) {
var randSit = Math.floor(Math.random() * 3) + 1; Script.clearTimeout(activeTimer);
if (emoteName === "Sit"){
emoteName = event.data + randSit; // "Sit1, Sit2, Sit3"
} }
var frameCount = ANIMATIONS[emoteName].animation.frames.length; // If the activeEmote is different from the chosen emote, then play the new emote. Other wise,
// This is a second click on the same emote as the activeEmote, and we will just stop it.
// Three types of emotes (non-looping end, non-looping return, looping) if (activeEmote !== emoteName) {
if (emoteName.match(/^Sit.*$/) || emoteName === "Fall") { // non-looping end activeEmote = emoteName;
MyAvatar.overrideAnimation(ANIMATIONS[emoteName].url, FPS, false, 0, frameCount);
// Non-looping return
} else if (emoteName === "Love" || emoteName === "Surprised" || emoteName === "Cry" || emoteName === "Point"){
MyAvatar.overrideAnimation(ANIMATIONS[emoteName].url, FPS, false, 0, frameCount);
var timeOut = MSEC_PER_SEC * frameCount / FPS;
activeTimer = Script.setTimeout(function () {
MyAvatar.restoreAnimation();
activeTimer = false;
activeEmote = false;
}, timeOut);
} else { // Looping
// Sit is the only animation currently that plays and then ends at the last frame
MyAvatar.overrideAnimation(ANIMATIONS[emoteName].url, FPS, true, 0, frameCount); if (emoteName.match(/^Sit.*$/)) {
} Controller.keyPressEvent.connect(restoreAnimation);
MyAvatar.overrideAnimation(ANIMATIONS[emoteName].url, FPS, false, 0, frameCount);
} else {
activeEmote = false; } else {
MyAvatar.restoreAnimation();
} activeEmote = emoteName;
var frameCount = ANIMATIONS[emoteName].animation.frames.length;
MyAvatar.overrideAnimation(ANIMATIONS[emoteName].url, FPS, false, 0, frameCount);
var timeOut = MSEC_PER_SEC * frameCount / FPS;
activeTimer = Script.setTimeout(function () {
MyAvatar.restoreAnimation();
activeTimer = false;
activeEmote = false;
}, timeOut);
}
} else {
activeEmote = false;
MyAvatar.restoreAnimation();
}
}
} }
} }
// If a user provides input, end the emote animation and restore the navigation animation states (idle, walk, run) // If a user provides input, end the emote animation and restore the navigation animation states (idle, walk, run)
function restoreAnimation() { function restoreAnimation() {
MyAvatar.restoreAnimation(); MyAvatar.restoreAnimation();
Controller.keyPressEvent.disconnect(restoreAnimation);
} }
Controller.keyPressEvent.connect(restoreAnimation);
// Note peek() so as to not interfere with other mappings. // Note peek() so as to not interfere with other mappings.
eventMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(restoreAnimation); eventMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(restoreAnimation);
eventMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(restoreAnimation); eventMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(restoreAnimation);
@ -137,6 +137,10 @@ eventMapping.from(Controller.Standard.LeftSecondaryThumb).peek().to(restoreAnima
eventMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(restoreAnimation); eventMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(restoreAnimation);
eventMapping.from(Controller.Standard.LB).peek().to(restoreAnimation); eventMapping.from(Controller.Standard.LB).peek().to(restoreAnimation);
eventMapping.from(Controller.Standard.LS).peek().to(restoreAnimation); eventMapping.from(Controller.Standard.LS).peek().to(restoreAnimation);
eventMapping.from(Controller.Standard.RY).peek().to(restoreAnimation);
eventMapping.from(Controller.Standard.RX).peek().to(restoreAnimation);
eventMapping.from(Controller.Standard.LY).peek().to(restoreAnimation);
eventMapping.from(Controller.Standard.LX).peek().to(restoreAnimation);
eventMapping.from(Controller.Standard.LeftGrip).peek().to(restoreAnimation); eventMapping.from(Controller.Standard.LeftGrip).peek().to(restoreAnimation);
eventMapping.from(Controller.Standard.RB).peek().to(restoreAnimation); eventMapping.from(Controller.Standard.RB).peek().to(restoreAnimation);
eventMapping.from(Controller.Standard.RS).peek().to(restoreAnimation); eventMapping.from(Controller.Standard.RS).peek().to(restoreAnimation);

View file

@ -98,14 +98,14 @@
</div> </div>
<div class="content"> <div class="content">
<p>Choose an emote:<p> <p>Choose an emote:<p>
<p><input type="button" class="emote-button white" value="Cry"> <p><input type="button" class="emote-button white" value="Crying">
<input type="button" class="emote-button white" value="Surprised"></p> <input type="button" class="emote-button white" value="Surprised"></p>
<p><input type="button" class="emote-button white" value="Dance"> <p><input type="button" class="emote-button white" value="Dancing">
<input type="button" class="emote-button white" value="Cheer"></p> <input type="button" class="emote-button white" value="Cheering"></p>
<p><input type="button" class="emote-button white" value="Wave"> <p><input type="button" class="emote-button white" value="Waving">
<input type="button" class="emote-button white" value="Fall"></p> <input type="button" class="emote-button white" value="Fall"></p>
<p><input type="button" class="emote-button white" value="Point"> <p><input type="button" class="emote-button white" value="Pointing">
<input type="button" class="emote-button white" value="Clap"></p> <input type="button" class="emote-button white" value="Clapping"></p>
<p><input type="button" class="emote-button white" value="Sit"> <p><input type="button" class="emote-button white" value="Sit">
<input type="button" class="emote-button white" value="Love"></p> <input type="button" class="emote-button white" value="Love"></p>
</div> </div>