From c0df50de3c0a0594bd84214c9a4c3e1157817a2f Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Sat, 4 Apr 2020 04:45:02 -0400 Subject: [PATCH] Event bridge + use item functionality enabled. --- scripts/system/inventory/inventory.html | 46 ++++++++++++++++++++----- scripts/system/inventory/inventory.js | 41 +++++++++++++++++++--- 2 files changed, 74 insertions(+), 13 deletions(-) diff --git a/scripts/system/inventory/inventory.html b/scripts/system/inventory/inventory.html index b865a7cd22..551c282890 100644 --- a/scripts/system/inventory/inventory.html +++ b/scripts/system/inventory/inventory.html @@ -95,7 +95,7 @@ Use @@ -467,6 +467,25 @@ var vue_this; +EventBridge.scriptEventReceived.connect(function(receivedCommand) { + receivedCommand = JSON.parse(receivedCommand); + // alert("RECEIVED COMMAND:" + receivedCommand.command) + if (receivedCommand.app == "inventory") { + // We route the data based on the command given. + if (receivedCommand.command == 'script-to-web-inventory') { + alert("INVENTORY RECEIVED ON APP:" + JSON.stringify(receivedCommand.data)); + vue_this.receiveInventory(receivedCommand.data); + } + + if (receivedCommand.command == 'script-to-web-item-offer') { + alert("RECEIVING ITEM OFFER:" + JSON.stringify(receivedCommand.data)); + } + + if (receivedCommand.command == 'script-to-web-nearby-users') { + alert("RECEIVING NEARBY USERS:" + JSON.stringify(receivedCommand.data)); + } + } +}); new Vue({ el: '#inventoryApp', @@ -692,15 +711,21 @@ new Vue({ this.items.push(itemToPush); }, - useItem: function(url) { - alert(url); - this.sendAppMessage("test", "testData"); + useItem: function(type, url) { + this.sendAppMessage("use-item", { + "type": type, + "url": url + }); }, sendInventory: function() { - alert("SAVING INVENTORY."); + this.sendAppMessage("web-to-script-inventory", this.items ); }, - receiveInventory: function() { - + receiveInventory: function(receivedInventory) { + if (!receivedInventory) { + this.items = []; + } else { + this.items = receivedInventory; + } }, displayIcon: function(itemType) { return this.iconType[itemType].icon; @@ -708,6 +733,9 @@ new Vue({ getIconColor: function(itemType) { return this.iconType[itemType].color; }, + receiveNearbyUsers: function(receivedUsers) { + this.nearbyUsers = receivedUsers; + }, sendAppMessage: function(command, data) { var JSONtoSend = { "app": "inventory", @@ -715,8 +743,8 @@ new Vue({ "data": data }; - alert(JSON.stringify(JSONtoSend)); - // EventBridge.emitWebEvent(JSON.stringify(JSONtoSend)); + // alert(JSON.stringify(JSONtoSend)); + EventBridge.emitWebEvent(JSON.stringify(JSONtoSend)); }, }, watch: { diff --git a/scripts/system/inventory/inventory.js b/scripts/system/inventory/inventory.js index 59c12ed7b0..3ef17c2298 100644 --- a/scripts/system/inventory/inventory.js +++ b/scripts/system/inventory/inventory.js @@ -31,6 +31,14 @@ function onWebAppEventReceived(event) { receiveInventory(eventJSON.data); } + if (eventJSON.command == "use-item") { + useItem(eventJSON.data); + } + + if (eventJSON.command == "share-item") { + shareItem(eventJSON.data); + } + } } @@ -42,7 +50,8 @@ function sendToWeb(command, data) { "command": command, "data": data } - tablet.emitScriptEvent(dataToSend); + + tablet.emitScriptEvent(JSON.stringify(dataToSend)); } // var inventoryMessagesChannel = "com.vircadia.inventory"; @@ -81,14 +90,38 @@ function loadInventory() { inventoryData = Settings.getValue(inventoryDataSettingString); } -function receivingItem() { +function receivingItem(data) { } -function shareItem() { +function shareItem(data) { } +function useItem(item) { + + //TODO: Add animation support for avatars, add JSON loading...? + + // Depending on the type, we decide how to load this item. + if (item.type == "script") { + ScriptDiscoveryService.loadScript(item.url, true, false, false, true, false); // See SDS.loadScript in APIDocs for more. + } + + if (item.type == "model") { + var entityID = Entities.addEntity({ + type: "Model", + position: Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -3 })), + rotation: MyAvatar.orientation, + modelURL: item.url, + collisionless: true, + }); + } + + if (item.type == "avatar") { + MyAvatar.useFullAvatarURL(item.url); + } +} + function initializeInventoryApp() { sendInventory(); } @@ -106,7 +139,7 @@ function startup() { loadInventory(); ui = new AppUi({ - buttonName: "INVENTORY", + buttonName: "TOPSECRET", home: Script.resolvePath("inventory.html"), graphicsDirectory: Script.resolvePath("./"), // Where your button icons are located onOpened: onOpened,