mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 01:16:35 +02:00
Add sending and receiving items.
This commit is contained in:
parent
f1ff399225
commit
7e414d47c7
4 changed files with 87 additions and 22 deletions
|
@ -17,6 +17,7 @@
|
||||||
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@4.x/css/materialdesignicons.min.css" rel="stylesheet">
|
||||||
<!-- <link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet"> -->
|
<!-- <link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet"> -->
|
||||||
<link href="./styles/vuetify.css" rel="stylesheet">
|
<link href="./styles/vuetify.css" rel="stylesheet">
|
||||||
|
<link href="./styles/styles.css" rel="stylesheet">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -446,7 +447,7 @@
|
||||||
color="blue"
|
color="blue"
|
||||||
class="px-3"
|
class="px-3"
|
||||||
:disabled="!shareDialog.valid"
|
:disabled="!shareDialog.valid"
|
||||||
@click="shareDialog.show = false; shareItem();"
|
@click="shareDialog.show = false; shareItem(shareDialog.data.url);"
|
||||||
>
|
>
|
||||||
Send
|
Send
|
||||||
</v-btn>
|
</v-btn>
|
||||||
|
@ -477,8 +478,9 @@ EventBridge.scriptEventReceived.connect(function(receivedCommand) {
|
||||||
vue_this.receiveInventory(receivedCommand.data);
|
vue_this.receiveInventory(receivedCommand.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (receivedCommand.command == 'script-to-web-item-offer') {
|
if (receivedCommand.command == 'script-to-web-receiving-item') {
|
||||||
alert("RECEIVING ITEM OFFER:" + JSON.stringify(receivedCommand.data));
|
// alert("RECEIVING ITEM OFFER:" + JSON.stringify(receivedCommand.data));
|
||||||
|
vue_this.receivingItem(receivedCommand.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (receivedCommand.command == 'script-to-web-nearby-users') {
|
if (receivedCommand.command == 'script-to-web-nearby-users') {
|
||||||
|
@ -647,6 +649,28 @@ new Vue({
|
||||||
|
|
||||||
return detectedItemType;
|
return detectedItemType;
|
||||||
},
|
},
|
||||||
|
checkItemType: function(itemType) {
|
||||||
|
var detectedItemType = null;
|
||||||
|
|
||||||
|
switch (itemType) {
|
||||||
|
case "model":
|
||||||
|
detectedItemType = "model";
|
||||||
|
break;
|
||||||
|
case "avatar":
|
||||||
|
detectedItemType = "avatar";
|
||||||
|
break;
|
||||||
|
case "script":
|
||||||
|
detectedItemType = "script";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (detectedItemType == null) {
|
||||||
|
// This is not a known item type...
|
||||||
|
detectedItemType = "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
return detectedItemType;
|
||||||
|
}
|
||||||
addItem: function(name, url) {
|
addItem: function(name, url) {
|
||||||
var extensionRegex = /\.[0-9a-z]+$/i; // to detect the file type based on extension in the URL.
|
var extensionRegex = /\.[0-9a-z]+$/i; // to detect the file type based on extension in the URL.
|
||||||
var detectedFileType = url.match(extensionRegex);
|
var detectedFileType = url.match(extensionRegex);
|
||||||
|
@ -688,17 +712,30 @@ new Vue({
|
||||||
},
|
},
|
||||||
receivingItem: function(data) {
|
receivingItem: function(data) {
|
||||||
if (this.receiveDialog.show != true) { // Do not accept offers if the user is already receiving an offer.
|
if (this.receiveDialog.show != true) { // Do not accept offers if the user is already receiving an offer.
|
||||||
this.receiveDialog.data.user = data.user;
|
this.receiveDialog.data.user = data.data.user;
|
||||||
this.receiveDialog.data.type = data.type;
|
this.receiveDialog.data.type = data.data.type;
|
||||||
this.receiveDialog.data.name = data.name;
|
this.receiveDialog.data.name = data.data.name;
|
||||||
this.receiveDialog.data.url = data.url;
|
this.receiveDialog.data.url = data.data.url;
|
||||||
|
|
||||||
this.receiveDialog.show = true;
|
this.receiveDialog.show = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
shareItem: function() {
|
shareItem: function(url) {
|
||||||
|
var typeToShare;
|
||||||
|
var nameToShare;
|
||||||
|
|
||||||
|
for (i = 0; i < this.items.length; i++) {
|
||||||
|
if (this.items[i].url == url) {
|
||||||
|
typeToShare = this.items[i].type;
|
||||||
|
nameToShare = this.items[i].name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// alert("type" + typeToShare + "name" + nameToShare);
|
||||||
this.sendAppMessage("share-item", {
|
this.sendAppMessage("share-item", {
|
||||||
|
"type": typeToShare,
|
||||||
|
"name": nameToShare,
|
||||||
"url": this.shareDialog.data.url,
|
"url": this.shareDialog.data.url,
|
||||||
"recipient": this.shareDialog.data.recipient,
|
"recipient": this.shareDialog.data.recipient,
|
||||||
});
|
});
|
||||||
|
@ -706,11 +743,10 @@ new Vue({
|
||||||
acceptItem: function() {
|
acceptItem: function() {
|
||||||
var itemToPush =
|
var itemToPush =
|
||||||
{
|
{
|
||||||
"type": this.checkFileType(this.receiveDialog.data.type),
|
"type": this.checkItemType(this.receiveDialog.data.type),
|
||||||
"name": this.receiveDialog.data.name,
|
"name": this.receiveDialog.data.name,
|
||||||
"url": this.receiveDialog.data.url,
|
"url": this.receiveDialog.data.url,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.items.push(itemToPush);
|
this.items.push(itemToPush);
|
||||||
},
|
},
|
||||||
useItem: function(type, url) {
|
useItem: function(type, url) {
|
||||||
|
|
|
@ -63,6 +63,11 @@ var inventoryMessagesChannel = "com.vircadia.inventory";
|
||||||
function onMessageReceived(channel, message, sender, localOnly) {
|
function onMessageReceived(channel, message, sender, localOnly) {
|
||||||
if (channel == inventoryMessagesChannel) {
|
if (channel == inventoryMessagesChannel) {
|
||||||
var messageJSON = JSON.parse(message);
|
var messageJSON = JSON.parse(message);
|
||||||
|
// Window.alert("Passed 0 " + messageJSON.recipient + " vs " + MyAvatar.sessionUUID);
|
||||||
|
if (messageJSON.command == "share-item" && messageJSON.recipient == MyAvatar.sessionUUID) { // We are receiving an item.
|
||||||
|
// Window.alert("Passed 1 " + messageJSON.recipient + " vs " + MyAvatar.sessionUUID);
|
||||||
|
receivingItem(sender, messageJSON.type, messageJSON.name, messageJSON.url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
print("Message received:");
|
print("Message received:");
|
||||||
print("- channel: " + channel);
|
print("- channel: " + channel);
|
||||||
|
@ -71,6 +76,10 @@ function onMessageReceived(channel, message, sender, localOnly) {
|
||||||
print("- localOnly: " + localOnly);
|
print("- localOnly: " + localOnly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendMessage(dataToSend) {
|
||||||
|
Messages.sendMessage(inventoryMessagesChannel, JSON.stringify(dataToSend));
|
||||||
|
}
|
||||||
|
|
||||||
// END APP EVENT AND MESSAGING ROUTING
|
// END APP EVENT AND MESSAGING ROUTING
|
||||||
|
|
||||||
// SEND AND RECEIVE INVENTORY STATE
|
// SEND AND RECEIVE INVENTORY STATE
|
||||||
|
@ -94,25 +103,30 @@ function loadInventory() {
|
||||||
inventoryData = Settings.getValue(inventoryDataSettingString);
|
inventoryData = Settings.getValue(inventoryDataSettingString);
|
||||||
}
|
}
|
||||||
|
|
||||||
function receivingItem(data) {
|
function receivingItem(sender, type, name, url) {
|
||||||
|
var packageRequest = {
|
||||||
|
"sender": sender,
|
||||||
|
"data": {
|
||||||
|
"type": type,
|
||||||
|
"name": name,
|
||||||
|
"url": url
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function shareItem(data) {
|
sendToWeb("script-to-web-receiving-item", packageRequest);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendNearbyUsers() {
|
function sendNearbyUsers() {
|
||||||
var nearbyUsers = AvatarList.getAvatarsInRange(Vec3.ZERO, 25); // Find all users within 25m.
|
var nearbyUsers = AvatarList.getAvatarsInRange(MyAvatar.position, 25); // Find all users within 25m.
|
||||||
var nearbyUsersToSend = [];
|
var nearbyUsersToSend = [];
|
||||||
|
|
||||||
nearbyUsers.forEach(function(user, i) {
|
nearbyUsers.forEach(function(user, i) {
|
||||||
var objectToWrite;
|
var objectToWrite;
|
||||||
var aviName = AvatarList.getAvatar(user).displayName;
|
var aviName = AvatarList.getAvatar(user).displayName;
|
||||||
|
// Window.alert("aviName" + aviName + "user" + user + "MyAvatar.sessionUUID" + MyAvatar.sessionUUID);
|
||||||
if (aviName != MyAvatar.displayName) {
|
if (user != MyAvatar.sessionUUID) { // Don't add ourselves to the list!
|
||||||
objectToWrite = { "name": aviName, "uuid": user };
|
objectToWrite = { "name": aviName, "uuid": user };
|
||||||
nearbyUsersToSend.push = objectToWrite;
|
nearbyUsersToSend.push(objectToWrite);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -141,6 +155,16 @@ function useItem(item) {
|
||||||
if (item.type == "avatar") {
|
if (item.type == "avatar") {
|
||||||
MyAvatar.useFullAvatarURL(item.url);
|
MyAvatar.useFullAvatarURL(item.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (item.type == "unknown") {
|
||||||
|
// We don't know how to handle this yet.
|
||||||
|
Window.alert("Unknown item type, unable to use.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function shareItem(data) {
|
||||||
|
data.command = "share-item";
|
||||||
|
sendMessage(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeInventoryApp() {
|
function initializeInventoryApp() {
|
||||||
|
@ -159,6 +183,9 @@ function startup() {
|
||||||
|
|
||||||
loadInventory();
|
loadInventory();
|
||||||
|
|
||||||
|
Messages.messageReceived.connect(onMessageReceived);
|
||||||
|
Messages.subscribe(inventoryMessagesChannel);
|
||||||
|
|
||||||
ui = new AppUi({
|
ui = new AppUi({
|
||||||
buttonName: "TOPSECRET",
|
buttonName: "TOPSECRET",
|
||||||
home: Script.resolvePath("inventory.html"),
|
home: Script.resolvePath("inventory.html"),
|
||||||
|
@ -170,8 +197,8 @@ function startup() {
|
||||||
startup();
|
startup();
|
||||||
|
|
||||||
Script.scriptEnding.connect(function () {
|
Script.scriptEnding.connect(function () {
|
||||||
// Messages.messageReceived.disconnect(onMessageReceived);
|
Messages.messageReceived.disconnect(onMessageReceived);
|
||||||
// Messages.unsubscribe(inventoryMessagesChannel);
|
Messages.unsubscribe(inventoryMessagesChannel);
|
||||||
});
|
});
|
||||||
|
|
||||||
}()); // END LOCAL_SCOPE
|
}()); // END LOCAL_SCOPE
|
1
scripts/system/inventory/styles/styles.css
Normal file
1
scripts/system/inventory/styles/styles.css
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/* .inventoryApp::-webkit-scrollbar { width: 0 !important } */
|
1
scripts/system/inventory/styles/vuetify.css.map
Normal file
1
scripts/system/inventory/styles/vuetify.css.map
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue