From a7ed9b9a2cd397fa0fcc7baaf43937b6209d5a12 Mon Sep 17 00:00:00 2001 From: Alezia Kurdis <60075796+AleziaKurdis@users.noreply.github.com> Date: Wed, 2 Feb 2022 22:23:58 -0500 Subject: [PATCH] Add Odometer application Add Odometer application --- applications/metadata.js | 9 +++ applications/odometer/appicon_a.png | Bin 0 -> 1580 bytes applications/odometer/appicon_i.png | Bin 0 -> 1248 bytes applications/odometer/odometer.js | 100 ++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 applications/odometer/appicon_a.png create mode 100644 applications/odometer/appicon_i.png create mode 100644 applications/odometer/odometer.js diff --git a/applications/metadata.js b/applications/metadata.js index a320728..0911b61 100644 --- a/applications/metadata.js +++ b/applications/metadata.js @@ -107,6 +107,15 @@ var metadata = { "applications": "jsfile": "blocks/Blocks.js", "icon": "blocks/blocks-inactive.svg", "caption": "BLOCKS" + }, + { + "isActive": true, + "directory": "odometer", + "name": "Odometer", + "description": "Tool to record the distance traveled by your avatar.", + "jsfile": "odometer/odometer.js", + "icon": "odometer/appicon_i.png", + "caption": "ODOMETER" } ] }; diff --git a/applications/odometer/appicon_a.png b/applications/odometer/appicon_a.png new file mode 100644 index 0000000000000000000000000000000000000000..b1193a8685b18d1bc08c09824c01cba093c9c400 GIT binary patch literal 1580 zcmV+{2GjY8P)z@;j(q!3lK=n!AY({UO#lFTB>(_`g8%^e{{R4h=>PzA zFaQARU;qF*m;eA5Z<1fdMgRZ>qDe$SRCwBA{Qv(y!*Boq0mOpLVPs?s1yX51d=H2# zfS!C06mtQxjggei0*Mo${ymUC3&<~r>RS!ON@!+*z*#I}@1e9Hn%Ev74n-CN*#Tkz z1P}u#Mxe0*vgAJ!o(UEIk3$@n`f@0LH=2GIBspY^O>8$5ql>vXm?eB|4-kkmncx0tne7u;{ITMmJ2X0+ytZqTCpddbmfR7#o-c z)d$mC0ZpDT^Hw9Nt-vA%N@AVJ$qyiaSkQb1N^_mSkVJPZERBOK>wtej}Ack zL5|u3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K2M3`T?A+DdTqDV7|hhDm6-(!{z`^(s10 zolbK+h&#UU#k)HL_f z7`uRYwH?JPs#{}^KDfmScL%@rixi>jOAZXU1=Z?t7#jluF^cP;d5ySeq$z z(|RWmvF4N-m)KD2r3tx)b^iMouQwXLNGwIC){&pf{f6E&g`H*|^Br>I6}F{Yrzk(ca~;4(${>IPkVe<8JKXRf2!Z5poXUE+IpP~WBk)_JwjvHzCoyOYsHv^G1*qf7P4 qs!hfrZ)sF)qHme~*WZ6s{$C>rx>ezrSr*a=0FauLk$5RyWB3QNz2rIo literal 0 HcmV?d00001 diff --git a/applications/odometer/odometer.js b/applications/odometer/odometer.js new file mode 100644 index 0000000..85457fe --- /dev/null +++ b/applications/odometer/odometer.js @@ -0,0 +1,100 @@ +"use strict"; +// +// odometer.js +// +// Created by Alezia Kurdis, October 11th, 2021. +// Copyright 2021 Alezia Kurdis. +// Copyright 2022 Overte e.V. +// +// Tool to record the distance traveled by the avatar. +// +// 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 jsMainFileName = "odometer.js"; + var ROOT = Script.resolvePath('').split(jsMainFileName)[0]; + var APP_NAME = "ODOMETER"; + var APP_ICON_INACTIVE = ROOT + "appicon_i.png"; + var APP_ICON_ACTIVE = ROOT + "appicon_a.png"; + + var isRecording = false; + var distance = 0; + var lastPosition = {}; + + var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + var button = tablet.addButton({ + text: APP_NAME, + icon: APP_ICON_INACTIVE, + activeIcon: APP_ICON_ACTIVE + }); + + function clicked(){ + + if (isRecording === false) { + //Start Recoding + lastPosition = MyAvatar.position; + distance = 0; + Script.update.connect(myTimer); + + //button + button.editProperties({ + "isActive": true, + "text": APP_NAME + }); + + isRecording = true; + } else { + //on Stop Recoding + Script.update.disconnect(myTimer); + var computedDistance, distanceInUnit; + //prepart to display distance in km 2 digit + if (distance < 1000) { + if (distance < 100) { + distanceInUnit = distance.toFixed(1); + } else { + distanceInUnit = Math.round(distance); + } + computedDistance = distanceInUnit + " m"; + } else { + distanceInUnit = distance/1000; + if (distanceInUnit < 100) { + distanceInUnit = distanceInUnit.toFixed(1); + } else { + distanceInUnit = Math.round(distanceInUnit); + } + computedDistance = distanceInUnit + " km"; + } + //button + button.editProperties({ + "isActive": false, + "text": computedDistance + }); + + isRecording = false; + } + } + + button.clicked.connect(clicked); + + function myTimer(deltaTime) { + var avatarPos = MyAvatar.position; + var dist = Vec3.distance(avatarPos, lastPosition ); + distance = distance + dist; + lastPosition = avatarPos; + } + + function cleanup() { + button.clicked.disconnect(clicked); + tablet.removeButton(button); + if (isRecording) { + Script.update.disconnect(myTimer); + } + Script.scriptEnding.disconnect(cleanup); + } + + Script.scriptEnding.connect(cleanup); + +}());