mirror of
https://github.com/overte-org/overte.git
synced 2025-07-24 10:23:43 +02:00
cleanup a few things in emote App
This commit is contained in:
parent
c4d0872bbf
commit
1dc24072dc
1 changed files with 19 additions and 26 deletions
|
@ -22,7 +22,6 @@ var ANIMATIONS = Array();
|
||||||
|
|
||||||
EMOTE_ANIMATIONS.forEach(function (name) {
|
EMOTE_ANIMATIONS.forEach(function (name) {
|
||||||
var animURL = Script.resolvePath("assets/animations/" + name + ".fbx");
|
var animURL = Script.resolvePath("assets/animations/" + name + ".fbx");
|
||||||
print(animURL);
|
|
||||||
var resource = AnimationCache.prefetch(animURL);
|
var resource = AnimationCache.prefetch(animURL);
|
||||||
var animation = AnimationCache.getAnimation(animURL);
|
var animation = AnimationCache.getAnimation(animURL);
|
||||||
ANIMATIONS[name] = { url: animURL, animation: animation, resource: resource};
|
ANIMATIONS[name] = { url: animURL, animation: animation, resource: resource};
|
||||||
|
@ -31,21 +30,23 @@ EMOTE_ANIMATIONS.forEach(function (name) {
|
||||||
|
|
||||||
var EMOTE_APP_BASE = "html/EmoteApp.html";
|
var EMOTE_APP_BASE = "html/EmoteApp.html";
|
||||||
var EMOTE_APP_URL = Script.resolvePath(EMOTE_APP_BASE);
|
var EMOTE_APP_URL = Script.resolvePath(EMOTE_APP_BASE);
|
||||||
|
var EMOTE_LABLE = "EMOTE";
|
||||||
|
var EMOTE_APP_SORT_ORDER = 11;
|
||||||
|
var FPS = 30;
|
||||||
|
var MSEC_PER_SEC = 1000;
|
||||||
|
var FINISHED = 3; // see ScriptableResource::State
|
||||||
|
|
||||||
var onEmoteScreen = false;
|
var onEmoteScreen = false;
|
||||||
var button;
|
var button;
|
||||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||||
|
var activeTimer = false; // used to cancel active timer if a user plays an amimation while another animation is playing
|
||||||
var emoteLable = "EMOTE";
|
|
||||||
|
|
||||||
button = tablet.addButton({
|
button = tablet.addButton({
|
||||||
//icon: "icons/tablet-icons/emote.svg",
|
//icon: "icons/tablet-icons/emote.svg", // TODO - we need graphics for this
|
||||||
text: emoteLable,
|
text: EMOTE_LABLE,
|
||||||
sortOrder: 11
|
sortOrder: EMOTE_APP_SORT_ORDER
|
||||||
});
|
});
|
||||||
|
|
||||||
var enabled = false;
|
|
||||||
function onClicked() {
|
function onClicked() {
|
||||||
if (onEmoteScreen) {
|
if (onEmoteScreen) {
|
||||||
tablet.gotoHomeScreen();
|
tablet.gotoHomeScreen();
|
||||||
|
@ -56,14 +57,12 @@ function onClicked() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onScreenChanged(type, url) {
|
function onScreenChanged(type, url) {
|
||||||
print("type:", type, "url:", url);
|
|
||||||
onEmoteScreen = type === "Web" && (url.indexOf(EMOTE_APP_BASE) == url.length - EMOTE_APP_BASE.length);
|
onEmoteScreen = type === "Web" && (url.indexOf(EMOTE_APP_BASE) == url.length - EMOTE_APP_BASE.length);
|
||||||
button.editProperties({ isActive: onEmoteScreen });
|
button.editProperties({ isActive: onEmoteScreen });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle the events we're receiving from the web UI
|
// Handle the events we're receiving from the web UI
|
||||||
function onWebEventReceived(event) {
|
function onWebEventReceived(event) {
|
||||||
print("emote.js received a web event: " + event);
|
|
||||||
|
|
||||||
// Converts the event to a JavasScript Object
|
// Converts the event to a JavasScript Object
|
||||||
if (typeof event === "string") {
|
if (typeof event === "string") {
|
||||||
|
@ -72,29 +71,20 @@ function onWebEventReceived(event) {
|
||||||
|
|
||||||
if (event.type === "click") {
|
if (event.type === "click") {
|
||||||
var emoteName = event.data;
|
var emoteName = event.data;
|
||||||
print("emote.js received a click event for " + emoteName);
|
|
||||||
|
|
||||||
print("ANIMATIONS[emoteName].resource.url:" + ANIMATIONS[emoteName].resource.url);
|
if (ANIMATIONS[emoteName].resource.state == FINISHED) {
|
||||||
|
if (activeTimer !== false) {
|
||||||
|
Script.clearTimeout(activeTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ANIMATIONS[emoteName].animation.isLoaded
|
|
||||||
if (ANIMATIONS[emoteName].resource.state == 3) {
|
|
||||||
var frameCount = ANIMATIONS[emoteName].animation.frames.length;
|
var frameCount = ANIMATIONS[emoteName].animation.frames.length;
|
||||||
print("the animation for " + emoteName + " is loaded, it has " + frameCount + " frames");
|
|
||||||
var frameCount = ANIMATIONS[emoteName].animation.frames.length;
|
|
||||||
|
|
||||||
var FPS = 30;
|
|
||||||
var MSEC_PER_SEC = 1000;
|
|
||||||
MyAvatar.overrideAnimation(ANIMATIONS[emoteName].url, FPS, false, 0, frameCount);
|
MyAvatar.overrideAnimation(ANIMATIONS[emoteName].url, FPS, false, 0, frameCount);
|
||||||
|
|
||||||
var timeOut = MSEC_PER_SEC * frameCount / FPS;
|
var timeOut = MSEC_PER_SEC * frameCount / FPS;
|
||||||
Script.setTimeout(function () {
|
activeTimer = Script.setTimeout(function () {
|
||||||
MyAvatar.restoreAnimation();
|
MyAvatar.restoreAnimation();
|
||||||
|
activeTimer = false;
|
||||||
}, timeOut);
|
}, timeOut);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
print("the animation for " + emoteName + " is in state:" + ANIMATIONS[emoteName].resource.state);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +93,6 @@ button.clicked.connect(onClicked);
|
||||||
tablet.screenChanged.connect(onScreenChanged);
|
tablet.screenChanged.connect(onScreenChanged);
|
||||||
tablet.webEventReceived.connect(onWebEventReceived);
|
tablet.webEventReceived.connect(onWebEventReceived);
|
||||||
|
|
||||||
|
|
||||||
Script.scriptEnding.connect(function () {
|
Script.scriptEnding.connect(function () {
|
||||||
if (onEmoteScreen) {
|
if (onEmoteScreen) {
|
||||||
tablet.gotoHomeScreen();
|
tablet.gotoHomeScreen();
|
||||||
|
@ -113,6 +102,10 @@ Script.scriptEnding.connect(function () {
|
||||||
if (tablet) {
|
if (tablet) {
|
||||||
tablet.removeButton(button);
|
tablet.removeButton(button);
|
||||||
}
|
}
|
||||||
|
if (activeTimer !== false) {
|
||||||
|
Script.clearTimeout(activeTimer);
|
||||||
|
MyAvatar.restoreAnimation();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue