Browse Source

add text with id on avatar, delete avatar node on leaving

Nikolay Suslov 7 years ago
parent
commit
d35da2c30f

+ 27 - 1
support/client/lib/vwf/model/aframe.js

@@ -155,6 +155,26 @@ define(["module", "vwf/model", "vwf/utility"], function (module, model, utility)
         //deletingNode: function( nodeID ) {
         //},
 
+        // -- deletingNode -------------------------------------------------------------------------
+
+        deletingNode: function( nodeID ) {
+
+            if ( this.state.nodes[ nodeID ] !== undefined ) {
+                
+                var node = this.state.nodes[ nodeID ];
+                if ( node.aframeObj !== undefined ) {
+                    // removes and destroys object
+                    node.aframeObj.parentNode.removeChild(node.aframeObj);
+                    node.aframeObj = undefined;    
+                }                
+
+                delete this.state.nodes[ nodeID ];
+            }
+            
+        },
+       
+       
+       
         // -- settingProperty ----------------------------------------------------------------------
 
         settingProperty: function (nodeID, propertyName, propertyValue) {
@@ -247,9 +267,12 @@ define(["module", "vwf/model", "vwf/utility"], function (module, model, utility)
                                         aframeObject.setAttribute('value', propertyValue);
                                         break;
 
-                                    case "color":
+                            case "color":
                                         aframeObject.setAttribute('color', propertyValue);
                                         break;
+                            case "side":
+                                        aframeObject.setAttribute('side', propertyValue);
+                                        break;
 
 
                         default:
@@ -579,6 +602,9 @@ define(["module", "vwf/model", "vwf/utility"], function (module, model, utility)
                                 case "color":
                                     value = aframeObject.getAttribute('color');
                                     break;
+                                case "side":
+                                    value = aframeObject.getAttribute('side');
+                                    break;
                                 }
                 }
 

+ 21 - 3
support/client/lib/vwf/view/aframe.js

@@ -107,20 +107,38 @@ define(["module", "vwf/view", "jquery", "jquery-ui"], function (module, view, $)
     });
 
     function createAvatar(nodeID) {
-        var nodeName = 'avatar-' + self.kernel.moniker();
+        let avatarID = self.kernel.moniker();
+        var nodeName = 'avatar-' + avatarID;
+
+        var nodeColor = getRandomColor();
 
         var newNode = {
             "id": nodeName,
             "uri": nodeName,
             "extends": "http://vwf.example.com/aframe/abox.vwf",
             "properties": {
-                "color": getRandomColor(),
+                "color": nodeColor,
                 "position": [0, 0, 0]
             },
             "methods": {
             },
-            "scripts": []
+            "scripts": [],
+            "children": {
+                "avatarNameNode": {
+                    "extends": "http://vwf.example.com/aframe/atext.vwf",
+                    "properties": {
+                        "color": nodeColor,
+                        "value": avatarID,
+                        "side": "double",
+                        "position": [0, 1, 0]
+                    },
+                    "methods": {
+                    },
+                    "scripts": []
+                }
+            }
         };
+
         vwf_view.kernel.createChild(nodeID, nodeName, newNode);
 
     }

+ 36 - 0
support/proxy/vwf.example.com/aframe/ascene.js

@@ -0,0 +1,36 @@
+this.initialize = function() {
+    this.future(0).clientWatch();
+};
+
+this.clientWatch = function () {
+    var self = this;
+
+    if (this.children.length !== 0) {
+
+        var clients = this.find("doc('http://vwf.example.com/clients.vwf')")[0];
+
+        if (clients !== undefined) {
+            //console.log(clients.children);
+
+            let clientsArray = [];
+
+            clients.children.forEach(function (element) {
+                clientsArray.push(element.name);
+
+            });
+
+            this.children.forEach(function (node) {
+                if (node.id.indexOf('avatar-') != -1) {
+
+                    if (clientsArray.includes(node.id.slice(7))) {
+                        //console.log(node.id + 'is here!');
+                    } else {
+                        //console.log(node.id + " needed to delete!");
+                        self.children.delete(self.children[node.id]);
+                    }
+                }
+            });
+     }
+    }
+    this.future(5).clientWatch(); 
+};

+ 2 - 1
support/proxy/vwf.example.com/aframe/ascene.vwf.yaml

@@ -5,6 +5,7 @@ type: "a-scene"
 properties:
   fog:
   assets:
-method:
+methods:
+  clientWatch:
 scripts:
 - source: "http://vwf.example.com/aframe/ascene.js"

+ 2 - 1
support/proxy/vwf.example.com/aframe/atext.vwf.yaml

@@ -4,4 +4,5 @@ extends: http://vwf.example.com/aframe/aentity.vwf
 type: "a-text"
 properties:
   value:
-  color:
+  color:
+  side: