Guest User

Untitled

a guest
May 27th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1.  
  2. var Item = function(world, id){
  3. var self = this;
  4.  
  5. var position, scale, asset,
  6. properties = {};
  7.  
  8. this.say = function(message){
  9. $LOGGER.log("<b>Item</b>: " + message);
  10.  
  11. var p = position.subtract(asset.getMenuAnchor());
  12.  
  13. var div = $("<div />");
  14. div.addClass('speech');
  15. div.css({
  16. left : p.x + 20,
  17. top : p.y + 50
  18. });
  19. div.appendTo('#playfield');
  20. div.delay(800 + message.split(" ").length * 200).animate({top : p.y - 50, opacity: 0}, function(){
  21. div.remove();
  22. });
  23.  
  24. var span = $("<span />");
  25. span.text(message);
  26. span.appendTo(div);
  27. span.css({
  28. top : 110 - span.height() / 2
  29. })
  30. }
  31.  
  32. this.redraw = function(){
  33. if(asset){
  34. asset.redraw();
  35. }
  36. }
  37.  
  38. this.setId = function(i){
  39. id = i;
  40. }
  41.  
  42. this.getId = function(){
  43. return id;
  44. }
  45.  
  46. this.getWorld = function(){
  47. return world;
  48. }
  49.  
  50. this.setWorld = function(w){
  51. if(w instanceof World){
  52. world = w;
  53. }else{
  54. throw "Not a World object";
  55. }
  56. }
  57.  
  58. this.remove = function(){
  59. if(asset){
  60. asset.remove();
  61. }
  62.  
  63. world.removeItem(id);
  64. }
  65.  
  66. this.setAsset = function(a){
  67. asset = a;
  68. }
  69.  
  70. this.getAsset = function(){
  71. return asset;
  72. }
  73.  
  74. this.setPosition = function(v){
  75. if(v instanceof Vector){
  76. position = new Vector(v);
  77. this.redraw();
  78. }else{
  79. throw "Not a Vector object"
  80. }
  81. }
  82.  
  83. this.getPosition = function(){
  84. return new Vector(position);
  85. }
  86.  
  87. this.getProperties = function(){
  88. return {
  89. id : id,
  90. type : 'Item',
  91. position : position ? position.toJSON() : null,
  92. asset : asset ? asset.toJSON() : null
  93. };
  94. }
  95.  
  96. this.getProperty = function(name){
  97. return properties[name];
  98. }
  99.  
  100. // todo - make it trigger any redraw events etc
  101. this.setProperty = function(name, value){
  102. if("id" == name){
  103. id = value;
  104. return;
  105. }
  106.  
  107. if("position" == name){
  108. position = Instantiate(Vector, value);
  109. }
  110.  
  111. if("asset" == name){
  112. asset = Instantiate(Asset, value);
  113. asset.setItem(this);
  114. }
  115.  
  116. properties[name] = value;
  117. }
  118.  
  119. this.setProperties = function(obj){
  120. // We need to normalize ids..
  121.  
  122. var key;
  123.  
  124. for(key in obj){
  125. this.setProperty(key, obj[key]);
  126. }
  127. }
  128.  
  129. this.notifyChange = function(){
  130. $SOCKET.send($.toJSON(this));
  131. }
  132. }
Add Comment
Please, Sign In to add comment