content/hifi-content/Experiences/LoadTest/RonaldoManager/ronaldoManager.js
2022-02-13 23:16:46 +01:00

134 lines
4.4 KiB
JavaScript

//
// ronaldoManager.js
// A tablet app for managing playable zombie locations
//
// Author: Elisa Lupin-Jimenez
// Copyright High Fidelity 2018
//
// Based on http://hifi-content.s3-us-west-1.amazonaws.com/DomainContent/Zombies/ZombieManager/zombieStageManager.js
//
// 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/
//
(function () {
var APP_NAME = "RONALDO";
var APP_URL = Script.resolvePath("./ronaldoManager.html?v3");
var APP_ICON = Script.resolvePath("./ronaldo-i.svg");
var APP_ICON_ACTIVE = Script.resolvePath("./ronaldo-a.svg");
var appWindowOpen = false;
var previousAvatarURL;
var previousDisplayName;
var previousAttachments;
var setPrevious = false;
var RONALDO_AVATAR_URL = "https://hifi-content.s3.amazonaws.com/jimi/avatar/Mannequin/ronaldo.fst";
var LOCATIONS = {
// walkable
1: "/-39.1299,-6.4843,10.1354/0,-0.838319,0,0.54518", // Overlooking the portals
2: "/-3.33722,-11.2928,-41.1697/0,0.999946,0,0.0104057", // Behind storage boxes
3: "/3.85048,-5.21772,-1.51455/0,0.993151,0,0.116836", // On a beam behind the countdown billboard
// accessible flying
4: "/-4.39545,7.93822,17.5512/0,0.209125,0,0.977889", // On the portals dome roof
5: "/-13.2396,1.94204,-37.1776/0,-0.0749746,0,0.997185", // On the pink ring tower roof
6: "/-55.9753,35.5184,4.94709/0,-0.709221,0,0.704986" // Flying high above in traffic
}
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var button = tablet.addButton({
icon: APP_ICON,
activeIcon: APP_ICON_ACTIVE,
text: APP_NAME
});
function onClicked() {
tablet.gotoWebScreen(APP_URL);
}
button.clicked.connect(onClicked);
function onScreenChanged(type, url) {
// if url === app_url
if (type === 'Web') {
button.editProperties({ isActive: true });
appWindowOpen = true;
} else {
button.editProperties({ isActive: false });
appWindowOpen = false;
}
}
tablet.screenChanged.connect(onScreenChanged);
// need to load json in as variable and get location from that
function onWebEventReceived(event) {
if (appWindowOpen) {
try {
var eventJSON = JSON.parse(event);
} catch (e) {
console.error("Issue parsing event in ronaldoManager: ", e);
}
var button = eventJSON.button;
if (button === "avatar") {
if (eventJSON.data === "ronaldo") {
if (!setPrevious) {
previousAvatarURL = MyAvatar.skeletonModelURL;
previousDisplayName = MyAvatar.displayName;
previousAttachments = MyAvatar.getAttachmentData();
MyAvatar.setAttachmentData([]);
}
MyAvatar.skeletonModelURL = RONALDO_AVATAR_URL;
MyAvatar.displayName = "anonymous";
setPrevious = true;
} else if (eventJSON.data === "previous" && setPrevious) {
MyAvatar.skeletonModelURL = previousAvatarURL;
MyAvatar.displayName = previousDisplayName;
MyAvatar.setAttachmentData(previousAttachments);
setPrevious = false;
} else {
// do nothing
}
}
if (button === "location") {
var number = eventJSON.data;
Window.location.handleLookupString(LOCATIONS[number]);
}
}
}
tablet.webEventReceived.connect(onWebEventReceived);
function cleanup() {
if(setPrevious) {
MyAvatar.skeletonModelURL = previousAvatarURL;
MyAvatar.displayName = previousDisplayName;
MyAvatar.setAttachmentData(previousAttachments);
}
tablet.webEventReceived.disconnect(onWebEventReceived);
tablet.removeButton(button);
}
Script.scriptEnding.connect(cleanup);
}());