diff --git a/applications/metadata.js b/applications/metadata.js index 255067b..1991ffe 100644 --- a/applications/metadata.js +++ b/applications/metadata.js @@ -61,6 +61,15 @@ var metadata = { "applications": [ "jsfile": "radar/radar.js", "icon": "radar/assets/radar-i.svg", "caption": "RADAR" - } + }, + { + "isActive": true, + "directory": "refresh-app", + "name": "Refresh App", + "description": "Add two buttons that refresh your avatar and attachments.", + "jsfile": "refresh-app/refreshApp.js", + "icon": "refresh-app/refresh-circle-w.png", + "caption": "REFRESH" + } ] }; \ No newline at end of file diff --git a/applications/refresh-app/refresh-circle-w.png b/applications/refresh-app/refresh-circle-w.png new file mode 100644 index 0000000..34b38b5 Binary files /dev/null and b/applications/refresh-app/refresh-circle-w.png differ diff --git a/applications/refresh-app/refreshApp.js b/applications/refresh-app/refreshApp.js new file mode 100644 index 0000000..5df357a --- /dev/null +++ b/applications/refresh-app/refreshApp.js @@ -0,0 +1,59 @@ +/* globals Vec3, Quat, Uuid, Camera, MyAvatar, Entities, Overlays, Script, Tablet, AvatarList, AvatarManager, Picks, PickType require ScriptDiscoveryService */ +// +// refreshApp.js +// +// Created by KasenVR on 30 May 2020. +// Copyright 2020 Vircadia contributors. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + var APP_NAME = "Refresh App"; + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + + var accountConvertIcon = 'data:image/svg+xml;utf8,'; + + var refreshIcon = 'data:image/svg+xml;utf8,'; + + var button = tablet.addButton({ + text: "REFRESH
AVATAR", + icon: accountConvertIcon, + }); + + var button1 = tablet.addButton({ + text: "REFRESH
ATTACH", + icon: refreshIcon, + }); + + Script.scriptEnding.connect(function(){ + tablet.removeButton(button); + tablet.removeButton(button1); + button = null; + button1 = null; + }); + + // + button.clicked.connect(refreshAvatar); + function refreshAvatar() { + var modelURL = MyAvatar.getFullAvatarURLFromPreferences(); + modelURL = modelURL.split("?")[0] + "?" + new Date().getTime(); + MyAvatar.useFullAvatarURL(modelURL); + console.info('Avatar refreshed!', modelURL); + } + + button1.clicked.connect(refreshAttachments); + function refreshAttachments() { + var data = MyAvatar.getAvatarEntityData(); // everything, including boxes which have no modelURL + + for (var id in data) { + var attachment = data[id]; + if (attachment.type.toString() === 'Model') { + attachment.modelURL = attachment.modelURL.toString().split('?')[0] + '?' + Date.now(); + // console.info('Attachment refreshed!', attachment.modelURL); + } + } + + MyAvatar.setAvatarEntityData(data); + } + \ No newline at end of file