player.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.sex = options.sex;
  9. var skins = this.sex == "female" ? scope.FEMALE_SKINS : scope.MALE_SKINS;
  10. this.skin = options.skin || skins[$.rand(0, skins.length - 1)];
  11. this.$el = $("#Player-" + this.position);
  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 $result = $("<g/>").html(result);
  30. var element = $result[0].firstChild;
  31. var xform = parseTransformAttribute(element.getAttribute("transform"));
  32. var ori = parseTransformAttribute(this.$el[0].getAttribute("transform"));
  33. var shift = "translate("+(-parseFloat(ori.translate[0])+parseFloat(xform.translate[0]))+","+
  34. (-parseFloat(ori.translate[1])+parseFloat(xform.translate[1]))+")";
  35. element.setAttribute("transform",shift);
  36. this.$el.append(element);
  37. this.unselect(); },
  38. initTimer: function() {
  39. this.timer = new scope.Timer(this.$timer, { duration: 30 }); },
  40. select: function() {
  41. this.$nameWrapper.attr({ fill: "#517ECE" }),
  42. this.$nameText.attr({ fill: "#FFFFFF" }),
  43. this.$timer.show(),
  44. this.$("#Selection").show(),
  45. this.timer.start(); },
  46. unselect: function() {
  47. this.$nameWrapper.attr({ fill: "#FFFFFF" }),
  48. this.$nameText.attr({ fill: "#48AF5E" }),
  49. this.$timer.hide(),
  50. this.$("#Selection").hide(),
  51. this.timer.reset(); }
  52. });
  53. scope.Player = Player;
  54. }