BitteWenden's Solar Crusaders Mod

Adds some functionality to the Solar Crusaders Alpha

  1. // ==UserScript==
  2. // @name BitteWenden's Solar Crusaders Mod
  3. // @version 0.1.3
  4. // @description Adds some functionality to the Solar Crusaders Alpha
  5. // @author @BitteWenden
  6. // @match http://www.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 gameInformation;
  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() {
  18. for (var ship of gameInformation.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><form><label for="shipColorChooser" >Set Ship Tint: </label><input id="shipColorChooser" type="color"></input></br><label for="shipScaleChooser" >Set Scale: </label><input placeholder="1" id="shipScaleChooser" type="number"></input></br><label for="engineGlowColorChooser" >Set Engine Glow Tint: </label><input placeholder="1" id="engineGlowColorChooser" type="color"></input></form></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.  
  33. if (game.state.current == "sector") {
  34. clearInterval(startupTestInterval)
  35. gameInformation = getGameInformation();
  36. setPlayable();
  37.  
  38.  
  39. createInputs();
  40. }
  41.  
  42. }
  43.  
  44. function getGameInformation() {
  45. return {
  46. game: game,
  47. state: game.state.getCurrentState(),
  48. ships: game.state.getCurrentState().shipManager.shipsGroup.children,
  49. }
  50. }
  51.  
  52. function KeyCheck(e) {
  53. if (overlay.style.visibility == "visible") {
  54. if (e.keyCode == 13) {
  55.  
  56. var shipColorChooser = document.getElementById("shipColorChooser");
  57. var shipRgbColorObj = hexToRgb(shipColorChooser.value);
  58.  
  59. var engineColorChooser = document.getElementById("engineGlowColorChooser");
  60. var engineRgbColorObj = hexToRgb(engineColorChooser.value);
  61.  
  62. var shipRgbColor = rgbToFullRgb(shipRgbColorObj);
  63. var engineRgbColor = rgbToFullRgb(engineRgbColorObj);
  64. var scaleChooser = document.getElementById("shipScaleChooser");
  65. var scale = scaleChooser.value;
  66. if (scale == 0) {
  67. scale = 0.1;
  68. }
  69. for (var ship of shipsToModify) {
  70. ship.tint = shipRgbColor;
  71. for (var engineCoreGlow of ship.engineCore.glows) {
  72. engineCoreGlow.tint = engineRgbColor;
  73. }
  74. ship.scale.x = scale,
  75. ship.scale.y = scale;
  76. }
  77. overlay.style.visibility = "hidden";
  78. }
  79.  
  80. if (e.keyCode == 27) {
  81.  
  82. overlay.style.visibility = "hidden";
  83. }
  84. } else if (e.keyCode == 70) {
  85. if (overlay != undefined) {
  86. overlay.style.visibility = "visible";
  87. shipsToModify = [];
  88. for (var ship of gameInformation.ships) {
  89. if (ship.selected == true)
  90. shipsToModify.push(ship);
  91. }
  92. if (shipsToModify.length != 0) {
  93. var labelString = "Selected: ";
  94. var first = true;
  95. for (var ship of shipsToModify) {
  96. if (first == true) {
  97. first = false;
  98. } else {
  99. labelString += ",";
  100. }
  101. if (ship.name)
  102. labelString += ship.name;
  103.  
  104.  
  105. }
  106. var label = document.getElementById("shipsToEditLabel");
  107. label.innerHTML = labelString;
  108. console.log("Selected:" + labelString);
  109. }
  110. }
  111. }
  112. else if(e.keyCode == 77) {
  113. gameInformation.state.createShips();
  114. }
  115. else if(e.keyCode == 78) {
  116. setPlayable();
  117. }
  118. }
  119.  
  120. var startupTestInterval = setInterval(function() {
  121. init()
  122. }, startupTimerFreq);
  123.  
  124.  
  125.  
  126. GM_addStyle(multilineStr(function() {
  127. /*!
  128. #overlay {
  129. visibility: hidden;
  130. position: absolute;
  131. left: 0px;
  132. top: 0px;
  133. width:100%;
  134. height:100%;
  135. text-align:center;
  136. z-index: 1000;
  137. }
  138. #dialog {
  139. width: 30vw;
  140. height: 40vh;
  141. background-color: rgba(255, 165, 0, 0.8);
  142. margin-left: auto;
  143. margin-right: auto;
  144. margin-top:10vh;
  145. }
  146. #shipsToEditLabel {
  147. height: 2em;
  148. width: 100%;
  149. text-overflow: ellipsis;
  150. overflow: hidden;
  151. white-space: nowrap;
  152. color:black;
  153. }
  154. label{
  155. color:black;
  156. }
  157. h3{
  158. color:black;
  159. }
  160. */
  161. }));
  162.  
  163. function multilineStr(dummyFunc) {
  164. var str = dummyFunc.toString();
  165. str = str.replace(/^[^\/]+\/\*!?/, '') // Strip function () { /*!
  166. .replace(/\s*\*\/\s*\}\s*$/, '') // Strip */ }
  167. .replace(/\/\/.+$/gm, '') // Double-slash comments wreck CSS. Strip them.
  168. ;
  169. return str;
  170. }
  171.  
  172. function hexToRgb(hex) {
  173. var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  174. return result ? {
  175. r: parseInt(result[1], 16),
  176. g: parseInt(result[2], 16),
  177. b: parseInt(result[3], 16)
  178. } : null;
  179. }
  180.  
  181. function rgbToFullRgb(rgbColorObj) {
  182.  
  183. var r = rgbColorObj.r.toString();
  184. if (rgbColorObj.r < 100) {
  185. var r = "0" + r;
  186. console.log(r);
  187. if (rgbColorObj.r < 10) {
  188. var r = "0" + r;
  189. }
  190. }
  191. var g = rgbColorObj.g.toString();
  192. if (rgbColorObj.g < 100) {
  193. g = "0" + g;
  194. console.log(g);
  195. if (rgbColorObj.g < 10) {
  196. var g = "0" + g;
  197. }
  198. }
  199. var b = rgbColorObj.b.toString();
  200. if (rgbColorObj.b < 100) {
  201. b = "0" + b;
  202. if (rgbColorObj.b < 10) {
  203. var b = "0" + b;
  204. }
  205. }
  206. return r + g + b;
  207. }

QingJ © 2025

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