player.js 2.4 KB

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