mirror of
https://github.com/overte-org/overte.git
synced 2025-04-07 06:52:32 +02:00
Emoji tablet app
This commit is contained in:
parent
a4123e3024
commit
bf35b08179
1 changed files with 80 additions and 0 deletions
80
unpublishedScripts/marketplace/emoji-tablet/emojiTablet.js
Normal file
80
unpublishedScripts/marketplace/emoji-tablet/emojiTablet.js
Normal file
|
@ -0,0 +1,80 @@
|
|||
///
|
||||
/// emojiTablet.js
|
||||
/// A tablet app for sending emojis to other users
|
||||
///
|
||||
/// Author: Elisa Lupin-Jimenez
|
||||
/// Copyright High Fidelity 2017
|
||||
///
|
||||
/// Licensed under the Apache 2.0 License
|
||||
/// See accompanying license file or http://apache.org/
|
||||
///
|
||||
/// All assets are under CC Attribution Non-Commerical
|
||||
/// http://creativecommons.org/licenses/
|
||||
///
|
||||
|
||||
// to avoid the caching block on updating JSONs
|
||||
var DEBUG = true;
|
||||
|
||||
if (DEBUG) {
|
||||
var lib = Script.require("https://hifi-content.s3.amazonaws.com/elisalj/emoji_scripts/emojiLib.js?" + Date.now());
|
||||
} else {
|
||||
var lib = Script.require("./emojiLib.js");
|
||||
}
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
var APP_NAME = "EMOJIS";
|
||||
var APP_URL = "https://hifi-content.s3.amazonaws.com/elisalj/emoji_scripts/emojiTabletUI.html?" + Date.now();
|
||||
var APP_ICON = null;
|
||||
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
||||
|
||||
var button = tablet.addButton({
|
||||
//icon: APP_ICON,
|
||||
text: APP_NAME
|
||||
});
|
||||
|
||||
// Activates tablet UI when selected from menu
|
||||
function onClicked() {
|
||||
tablet.gotoWebScreen(APP_URL);
|
||||
};
|
||||
button.clicked.connect(onClicked);
|
||||
|
||||
// Gives position right in front of user's avatar
|
||||
function getPositionToCreateEntity() {
|
||||
var direction = Quat.getFront(MyAvatar.orientation);
|
||||
var distance = 0.3;
|
||||
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(direction, distance));
|
||||
position.y += 0.5;
|
||||
return position;
|
||||
};
|
||||
|
||||
var emojiJSON = null;
|
||||
|
||||
// Handles emoji button clicks to retrieve the link to the emoji JSON from emojiLib
|
||||
function onWebEventReceived(event) {
|
||||
var emojiName = (JSON.parse(event)).data;
|
||||
var url = lib.getEmoji(emojiName, lib.emojiLib);
|
||||
if (url != null) {
|
||||
emojiJSON = Script.require(url);
|
||||
create3DEmoji(emojiJSON, null);
|
||||
} else {
|
||||
print("Unable to create emoji");
|
||||
}
|
||||
};
|
||||
tablet.webEventReceived.connect(onWebEventReceived);
|
||||
|
||||
function create3DEmoji(emojiJSON, userName) {
|
||||
print("Creating " + emojiJSON.name + " emoji");
|
||||
emojiJSON.position = getPositionToCreateEntity(emojiJSON.personified);
|
||||
var newEmoji = Entities.addEntity(emojiJSON);
|
||||
};
|
||||
|
||||
// When tablet UI is closed and app is removed from menu
|
||||
function cleanup() {
|
||||
tablet.removeButton(button);
|
||||
};
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
|
||||
}());
|
||||
|
Loading…
Reference in a new issue