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