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.4
  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. switch (event.keyCode) {
  129. case 8:
  130. if ((this.starbaseScreenOpen || this.planetScreenOpen || this.shipScreenOpen) && !this.moreOpen) {
  131. vgap.rPrev();
  132. return;
  133. }
  134. case 78: // 'n'
  135. if (event.shiftKey) {
  136. if (this.planetScreenOpen) {
  137. shtml.editNote(vgap.planetScreen.planet.id, 1);
  138. return;
  139. } else if (vgap.currentPlanetSurvey > 0) { // ship screen is open, but unowned planet is selected
  140. shtml.editNote(vgap.currentPlanetSurvey, 1);
  141. return
  142. } else if (this.shipScreenOpen) {
  143. shtml.editNote(vgap.shipScreen.ship.id, 2);
  144. return;
  145. } else if (this.starbaseScreenOpen) {
  146. shtml.editNote(vgap.starbaseScreen.starbase.id, 3);
  147. return;
  148. }
  149. }
  150. break;
  151. case 88: // 'x'
  152. this.map.clearTools();
  153. return;
  154. case 90: // 'z'
  155. this.map.zoomFarInOrOut_OnWaypointOrPlanet();
  156. return;
  157.  
  158. //case 188: // '<' if (event.shiftKey)
  159. case 38: // Arrow up
  160. vgap.unrotateActiveObject();
  161. return;
  162. // case 190: // '>'
  163. case 40: // Arrow-Down if (event.shiftKey)
  164. vgap.rotateActiveObject();
  165. return;
  166. case 39: // Arrow right // if (ev.keyCode == 39 && this.shipScreenOpen || this.planetScreenOpen)
  167. this.rNext();
  168. return;
  169. case 37: // Arrow left // if (ev.keyCode == 39 && this.shipScreenOpen || this.planetScreenOpen)
  170. this.rPrev();
  171. return;
  172.  
  173. /* case 163: // '#' set ships/planet ready
  174. {
  175. //console.log("ID:"+this.activePlanet.id+" R:"+this.activePlanet.readystatus+" # pressed...")
  176. if (this.planetScreenOpen)
  177. this.setPlanetsReadyCheckBox();
  178. else if (this.starbaseScreenOpen)
  179. vgap.setReadyCheckBox(this);
  180. else if (this.shipScreenOpen)
  181. vgap.setReadyCheckBox(this);
  182. this.rNext();
  183. return;
  184. } */
  185. }
  186. }
  187. this.hotkey_McNimblesToolkit(event);
  188. }
  189.  
  190. vgapMap.prototype.zoomFarInOrOut_OnWaypointOrPlanet = function () {
  191. var zoomedOut = (this.zoom < 29);
  192. if (zoomedOut) {
  193. this.zoomFactorBeforeZoomingInDeeply = this.zoom;
  194. this.setZoom(42);
  195. } else {
  196. this.setZoom(this.zoomFactorBeforeZoomingInDeeply);
  197. }
  198. var x,
  199. y;
  200. if (this.activeShip) {
  201. x = this.activeShip.targetx;
  202. y = this.activeShip.targety;
  203. } else if (this.activePlanet) {
  204. x = this.activePlanet.x;
  205. y = this.activePlanet.y;
  206. } else {
  207. x = this.centerX;
  208. y = this.centerY;
  209. }
  210.  
  211. this.centerX = x;
  212. this.centerY = y;
  213. this.canvas.x = x - $(window).width() / 2 / this.zoom;
  214. this.canvas.y = y - $(window).height() / 2 / this.zoom;
  215. this.draw();
  216. }
  217.  
  218. vgaPlanets.prototype.rotateActiveObject = function () {
  219. if (vgap.planetScreenOpen) {
  220. var planet = vgap.map.activePlanet;
  221. if (planet.isbase) {
  222. vgap.map.selectStarbase(planet.id);
  223. } else {
  224. var ships = vgap.shipsAt(planet.x, planet.y);
  225. if (ships.length > 0)
  226. vgap.map.selectShip(ships[0].id);
  227. // else only a planet
  228. }
  229. } else if (vgap.starbaseScreenOpen) {
  230. var planet = vgap.map.activePlanet;
  231. var ships = vgap.shipsAt(planet.x, planet.y);
  232. if (ships.length > 0) {
  233. vgap.map.selectShip(ships[0].id);
  234. } else {
  235. vgap.map.selectPlanet(planet.id);
  236. }
  237. } else if (vgap.shipScreenOpen) {
  238. var ship = vgap.map.activeShip;
  239. var ships = vgap.shipsAt(ship.x, ship.y)
  240. var index = ships.indexOf(ship);
  241. if (index == ships.length - 1) {
  242. var planet = vgap.planetAt(ship.x, ship.y)
  243. if (planet) {
  244. vgap.map.selectPlanet(planet.id);
  245. } else if (ships.length > 1) {
  246. vgap.map.selectShip(ships[0].id);
  247. } // else Cannot rotate 1 ship
  248. } else {
  249. vgap.map.selectShip(ships[index + 1].id);
  250. }
  251. }
  252. }
  253.  
  254. vgaPlanets.prototype.unrotateActiveObject = function () {
  255. if (vgap.planetScreenOpen) {
  256. var planet = vgap.map.activePlanet;
  257. var ships = vgap.shipsAt(planet.x, planet.y);
  258. if (ships.length > 0) {
  259. vgap.map.selectShip(ships[ships.length - 1].id);
  260. } else if (planet.isbase) {
  261. vgap.map.selectStarbase(planet.id);
  262. } // else only a planet
  263. } else if (vgap.starbaseScreenOpen) {
  264. var planet = vgap.map.activePlanet;
  265. vgap.map.selectPlanet(planet.id);
  266. } else if (vgap.shipScreenOpen) {
  267. var ship = vgap.map.activeShip;
  268. var ships = vgap.shipsAt(ship.x, ship.y)
  269. var index = ships.indexOf(ship);
  270. if (index == 0) {
  271. var planet = vgap.planetAt(ship.x, ship.y)
  272. if (planet) {
  273. if (planet.isbase) {
  274. vgap.map.selectStarbase(planet.id);
  275. } else {
  276. vgap.map.selectPlanet(planet.id);
  277. }
  278. } else {
  279. if (ships.length > 1)
  280. vgap.map.selectShip(ships[ships.length - 1].id);
  281. }
  282. } else {
  283. vgap.map.selectShip(ships[index - 1].id);
  284. }
  285. }
  286. }