Event bridge + use item functionality enabled.

This commit is contained in:
Kasen IO 2020-04-04 04:45:02 -04:00
parent 118ccbdbe5
commit c0df50de3c
2 changed files with 74 additions and 13 deletions

View file

@ -95,7 +95,7 @@
<v-list color="grey darken-3">
<v-list-item
@click="useItem(item.url)"
@click="useItem(item.type, item.url)"
>
<v-list-item-title>Use</v-list-item-title>
<v-list-item-action>
@ -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: {

View file

@ -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,