diff --git a/scripts/system/inventory/inventory.html b/scripts/system/inventory/inventory.html
index faaad85479..8ca20be307 100644
--- a/scripts/system/inventory/inventory.html
+++ b/scripts/system/inventory/inventory.html
@@ -124,7 +124,7 @@
Remove
@@ -135,10 +135,8 @@
-
-
@@ -172,7 +170,7 @@
Yes
@@ -188,6 +186,17 @@
>
Add Item
+
+
+ Enter the name of the item.
+
+
+
Enter the URL of the item.
@@ -196,6 +205,8 @@
@@ -213,7 +224,7 @@
Add
@@ -285,42 +296,42 @@ new Vue({
{
"type": "script",
"name": "VRGrabScale",
- "url": "https://google.com/vr.js",
+ "url": "https://gooawefaweawfgle.com/vr.js",
},
{
"type": "script",
"name": "VRGrabScale",
- "url": "https://google.com/vr.js",
+ "url": "https://googfdafsgaergale.com/vr.js",
},
{
"type": "script",
"name": "TEST",
- "url": "https://google.com/vr.js",
+ "url": "https://gooadfdagle.com/vr.js",
},
{
"type": "script",
"name": "TESTLONGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
- "url": "https://google.com/vrLONGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG.js",
+ "url": "https://googfdaffle.com/vrLONGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG.js",
},
{
"type": "avatar",
"name": "AVI",
- "url": "https://google.com/vr.fst",
+ "url": "https://googlfadfe.com/vr.fst",
},
{
"type": "avatar",
"name": "AVI",
- "url": "https://google.com/vr.fst",
+ "url": "https://googlefdaf.com/vr.fst",
},
{
"type": "model",
"name": "3D MODEL",
- "url": "https://google.com/vr.fbx",
+ "url": "https://googlee.com/vr.fbx",
},
{
"type": "model",
"name": "3D MODEL",
- "url": "https://google.com/vr.fbx",
+ "url": "https://googleee.com/vr.fbx",
},
],
iconType: {
@@ -336,13 +347,21 @@ new Vue({
"icon": "mdi-account-convert",
"color": "purple",
},
+ "unknown": {
+ "icon": "mdi-help",
+ "color": "grey",
+ }
},
removeDialog: {
show: false,
- item: null,
+ url: null, // This is the item to remove since URL is the key.
},
addDialog: {
show: false,
+ data: {
+ "name": null,
+ "url": null,
+ },
},
receiveDialog: {
show: false,
@@ -358,13 +377,57 @@ new Vue({
created: function () {
vue_this = this;
this.$vuetify.theme.dark = this.darkTheme;
+
+ this.sendAppMessage("ready", "");
},
methods: {
- addItem: function(url) {
+ addItem: function(name, url) {
+ var extensionRegex = /\.[0-9a-z]+$/i; // to detect the file type based on extension in the URL.
+ var detectedFileType = url.match(extensionRegex);
+ var itemType;
+
+ if (detectedFileType == null || detectedFileType[0] == null) {
+ itemType = "unknown";
+ } else {
+ switch (detectedFileType[0]) {
+ // Model Cases
+ case ".fbx":
+ itemType = "model";
+ break;
+ case ".gltf":
+ itemType = "model";
+ break;
+ // Script Cases
+ case ".js":
+ itemType = "script";
+ break;
+ // Avatar Cases
+ case ".fst":
+ itemType = "avatar";
+ break;
+ }
+ }
+
+ if (itemType == null) {
+ // This is not a known item...
+ itemType = "unknown";
+ }
+ var itemToPush =
+ {
+ "type": itemType,
+ "name": name,
+ "url": url,
+ };
+
+ this.items.push(itemToPush);
},
removeItem: function(url) {
-
+ for (i = 0; i < this.items.length; i++) {
+ if (this.items[i].url == url) {
+ this.items.splice(i, 1);
+ }
+ }
},
renameItem: function(url) {
@@ -381,6 +444,12 @@ new Vue({
useItem: function(url) {
alert(url);
this.sendAppMessage("test", "testData");
+ },
+ sendInventory: function() {
+
+ },
+ receiveInventory: function() {
+
},
sendAppMessage: function(command, data) {
var JSONtoSend = {
@@ -388,6 +457,7 @@ new Vue({
"command": command,
"data": data
};
+
EventBridge.emitWebEvent(JSON.stringify(JSONtoSend));
},
displayIcon: function(itemType) {
diff --git a/scripts/system/inventory/inventory.js b/scripts/system/inventory/inventory.js
index 25129345be..59c12ed7b0 100644
--- a/scripts/system/inventory/inventory.js
+++ b/scripts/system/inventory/inventory.js
@@ -13,25 +13,72 @@ var AppUi = Script.require('appUi');
var ui;
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
-// APP EVENT ROUTING
+var inventoryDataSettingString = "inventoryApp.data";
+var inventoryData;
+
+// APP EVENT AND MESSAGING ROUTING
function onWebAppEventReceived(event) {
var eventJSON = JSON.parse(event);
if (eventJSON.app == "inventory") { // This is our web app!
- print("gemstoneApp.js received a web event: " + event);
+ print("inventory.js received a web event: " + event);
+
+ if (eventJSON.command == "ready") {
+ initializeInventoryApp();
+ }
+
+ if (eventJSON.command == "web-to-script-inventory") {
+ receiveInventory(eventJSON.data);
+ }
+
}
}
tablet.webEventReceived.connect(onWebAppEventReceived);
-// END APP EVENT ROUTING
+function sendToWeb(command, data) {
+ var dataToSend = {
+ "app": "inventory",
+ "command": command,
+ "data": data
+ }
+ tablet.emitScriptEvent(dataToSend);
+}
+
+// var inventoryMessagesChannel = "com.vircadia.inventory";
+
+// function onMessageReceived(channel, message, sender, localOnly) {
+// if (channel == inventoryMessagesChannel) {
+// var messageJSON = JSON.parse(message);
+// }
+// print("Message received:");
+// print("- channel: " + channel);
+// print("- message: " + message);
+// print("- sender: " + sender);
+// print("- localOnly: " + localOnly);
+// }
+
+// END APP EVENT AND MESSAGING ROUTING
+
+// SEND AND RECEIVE INVENTORY STATE
+
+function receiveInventory(receivedInventoryData) {
+ inventoryData = receivedInventoryData;
+ saveInventory();
+}
+
+function sendInventory() {
+ sendToWeb("script-to-web-inventory", inventoryData);
+}
+
+// END SEND AND RECEIVE INVENTORY STATE
function saveInventory() {
-
+ Settings.setValue(inventoryDataSettingString, inventoryData);
}
function loadInventory() {
-
+ inventoryData = Settings.getValue(inventoryDataSettingString);
}
function receivingItem() {
@@ -42,6 +89,10 @@ function shareItem() {
}
+function initializeInventoryApp() {
+ sendInventory();
+}
+
function onOpened() {
console.log("hello world!");
}
@@ -51,6 +102,9 @@ function onClosed() {
}
function startup() {
+
+ loadInventory();
+
ui = new AppUi({
buttonName: "INVENTORY",
home: Script.resolvePath("inventory.html"),
@@ -60,4 +114,10 @@ function startup() {
});
}
startup();
+
+Script.scriptEnding.connect(function () {
+ // Messages.messageReceived.disconnect(onMessageReceived);
+ // Messages.unsubscribe(inventoryMessagesChannel);
+});
+
}()); // END LOCAL_SCOPE
\ No newline at end of file