Advertisement
mathieuc

openHarmony first steps

Sep 16th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getScene(){
  2.     return new oScene();
  3. }
  4.  
  5. function oScene(){
  6. }
  7.  
  8. Object.defineProperty(oScene.prototype, 'nodes', {
  9.     get : function(){
  10.         var _nodes = node.subNodes("Top");
  11.         for (var i in _nodes){
  12.             _nodes[i] = new oNode(_nodes[i])
  13.         }
  14.         return _nodes
  15.     }
  16. })
  17.  
  18. oScene.prototype.$node = function(fullPath){
  19.     return new oNode(fullPath)
  20. }
  21.  
  22. oScene.prototype.getNodeByName = function(fullPath){
  23.     return new oNode(fullPath)
  24. }
  25.  
  26. function oNode(path){
  27.     this.fullPath = path;
  28. }
  29.  
  30. Object.defineProperty(oNode.prototype, 'name', {
  31.     get : function(){
  32.          return node.getName(this.fullPath)
  33.     },
  34.  
  35.     set : function(newName){
  36.         var _parent = node.parentNode(this.fullPath)
  37.         var _node = node.rename(this.fullPath, newName)
  38.         this.fullPath = _parent+'/'+newName;
  39.     }
  40.  
  41. })
  42.  
  43.  
  44. function run(){
  45.     var scene = getScene();
  46.     var nodes = scene.nodes;
  47.  
  48.     for (var i in nodes){
  49.         MessageLog.trace(nodes[i].name)
  50.     }
  51.  
  52.     var myNode = scene.$node("Top/Drawing")
  53.     myNode.name = 'newName'
  54.  
  55.     MessageLog.trace(myNode.name)
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement