BitteWenden's Solar Crusaders Mod

Adds some functionality to the Solar Crusaders Alpha

目前为 2015-10-26 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name BitteWenden's Solar Crusaders Mod
  3. // @version 0.1
  4. // @description Adds some functionality to the Solar Crusaders Alpha
  5. // @author BitteWenden
  6. // @match http://solarcrusaders.com/
  7. // @grant GM_addStyle
  8. // @namespace https://gf.qytechs.cn/users/18854
  9. // ==/UserScript==
  10.  
  11. var startupTimerFreq = 5000; // expressed in miliseconds
  12. var allShips;
  13. var overlay;
  14. var shipsToModify;
  15. alert("You're using a modified version of the game. Any bugs you encounter could be caused by the modification so please send a message to BitteWenden in the Solar Crusader forums if you encounter a mod caused bug. Feel free to contact me if you have any suggestions! Select some ships and press 'F' to open the mod menu.");
  16.  
  17. function setPlayable(ships) {
  18. for (var ship of ships) {
  19. ship.isPlayer = true;
  20. }
  21. }
  22.  
  23. function createInputs() {
  24. window.addEventListener('keydown', KeyCheck, true);
  25. overlay = document.createElement ('div');
  26. overlay.innerHTML = '<div id="dialog"><h2 id="shipsToEditLabel">No Ships Selected!</h2><label for="shipColorChooser" >Set Ship Color: </label><input id="shipColorChooser" type="color"></input></br><label for="shipScaleChooser" >Set Scale: </label><input placeholder="1" id="shipScaleChooser" type="number"></input></br><h3>Press Enter to Proceed or ESC to exit.</h3></div>';
  27. overlay.setAttribute ('id', 'overlay');
  28. document.body.appendChild (overlay);
  29. }
  30.  
  31. function init() {
  32. allShips = game.world.getChildAt(1).children;
  33. if(allShips[0].isPlayer !== undefined) {
  34. clearInterval(startupTestInterval)
  35. setPlayable(allShips);
  36. createInputs();
  37. }
  38. }
  39.  
  40. function KeyCheck(e) {
  41. if(overlay.style.visibility == "visible") {
  42. if(e.keyCode == 13) {
  43. var colorChooser = document.getElementById("shipColorChooser");
  44. var rgbColorObj = hexToRgb(colorChooser.value);
  45. var r = rgbColorObj.r.toString();
  46. if(rgbColorObj.r < 100) {
  47. r = "0" + r;
  48. console.log(r);
  49. if(rgbColorObj.r < 10) {
  50. r = "0" + r;
  51. }
  52. }
  53. var g = rgbColorObj.g.toString();
  54. if(rgbColorObj.g < 100) {
  55. g = "0" + g;
  56. console.log(g);
  57. if(rgbColorObj.g < 10) {
  58. g = "0" + g;
  59. }
  60. }
  61. var b = rgbColorObj.b.toString();
  62. if(rgbColorObj.b < 100) {
  63. b = "0" + b;
  64. if(rgbColorObj.b < 10) {
  65. b = "0" + b;
  66. }
  67. }
  68. console.log(r);
  69. console.log(g);
  70. console.log(b);
  71. var rgbColor = r + g + b;
  72. var scaleChooser = document.getElementById("shipScaleChooser");
  73. var scale = scaleChooser.value;
  74. if(scale == 0) {
  75. scale = 0.1;
  76. }
  77. for(var ship of shipsToModify) {
  78. ship.tint = rgbColor;
  79. ship.scale.x = scale,
  80. ship.scale.y = scale;
  81. }
  82. console.log(rgbColor);
  83. overlay.style.visibility = "hidden";
  84. }
  85. if(e.keyCode == 27) {
  86. overlay.style.visibility = "hidden";
  87. }
  88. }
  89. else if(e.keyCode == 70) {
  90. if(overlay != undefined) {
  91. overlay.style.visibility = "visible";
  92. shipsToModify = [];
  93. for(var ship of allShips) {
  94. if(ship.selected === true)
  95. shipsToModify.push(ship);
  96. }
  97. if(shipsToModify.length != 0) {
  98. var labelString = "Selected: ";
  99. var first = true;
  100. for(var ship of shipsToModify) {
  101. if(first === true) {
  102. first = false;
  103. }
  104. else {
  105. labelString += ",";
  106. }
  107. if(ship.name)
  108. labelString += ship.name;
  109. }
  110. var label = document.getElementById("shipsToEditLabel");
  111. label.innerHTML = labelString;
  112. console.log("Selected:" + labelString);
  113. }
  114. }
  115. }
  116. }
  117.  
  118. var startupTestInterval = setInterval(function(){ init() }, startupTimerFreq );
  119.  
  120.  
  121.  
  122. GM_addStyle ( multilineStr ( function () {/*!
  123. #overlay {
  124. visibility: hidden;
  125. position: absolute;
  126. left: 0px;
  127. top: 0px;
  128. width:100%;
  129. height:100%;
  130. text-align:center;
  131. z-index: 1000;
  132. }
  133. #dialog {
  134. width: 30vw;
  135. height: 40vh;
  136. background-color: rgba(255, 165, 0, 0.8);
  137. margin-left: auto;
  138. margin-right: auto;
  139. margin-top:10vh;
  140. }
  141. #shipsToEditLabel {
  142. height: 2em;
  143. width: 100%;
  144. text-overflow: ellipsis;
  145. overflow: hidden;
  146. white-space: nowrap;
  147. color:black;
  148. }
  149. label{
  150. color:black;
  151. }
  152. h3{
  153. color:black;
  154. }
  155. */} ) );
  156.  
  157. function multilineStr (dummyFunc) {
  158. var str = dummyFunc.toString ();
  159. str = str.replace (/^[^\/]+\/\*!?/, '') // Strip function () { /*!
  160. .replace (/\s*\*\/\s*\}\s*$/, '') // Strip */ }
  161. .replace (/\/\/.+$/gm, '') // Double-slash comments wreck CSS. Strip them.
  162. ;
  163. return str;
  164. }
  165.  
  166. function hexToRgb(hex) {
  167. var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  168. return result ? {
  169. r: parseInt(result[1], 16),
  170. g: parseInt(result[2], 16),
  171. b: parseInt(result[3], 16)
  172. } : null;
  173. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址