checkReady

draw a ring around planets and ships that are not marked ready

当前为 2016-04-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name checkReady
  3. // @description draw a ring around planets and ships that are not marked ready
  4. // can't move ships marked ready
  5. //
  6. // @include http://play.planets.nu/*
  7. // @include http://test.planets.nu/*
  8. // @include http://planets.nu/*
  9. // @version 3.0.0
  10. // @homepage https://greasyfork.org/en/users/32642-stephen-piper
  11. // @namespace https://greasyfork.org/en/users/32642-stephen-piper
  12. // ==/UserScript==
  13.  
  14. function wrapper() {
  15. var showReady = false;
  16.  
  17. function checkReady() {
  18. }
  19. checkReady.prototype = {
  20.  
  21. loadControls : function() {
  22.  
  23. this.clearData();
  24.  
  25. if (vgapMap.prototype.spMenuItem != undefined) {
  26. vgapMap.prototype.spMenuItem("Check Ready", "checkReady", function() {
  27. showReady = !showReady;
  28. });
  29.  
  30. vgapMap.prototype.spMenuItem("Clear", "_massClear", function() {
  31. checkReady.prototype.clearData();
  32. });
  33. }
  34. },
  35.  
  36. clearData : function() {
  37. showReady = false;
  38. },
  39.  
  40. };
  41.  
  42. var oldDraw = vgapMap.prototype.draw;
  43. vgapMap.prototype.draw = function(fast, ctx, skipUserContent, secondCanvas) {
  44. oldDraw.apply(this, arguments);
  45.  
  46. if (!ctx)
  47. ctx = this.ctx;
  48.  
  49. // have to redraw ships because normal draw
  50. // copies the planets over the ships
  51. // draw ships not ready
  52. for (var n = 0; n < vgap.myships.length; n++) {
  53. var E = vgap.myships[n];
  54. this.drawShip(E, ctx)
  55. }
  56.  
  57. };
  58.  
  59. var oldDrawPlanet = vgapMap.prototype.drawPlanet;
  60. vgapMap.prototype.drawPlanet = function(planet, ctx, fullrender) {
  61. oldDrawPlanet.apply(this, arguments);
  62.  
  63. var x = this.screenX(planet.x);
  64. var y = this.screenY(planet.y);
  65.  
  66. // draw planets not ready
  67. if (planet.infoturn > 0) {
  68. if (showReady) {
  69. if (planet.readystatus == 0 && vgap.player.id == planet.ownerid) {
  70. this.drawCircle(ctx, x, y, 13 * this.zoom, "orange", 2);
  71. }
  72. if (planet.isbase) {
  73. for (var i = 0; i < vgap.mystarbases.length; ++i) {
  74. if (vgap.mystarbases[i].planetid == planet.id && vgap.mystarbases[i].readystatus == 0) {
  75. this.drawCircle(ctx, x, y, 11 * this.zoom, "red", 2);
  76. break;
  77. }
  78. }
  79. }
  80. }
  81. }
  82. };
  83.  
  84. var oldDrawShip = vgapMap.prototype.drawShip;
  85. vgapMap.prototype.drawShip = function(ship, ctx) {
  86. oldDrawShip.apply(this, arguments);
  87.  
  88. // draw ships not ready had to redraw in draw()
  89. // because drawplanet() wrote over them
  90. if (showReady && ship.readystatus == 0 && vgap.player.id == ship.ownerid) {
  91. this.drawCircle(ctx, this.screenX(ship.x), this.screenY(ship.y), 15 * this.zoom, "yellow", 2);
  92. }
  93. // if (warnings && ship.ownerid) {
  94. // if (ship.dist > Math.pow(ship.warp, 2)) {
  95. // this.drawCircle(ctx, this.screenX(ship.x), this.screenY(ship.y), 14 *
  96. // this.zoom, "red", 2);
  97. // }
  98. // // < required neutronium
  99. // }
  100. };
  101.  
  102. var oldShipSelectorClick = vgapMap.prototype.shipSelectorClick;
  103. vgapMap.prototype.shipSelectorClick = function(event) {
  104.  
  105. var e = this.activeShip;
  106. if (e.readystatus > 0) // can't move ships marked ready
  107. return;
  108.  
  109. oldShipSelectorClick.apply(this, arguments);
  110. };
  111.  
  112. var oldLoadControls = vgapMap.prototype.loadControls;
  113. vgapMap.prototype.loadControls = function() {
  114. oldLoadControls.apply(this, arguments);
  115.  
  116. checkReady.prototype.loadControls();
  117. };
  118. }
  119.  
  120. var script = document.createElement("script");
  121. script.type = "application/javascript";
  122. script.textContent = "(" + wrapper + ")();";
  123.  
  124. document.body.appendChild(script);