content/hifi-content/robin/dev/domains/loadtest/Checkin/DomainEnter/checkinClient.js
2022-02-14 02:04:11 +01:00

173 lines
No EOL
5.5 KiB
JavaScript

// checkinClient.js
//
// Created by Robin Wilson on 2018-08-24
//
// Copyright 2018 High Fidelity, Inc.
//
// Entity client script used in tandem with checkinServer.js to search for username in a
// google sheet column and mark the user present.
//
// Overlay placement utilizes an entity called "Checkin Display Here". If placement entity can not
// be found the overlays default to the entity's position and MyAvatar.orientation.
//
// Add property to userData object:
// "checkinData": {
// "url": "",
// "on": true,
// },
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
/* global AccountServices Script */
(function () {
var PLACEMENT_ENTITY_NAME = "Checkin Display Here"; // not case sensitive
var Util = Script.require("https://hifi-content.s3.amazonaws.com/robin/dev/utils/Helper.js?v12347");
var OVERLAYS = {
USERNAME_OFFSET: {
x: 0.17,
y: 1,
z: 0.01
},
USERNAME_PROPERTIES: {
backgroundAlpha: 0,
lineHeight: 0.13,
dimensions: { x: 1.5, y: 0.1, z: 0.01 },
},
MODEL_URLS: {
CHECKED_IN: "https://hifi-content.s3.amazonaws.com/alan/dev/Check-In-Sign-Checked-In.fbx",
NOT_CHECKED_IN: "https://hifi-content.s3.amazonaws.com/alan/dev/Check-In-Sign-Line-Up.fbx",
LOGIN: "https://hifi-content.s3.amazonaws.com/alan/dev/Check-In-Sign-Log-In.fbx"
}
};
var overlayPosition;
var overlayRotation;
var SEARCH_RADIUS = 100;
function DomainCheckin() {
this.entityID;
this.overlay1; // Model
this.overlay2; // Username
}
DomainCheckin.prototype = {
remotelyCallable: [
"success",
"invalid"
],
preload: function (id) {
this.entityID = id;
var entityProperties = Util.Entity.getProps(this.entityID, ["position", "rotation"]);
var entityList = Entities.findEntitiesByName(
PLACEMENT_ENTITY_NAME,
entityProperties.position,
SEARCH_RADIUS
);
var placementProperties;
if (entityList.length > 0) {
placementProperties = Util.Entity.getProps(entityList[0], ["position", "rotation"]);
}
overlayPosition =
placementProperties && placementProperties.position
? placementProperties.position
: entityProperties.position;
overlayRotation =
placementProperties && placementProperties.rotation
? placementProperties.rotation
: entityProperties.rotation;
if (AccountServices.loggedIn) {
Entities.callEntityServerMethod(id, "hasUsername", [MyAvatar.sessionUUID, AccountServices.username, MyAvatar.displayName]);
} else {
// not logged in
AccountServices.loggedInChanged.connect(this.checkList);
this.displayOverlays("loggedout");
}
},
checkList: function () {
Entities.callEntityServerMethod(this.entityID, "hasUsername", [MyAvatar.sessionUUID, AccountServices.username]);
AccountServices.loggedInChanged.disconnect(this.checkList);
},
success: function (id, params) {
this.displayOverlays("onlist");
},
invalid: function (id, params) {
this.displayOverlays("invalid");
},
displayOverlays: function (overlayName) {
this.deleteOverlays();
var overlayModel = {
position: overlayPosition,
rotation: overlayRotation,
dimensions: {
x: 2.0208,
y: 0.8672,
z: 0.0013
}
};
var worldOffset = Vec3.multiplyQbyV(overlayRotation, OVERLAYS.USERNAME_OFFSET);
var worldPosition = Vec3.sum(overlayPosition, worldOffset);
var overlayUsername = {
position: worldPosition,
rotation: overlayRotation
};
overlayUsername = Util.Object.combineProperties(overlayUsername, OVERLAYS.USERNAME_PROPERTIES)
if (overlayName === "loggedout") {
overlayModel.url = OVERLAYS.MODEL_URLS.LOGIN;
overlayUsername.text = "???";
} else {
overlayModel.url = overlayName === "onlist"
? OVERLAYS.MODEL_URLS.CHECKED_IN
: OVERLAYS.MODEL_URLS.NOT_CHECKED_IN;
overlayUsername.text = AccountServices.username;
}
this.overlay1 = Overlays.addOverlay("model", overlayModel);
this.overlay2 = Overlays.addOverlay("text3d", overlayUsername);
},
deleteOverlays: function () {
if (this.overlay1) {
Overlays.deleteOverlay(this.overlay1);
this.overlay1 = null;
}
if (this.overlay2) {
Overlays.deleteOverlay(this.overlay2);
this.overlay2 = null;
}
},
unload: function () {
this.deleteOverlays();
}
};
return new DomainCheckin();
});