content/hifi-content/liv/dev/emojis/CheckForLove.js
2022-02-14 02:04:11 +01:00

96 lines
No EOL
3.3 KiB
JavaScript

//
// CheckForLove.js
//
// Author: Liv Erickson
// Copyright 2017 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 FUNCTION_URL = "https://sendanentity.azurewebsites.net/api/HttpTriggerJS/";
var TEXT_DISPLAY_ENTITY_ID = "{67f692c0-068b-4da1-83d9-a636f3ab39d4}";
var previousHearts = 0;
var _this;
AzureFunctionObject = function () {
_this = this;
}
AzureFunctionObject.prototype = {
preload: function (entityID) {
_this.entityID = entityID;
Script.setInterval(_this.checkForHearts, 3000);
},
clickDownOnEntity: function () {
this.checkForHearts();
},
checkForHearts: function () {
var req = new XMLHttpRequest();
req.open("GET", FUNCTION_URL + "?user=" + Account.username);
req.onreadystatechange = function () {
if (req.readyState === 4) {
if (req.status === 200) {
var newHearts = req.response - previousHearts;
previousHearts = req.response;
var text = "You have: " + newHearts + " new hearts";
var property = { "text": text };
Entities.editEntity(TEXT_DISPLAY_ENTITY_ID, property);
if (newHearts > 0) {
Create3DEmoji();
}
} else {
print(req.status);
}
}
}
req.send("");
}
};
var Create3DEmoji = function () {
print("Creating emoji");
var emojiProperties = {
type: "Model",
modelURL: "https://hifi-content.s3.amazonaws.com/liv/3DModels/heart.fbx",
position: Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation)),
dimensions: { x: .25, y: .25, z: .25 },
dynamic: 1,
angularVelocity: { x: 0, y: 5, z: 0 },
angularDamping: 0,
velocity: { x: 0, y: 1, z: 0 },
gravity: { x: 0, y: 5, z: 0 },
linearDamping: 0,
lifetime: 4
}
return Entities.addEntity(emojiProperties);
}
var CreateHeartParticleEffect = function (count) {
var heartsProperties = {
type: "ParticleEffect",
isEmitting: true,
position: Entities.getEntityProperties(_this.entityID).position,
lifetime: count / 2,
"maxParticles": count,
"textures": "https://upload.wikimedia.org/wikipedia/commons/f/f1/Heart_coraz%C3%B3n.svg",
"emitRate": 2,
"lifespan": 0.5,
"accelerationSpread": "{x: 0.5, y:1, z:0.5}",
"emitAcceleration": "{x: -0.5, y:2.5, z:0.5}",
"particleRadius": 0.1,
"radiusStart": 0.1,
"radiusFinish": 0.1,
"alphaStart": 1,
"alpha": 1,
"alphaFinish": 1
};
return Entities.addEntity(heartsProperties);
}
return new AzureFunctionObject();
})