VPA-Keyboard

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

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

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