From 70a0d50edeabb9cf8ec099b100444a2d8c6a977a Mon Sep 17 00:00:00 2001 From: Kasen IO Date: Sat, 4 Apr 2020 20:27:21 -0400 Subject: [PATCH] Switch to UUID system. --- scripts/system/inventory/inventory.html | 73 +++++++++++++++---------- scripts/system/inventory/inventory.js | 2 +- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/scripts/system/inventory/inventory.html b/scripts/system/inventory/inventory.html index 34bbfeb72f..8024fb72b6 100644 --- a/scripts/system/inventory/inventory.html +++ b/scripts/system/inventory/inventory.html @@ -62,7 +62,7 @@ Share @@ -126,7 +126,7 @@ Remove @@ -173,7 +173,7 @@ Yes @@ -236,7 +236,7 @@ color="blue" class="px-3" :disabled="!editDialog.valid" - @click="editDialog.show = false; editItem(editDialog.url);" + @click="editDialog.show = false; editItem(editDialog.uuid);" > Done @@ -447,7 +447,7 @@ color="blue" class="px-3" :disabled="!shareDialog.valid" - @click="shareDialog.show = false; shareItem(shareDialog.data.url);" + @click="shareDialog.show = false; shareItem(shareDialog.data.uuid, shareDialog.data.url);" > Send @@ -558,7 +558,7 @@ new Vue({ // The URL is the key (to finding the item we want) so we want to keep track of that. removeDialog: { show: false, - url: null, + uuid: null, }, addDialog: { show: false, @@ -571,7 +571,7 @@ new Vue({ editDialog: { show: false, valid: false, - url: null, // This is the key, the URL in data is what will overwrite this key. + uuid: null, // data: { "type": null, "name": null, @@ -592,6 +592,7 @@ new Vue({ show: false, valid: false, data: { + "uuid": null, // UUID of the item you want to share. THIS IS THE KEY. "url": null, // The item you want to share. "recipient": null, } @@ -621,6 +622,31 @@ new Vue({ this.sendAppMessage("ready", ""); }, methods: { + createUUID: function() { + // http://www.ietf.org/rfc/rfc4122.txt + var s = []; + var hexDigits = "0123456789abcdef"; + for (var i = 0; i < 36; i++) { + s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); + } + s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010 + s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 + s[8] = s[13] = s[18] = s[23] = "-"; + + var uuid = s.join(""); + return uuid; + }, + pushToItems: function(type, name, url) { + var itemToPush = + { + "type": type, + "name": name, + "url": url, + "uuid": this.createUUID(), + }; + + this.items.push(itemToPush); + }, checkFileType: function(fileType) { var detectedItemType = null; @@ -682,28 +708,21 @@ new Vue({ itemType = this.checkFileType(detectedFileType[0]); } - var itemToPush = - { - "type": itemType, - "name": name, - "url": url, - }; - - this.items.push(itemToPush); + this.pushToItems(itemType, name, url); this.addDialog.data.name = null; this.addDialog.data.url = null; }, - removeItem: function(url) { + removeItem: function(uuid) { for (i = 0; i < this.items.length; i++) { - if (this.items[i].url == url) { + if (this.items[i].uuid == uuid) { this.items.splice(i, 1); } } }, - editItem: function(url) { + editItem: function(uuid) { for (i = 0; i < this.items.length; i++) { - if (this.items[i].url == url) { + if (this.items[i].uuid == uuid) { this.items[i].type = this.checkItemType(this.editDialog.data.type); this.items[i].name = this.editDialog.data.name; this.items[i].url = this.editDialog.data.url; @@ -721,12 +740,12 @@ new Vue({ } }, - shareItem: function(url) { + shareItem: function(uuid, url) { var typeToShare; var nameToShare; for (i = 0; i < this.items.length; i++) { - if (this.items[i].url == url) { + if (this.items[i].uuid == uuid) { typeToShare = this.items[i].type; nameToShare = this.items[i].name; } @@ -741,13 +760,7 @@ new Vue({ }); }, acceptItem: function() { - var itemToPush = - { - "type": this.checkItemType(this.receiveDialog.data.type), - "name": this.receiveDialog.data.name, - "url": this.receiveDialog.data.url, - }; - this.items.push(itemToPush); + this.pushToItems(this.checkItemType(this.receiveDialog.data.type), this.receiveDialog.data.name, this.receiveDialog.data.url); }, useItem: function(type, url) { this.sendAppMessage("use-item", { diff --git a/scripts/system/inventory/inventory.js b/scripts/system/inventory/inventory.js index 83948e42c2..6ceeb83f5c 100644 --- a/scripts/system/inventory/inventory.js +++ b/scripts/system/inventory/inventory.js @@ -187,7 +187,7 @@ function startup() { Messages.subscribe(inventoryMessagesChannel); ui = new AppUi({ - buttonName: "TOPSECRET", + buttonName: "INVENTORY", home: Script.resolvePath("inventory.html"), graphicsDirectory: Script.resolvePath("./"), // Where your button icons are located onOpened: onOpened,