"use strict"; // // diamond_dave.js // tablet-sample-app // // Created by Ryan Karpf on Oct 25th 201. // Copyright 2017 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // (function() { // Every great app starts with a great name (keep it short so that it can fit in the tablet button) var APP_NAME = "Diamond D"; // Link to your app's HTML file var APP_URL = "http://hifi-content.s3.amazonaws.com/ryan/diamond_dave.html?001"; // Path to the icon art for your app var APP_ICON = "http://hifi-content.s3.amazonaws.com/ryan/DLR.svg"; // -----------------ADD THE REST OF YOUR SOUNDS HERE---------------------------- var YEAH = SoundCache.getSound(Script.resolvePath('Yeeeeah.mp3')); var UUH = SoundCache.getSound(Script.resolvePath('Uhhhggghhh.mp3')); var OOH = SoundCache.getSound(Script.resolvePath('Ooohhhh.mp3')); var OOHYEAH = SoundCache.getSound(Script.resolvePath('Ohhh yessss.mp3')); var AAHAA = SoundCache.getSound(Script.resolvePath('Aaahaaahhhh.mp3')); var AHAYEAH = SoundCache.getSound(Script.resolvePath('Awww Yeahhhh.mp3')); // Get a reference to the tablet var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var injector; // "Install" your cool new app to the tablet // The following lines create a button on the tablet's menu screen var button = tablet.addButton({ icon: APP_ICON, text: APP_NAME }); // When user click the app button, we'll display our app on the tablet screen function onClicked() { tablet.gotoWebScreen(APP_URL); } button.clicked.connect(onClicked); // Handle the events we're recieving from the web UI function onWebEventReceived(event) { print("diamond_dave.js received a web event:" + event); // Converts the event to a JavasScript Object if (typeof event === "string") { print("CAPTAIN...I HAVE THE WEB EVENT"); event = JSON.parse(event); switch (event.type) { case 'yeah' : playSound(YEAH, 0.4); break; case 'uuh' : playSound(UUH, 0.4); break; case 'ooh' : playSound(OOH, 0.4); break; case 'oohYeah': playSound(OOHYEAH, 0.4); break; case 'aahaa': playSound(AAHAA, 0.4); break; case 'ahayeah': playSound(AHAYEAH, 0.4); break; default: print("error in detecting event.type"); } } } tablet.webEventReceived.connect(onWebEventReceived); // Provide a way to "uninstall" the app // Here, we write a function called "cleanup" which gets executed when // this script stops running. It'll remove the app button from the tablet. function cleanup() { tablet.removeButton(button); } function playSound(sound, volume) { print("sound"); if (sound.downloaded) { if (injector) { injector.stop(); } injector = Audio.playSound(sound, { position: MyAvatar.position, volume: volume }); } } Script.scriptEnding.connect(cleanup); }());