VPA-Keyboard

For planets.nu -- Add VPA-key strokes, and commands

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

  1. // ==UserScript==
  2. // @name VPA-Keyboard
  3. // @author Quapla
  4. // @copyright Basecode: Kero van Gelder, 2016 - latest: Quapla
  5. // @license Lesser Gnu Public License, version 3
  6. // @description For planets.nu -- Add VPA-key strokes, and commands
  7. // @namespace quapla/VPA-Keyboard
  8. // @include http://planets.nu/*
  9. // @include http://play.planets.nu/*
  10. // @include http://test.planets.nu/*
  11. // @version 1.0.2
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. // Reference: Kero van Gelder's Keayboard: http://chmeee.org/ext/planets.nu/Keyboard.user.js
  16.  
  17.  
  18. sharedContent.prototype.planetSurvey_McNimblesToolkit = sharedContent.prototype.planetSurvey;
  19. sharedContent.prototype.planetSurvey = function(planetId) {
  20. vgap.currentPlanetSurvey = planetId;
  21. this.planetSurvey_McNimblesToolkit(planetId);
  22. }
  23.  
  24. sharedContent.prototype.editNote_McNimblesToolkit = sharedContent.prototype.editNote;
  25. sharedContent.prototype.editNote = function(noteId, noteType) {
  26. vgap.currentNoteId = noteId;
  27. vgap.currentNoteType = noteType;
  28. this.editNote_McNimblesToolkit(noteId, noteType);
  29. $("#EditNote").focus();
  30. }
  31.  
  32. vgapShipScreen.prototype.shipMission_McNimblesToolkit = vgapShipScreen.prototype.shipMission;
  33. vgapShipScreen.prototype.shipMission = function() {
  34. this.shipMissionOpen = true;
  35. this.shipMission_McNimblesToolkit();
  36. }
  37.  
  38. vgapShipScreen.prototype.selectMission_McNimblesToolkit = vgapShipScreen.prototype.selectMission;
  39. vgapShipScreen.prototype.selectMission = function(missionId) {
  40. this.selectMission_McNimblesToolkit(missionId);
  41. this.shipMissionOpen = false;
  42. }
  43.  
  44. vgapShipScreen.prototype.primaryEnemy_McNimblesToolkit = vgapShipScreen.prototype.primaryEnemy;
  45. vgapShipScreen.prototype.primaryEnemy = function() {
  46. this.primaryEnemyOpen = true;
  47. this.primaryEnemy_McNimblesToolkit();
  48. }
  49. vgapShipScreen.prototype.selectEnemy_McNimblesToolkit = vgapShipScreen.prototype.selectEnemy;
  50. vgapShipScreen.prototype.selectEnemy = function(enemyId) {
  51. this.selectEnemy_McNimblesToolkit(enemyId);
  52. this.primaryEnemyOpen = false;
  53. }
  54. vgaPlanets.prototype.closeMore_McNimblesToolkit = vgaPlanets.prototype.closeMore;
  55. vgaPlanets.prototype.closeMore = function(callback) {
  56. vgap.closeMore_McNimblesToolkit(callback);
  57. this.primaryEnemyOpen = false;
  58. vgap.currentPlanetSurvey = null;
  59. vgap.shipScreen.shipMissionOpen = false;
  60. }
  61.  
  62. vgaPlanets.prototype.hotkey_McNimblesToolkit = vgaPlanets.prototype.hotkey;
  63. vgaPlanets.prototype.hotkey = function(event) {
  64. if (vgap.shipScreen.primaryEnemyOpen) {
  65. var enemy = 0;
  66. if (event.keyCode >= 48 && event.keyCode <= 57) enemy = event.keyCode - 48;
  67. if (event.keyCode >= 65 && event.keyCode <= 90) enemy = event.keyCode - 65 + 10;
  68. if (enemy <= vgap.players.length) {
  69. vgap.shipScreen.selectEnemy(enemy);
  70. return;
  71. }
  72. }
  73.  
  74. if (vgap.shipScreen.shipMissionOpen) {
  75. var missionId = -1;
  76. if (event.keyCode == 67) missionId = 9; // 'c', Cloak
  77. else if (event.keyCode == 69) missionId = 0; // 'e', Explore
  78. else if (event.keyCode == 73) missionId = 7; // 'i', Intercept
  79. else if (event.keyCode == 75) missionId = 3; // 'k', Kill
  80. else if (event.keyCode == 76) missionId = 2; // 'l', Lay Mines
  81. else if (event.keyCode == 77) missionId = 1; // 'm', Mine Sweep
  82. else if (event.keyCode == 83 && event.shiftKey) missionId = 8; // 'S', Special / Super Spy
  83. else if (event.keyCode == 83) missionId = 4; // 's', Sensor Sweep
  84. else if (event.keyCode == 84) missionId = 6; // 't', Tow
  85. if (missionId >= 0) {
  86. vgap.shipScreen.selectMission(missionId);
  87. return;
  88. }
  89. }
  90.  
  91. if (vgap.editNoteOpen) {
  92. if (event.keyCode == 13 && event.ctrlKey) {
  93. this.saveNote(vgap.currentNoteId, vgap.currentNoteType);
  94. return;
  95. }
  96. }
  97.  
  98. if (event.keyCode == 27) {
  99. if (this.findObjectFeatureActivated) vgap.map.hideFindObjectFeature();
  100. else if (vgap.moreOpen) this.closeMore();
  101. else if (this.lcOpen) this.deselectAll();
  102. else this.hotkey_McNimblesToolkit(event);
  103. return;
  104. }
  105.  
  106. if (vgap.hotkeysOn) {
  107. switch (event.keyCode) {
  108. case 8:
  109. if ((this.starbaseScreenOpen || this.planetScreenOpen || this.shipScreenOpen) && !this.moreOpen) {
  110. vgap.rPrev();
  111. return;
  112. }
  113. case 78: // 'n'
  114. if (event.shiftKey) {
  115. if (this.planetScreenOpen) {
  116. shtml.editNote(vgap.planetScreen.planet.id, 1);
  117. return;
  118. } else if (vgap.currentPlanetSurvey > 0) { // ship screen is open, but unowned planet is selected
  119. shtml.editNote(vgap.currentPlanetSurvey, 1);
  120. return
  121. } else if (this.shipScreenOpen) {
  122. shtml.editNote(vgap.shipScreen.ship.id, 2);
  123. return;
  124. } else if (this.starbaseScreenOpen) {
  125. shtml.editNote(vgap.starbaseScreen.starbase.id, 3);
  126. return;
  127. }
  128. }
  129. break;
  130. case 88: // 'x'
  131. this.map.clearTools();
  132. return;
  133. case 90: // 'z'
  134. this.map.zoomFarInOrOut_OnWaypointOrPlanet();
  135. return;
  136. //case 188: // '<' if (event.shiftKey)
  137. case 38: // Arrow up
  138. vgap.unrotateActiveObject();
  139. return;
  140. // case 190: // '>'
  141. case 40: // Arrow-Down if (event.shiftKey)
  142. vgap.rotateActiveObject();
  143. return;
  144. case 39: // Arrow right // if (ev.keyCode == 39 && this.shipScreenOpen || this.planetScreenOpen)
  145. this.rNext();
  146. return;
  147. case 37: // Arrow left // if (ev.keyCode == 39 && this.shipScreenOpen || this.planetScreenOpen)
  148. this.rPrev();
  149. return;
  150. }
  151. }
  152.  
  153. this.hotkey_McNimblesToolkit(event);
  154. }
  155.  
  156. vgapMap.prototype.zoomFarInOrOut_OnWaypointOrPlanet = function() {
  157. var zoomedOut = (this.zoom < 29);
  158. if (zoomedOut) {
  159. this.zoomFactorBeforeZoomingInDeeply = this.zoom;
  160. this.setZoom(42);
  161. } else {
  162. this.setZoom(this.zoomFactorBeforeZoomingInDeeply);
  163. }
  164. var x, y;
  165. if (this.activeShip) {
  166. x = this.activeShip.targetx;
  167. y = this.activeShip.targety;
  168. } else if (this.activePlanet) {
  169. x = this.activePlanet.x;
  170. y = this.activePlanet.y;
  171. } else {
  172. x = this.centerX;
  173. y = this.centerY;
  174. }
  175.  
  176. this.centerX = x;
  177. this.centerY = y;
  178. this.canvas.x = x - $(window).width() / 2 / this.zoom;
  179. this.canvas.y = y - $(window).height() / 2 / this.zoom;
  180. this.draw();
  181. }
  182.  
  183. vgaPlanets.prototype.rotateActiveObject = function() {
  184. if (vgap.planetScreenOpen) {
  185. var planet = vgap.map.activePlanet;
  186. if (planet.isbase) {
  187. vgap.map.selectStarbase(planet.id);
  188. } else {
  189. var ships = vgap.shipsAt(planet.x, planet.y);
  190. if (ships.length > 0) vgap.map.selectShip(ships[0].id);
  191. // else only a planet
  192. }
  193. } else if (vgap.starbaseScreenOpen) {
  194. var planet = vgap.map.activePlanet;
  195. var ships = vgap.shipsAt(planet.x, planet.y);
  196. if (ships.length > 0) {
  197. vgap.map.selectShip(ships[0].id);
  198. } else {
  199. vgap.map.selectPlanet(planet.id);
  200. }
  201. } else if (vgap.shipScreenOpen) {
  202. var ship = vgap.map.activeShip;
  203. var ships = vgap.shipsAt(ship.x, ship.y)
  204. var index = ships.indexOf(ship);
  205. if (index == ships.length - 1) {
  206. var planet = vgap.planetAt(ship.x, ship.y)
  207. if (planet) {
  208. vgap.map.selectPlanet(planet.id);
  209. } else if (ships.length > 1) {
  210. vgap.map.selectShip(ships[0].id);
  211. } // else Cannot rotate 1 ship
  212. } else {
  213. vgap.map.selectShip(ships[index+1].id);
  214. }
  215. }
  216. }
  217.  
  218. vgaPlanets.prototype.unrotateActiveObject = function() {
  219. if (vgap.planetScreenOpen) {
  220. var planet = vgap.map.activePlanet;
  221. var ships = vgap.shipsAt(planet.x, planet.y);
  222. if (ships.length > 0) {
  223. vgap.map.selectShip(ships[ships.length-1].id);
  224. } else if (planet.isbase) {
  225. vgap.map.selectStarbase(planet.id);
  226. } // else only a planet
  227. } else if (vgap.starbaseScreenOpen) {
  228. var planet = vgap.map.activePlanet;
  229. vgap.map.selectPlanet(planet.id);
  230. } else if (vgap.shipScreenOpen) {
  231. var ship = vgap.map.activeShip;
  232. var ships = vgap.shipsAt(ship.x, ship.y)
  233. var index = ships.indexOf(ship);
  234. if (index == 0) {
  235. var planet = vgap.planetAt(ship.x, ship.y)
  236. if (planet) {
  237. if (planet.isbase) {
  238. vgap.map.selectStarbase(planet.id);
  239. } else {
  240. vgap.map.selectPlanet(planet.id);
  241. }
  242. } else {
  243. if (ships.length > 1) vgap.map.selectShip(ships[ships.length-1].id);
  244. }
  245. } else {
  246. vgap.map.selectShip(ships[index-1].id);
  247. }
  248. }
  249. }