player.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. function PlayerScope(scope) {
  2. function Player(options)
  3. {
  4. options = options || {},
  5. this.name = options.name;
  6. this.position = options.position;
  7. this.noSkin = options.noSkin;
  8. this.skin = options.skin || scope.SKIN_NAMES[$.rand(0, scope.SKIN_NAMES.length - 1)];
  9. this.$el = $("#Player-" + this.position);
  10. this.elements = {
  11. $timer: "#Timer",
  12. $name: "#Name",
  13. $nameWrapper: "#Name rect",
  14. $nameText: "#Name text" };
  15. this.proxies = [ "loadSkin" ];
  16. this.__super__.constructor.call(this);
  17. this.$el.show();
  18. this.$timer.hide();
  19. this.$name.show();
  20. setPlayerName("Player-" + this.position, this.name);
  21. this.initTimer();
  22. "Me" == this.position || this.noSkin || $.load("svg/" + [ "Person", this.position, this.skin ].join("-") + ".svg", this.loadSkin);
  23. }
  24. $.inherit(Player, scope.Controller);
  25. $.extend(Player.prototype, {
  26. loadSkin: function(result) {
  27. var $result = $("<g/>").html(result);
  28. var element = $result[0].firstChild;
  29. var xform = parseTransformAttribute(element.getAttribute("transform"));
  30. var ori = parseTransformAttribute(this.$el[0].getAttribute("transform"));
  31. var shift = "translate("+(-parseFloat(ori.translate[0])+parseFloat(xform.translate[0]))+","+
  32. (-parseFloat(ori.translate[1])+parseFloat(xform.translate[1]))+")";
  33. element.setAttribute("transform",shift);
  34. this.$el.append(element);
  35. this.unselect(); },
  36. initTimer: function() {
  37. this.timer = new scope.Timer(this.$timer, { duration: 30 }); },
  38. select: function() {
  39. this.$nameWrapper.attr({ fill: "#517ECE" }),
  40. this.$nameText.attr({ fill: "#FFFFFF" }),
  41. this.$timer.show(),
  42. this.$("#Selection").show(),
  43. this.timer.start(); },
  44. unselect: function() {
  45. this.$nameWrapper.attr({ fill: "#FFFFFF" }),
  46. this.$nameText.attr({ fill: "#48AF5E" }),
  47. this.$timer.hide(),
  48. this.$("#Selection").hide(),
  49. this.timer.reset(); }
  50. });
  51. scope.Player = Player;
  52. }