/* globals WELCOME_WAGON_OPTIONS */ var VERSION = 1.02; // TODO: replace with http://content.highfidelity.com once stable. var WELCOME_WAGON_FOLDER = 'http://hifi-content.s3.amazonaws.com/DomainContent/production/welcomeWagon/'; // TODO: get this from the domain itself through the API (might need to expose it) // depends on https://github.com/highfidelity/hifi/pull/10764 , which will give us location.domainId var DOMAIN_ID = WELCOME_WAGON_OPTIONS.DOMAIN_ID !== undefined ? WELCOME_WAGON_OPTIONS.DOMAIN_ID : 'fb6aa924-29e3-476a-808b-a1ffd8c16b97'; var ROTATING_DOMAIN = WELCOME_WAGON_OPTIONS.ROTATING_DOMAIN !== undefined ? WELCOME_WAGON_OPTIONS.ROTATING_DOMAIN : 'WelcomeWagon'; var SEARCH_CENTER = WELCOME_WAGON_OPTIONS.SEARCH_CENTER !== undefined ? WELCOME_WAGON_OPTIONS.SEARCH_CENTER : {x: 19.2, y: 0.1, z: -135.6}; var SEARCH_AREA = WELCOME_WAGON_OPTIONS.SEARCH_AREA !== undefined ? WELCOME_WAGON_OPTIONS.SEARCH_AREA : 60000; // search area (sphere) in meters radius var DISPLAY_NAME = WELCOME_WAGON_OPTIONS.DISPLAY_NAME !== undefined ? WELCOME_WAGON_OPTIONS.DISPLAY_NAME : 'WelcomeWagon [BOT]'; var ACTIVE_WELCOME_WAGON_JSON = WELCOME_WAGON_OPTIONS.ACTIVE_WELCOME_WAGON_JSON !== undefined ? WELCOME_WAGON_OPTIONS.ACTIVE_WELCOME_WAGON_JSON : WELCOME_WAGON_FOLDER + 'ww-wagonPad-complete.json'; var DISABLED_WELCOME_WAGON_JSON = WELCOME_WAGON_OPTIONS.DISABLED_WELCOME_WAGON_JSON !== undefined ? WELCOME_WAGON_OPTIONS.DISABLED_WELCOME_WAGON_JSON : WELCOME_WAGON_FOLDER + 'ww-wagonPad-ghost.json'; var PLATFORM_NAME = WELCOME_WAGON_OPTIONS.PLATFORM_NAME !== undefined ? WELCOME_WAGON_OPTIONS.PLATFORM_NAME : 'ww-landingPad'; var WELCOME_WAGON_CHANNEL = WELCOME_WAGON_OPTIONS.WELCOME_WAGON_CHANNEL !== undefined ? WELCOME_WAGON_OPTIONS.WELCOME_WAGON_CHANNEL : 'com.highfidelity.welcomeWagon'; var MODULES_PATH = WELCOME_WAGON_OPTIONS.MODULES_PATH !== undefined ? WELCOME_WAGON_OPTIONS.MODULES_PATH : WELCOME_WAGON_FOLDER + 'modules/'; var request = Script.require(MODULES_PATH + 'request.js').request; var _entityImport = Script.require(MODULES_PATH + 'entityImport.js'); var welcomeWagonEntities = []; var welcomeWagonEnabled = false; var NOT_FOUND_INDEX = -1; function removeLockedEntity(entityID) { Entities.editEntity(entityID, {locked: false}); Entities.deleteEntity(entityID); } function checkDomainASync() { request('https://metaverse.highfidelity.com/api/v1/places/' + ROTATING_DOMAIN, function (error, data) { if (error === false) { var rotatingDomainID = data.data.place.root !== undefined ? data.data.place.root.domain.id : data.data.place.domain.id; var hasMatchingDomainID = Uuid.isEqual(DOMAIN_ID, rotatingDomainID); if (welcomeWagonEntities.length === 0 || welcomeWagonEnabled !== hasMatchingDomainID) { welcomeWagonEnabled = hasMatchingDomainID; var platformEntityID = null; Entities.findEntities(SEARCH_CENTER, SEARCH_AREA).forEach(function(entityID) { if (Entities.getEntityProperties(entityID, 'name').name === PLATFORM_NAME) { platformEntityID = entityID; } }); if (platformEntityID === null) { print('couldn\'t find platform'); return; } var platformProperties = Entities.getEntityProperties(platformEntityID, ['position', 'rotation']); var importJSON = welcomeWagonEnabled ? ACTIVE_WELCOME_WAGON_JSON : DISABLED_WELCOME_WAGON_JSON; var entityTree = _entityImport.importEntitiesJSON(importJSON, { position: platformProperties.position, rotation: platformProperties.rotation }, { locked: true }, { parentID: platformEntityID }); /*var platformIndex = NOT_FOUND_INDEX; entityTree.childEntities.forEach(function(childEntity, index) { if (childEntity.name === PLATFORM_NAME) { platformIndex = index; } });*/ // if (platformIndex === NOT_FOUND_INDEX) { // print('Platform not found in JSON.'); // return; // } // TODO: first delete welcomeWagonEntities Entities.findEntities(SEARCH_CENTER, SEARCH_AREA).forEach(function(entityID) { var properties = Entities.getEntityProperties(entityID, 'parentID'); if (properties.parentID === platformEntityID) { removeLockedEntity(entityID); } }); /*var platFormEntity = entityTree.childEntities[platformIndex]; if (platFormEntity.childEntities.length > 0) { print('Found child entities on the platform, these will not be imported.'); }*/ //entityTree.childEntities.splice(platformIndex, 1); /*entityTree.childEntities.forEach(function(childEntity, index) { childEntity.rotation = Quat.multiply(childEntity.rotation, Quat.inverse(platFormEntity.rotation)); childEntity.position = Vec3.multiplyQbyV(Quat.inverse(platFormEntity.rotation), Vec3.subtract(childEntity.position, platFormEntity.position)); });*/ welcomeWagonEntities = _entityImport.createEntitiesFromTree([ entityTree ])[0].childEntities; } } else { // TODO: Do nothing here for now, could be a metaverse bug (make require display the exact error, which is available in the data) print("[ERROR] Something went wrong with the request: " + error + " / data: " + JSON.stringify(data)); } }); } print('WelcomeWagonAC.js version: ' + VERSION); // Assignment Client related code: if (Script.isAgentScript()) { Agent.isAvatar = true; Avatar.skeletonModelURL = 'http://hifi-content.s3.amazonaws.com/ozan/dev/avatars/invisible_avatar/invisible_avatar.fst'; Avatar.displayName = DISPLAY_NAME; var initialized = false; var update = function(deltaTime) { if (!initialized) { if (Entities.serversExist() && Entities.canRez()) { Entities.setPacketsPerSecond(60000); EntityViewer.setPosition(SEARCH_CENTER); EntityViewer.setCenterRadius(SEARCH_AREA); // This should allow us to see nano-scale entities from great distances EntityViewer.setVoxelSizeScale(Number.MAX_VALUE); Script.setInterval(function() { EntityViewer.queryOctree(); }, 1000); initialized = true; Script.setInterval(checkDomainASync, 3000); Script.update.disconnect(update); } return; } }; AvatarList.avatarAddedEvent.connect(function(avatarID) { if (avatarID === Agent.sessionUUID) { print('Skipping own session UUID ' + avatarID); return; } print('Requesting ' + avatarID); // Test var IDENTITY_PACKETS_TIMEOUT = 1000; Script.setTimeout(function() { Users.requestUsernameFromID(avatarID); }, IDENTITY_PACKETS_TIMEOUT); }); Users.usernameFromIDReply.connect(function(id, username, machineFingerprint, isAdmin) { if (!isAdmin) { // Users.ignore(id, true); print(username + " {" + id + "} is NOT supposed to see me."); } else { print(username + " {" + id + "} is supposed to see me."); } }); Script.update.connect(update); }