You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

455 lines
22 KiB

  1. function secondsToTime(secs)
  2. {
  3. var h = Math.floor(secs / (60 * 60));
  4. var divisor_for_minutes = secs % (60 * 60);
  5. var m = Math.floor(divisor_for_minutes / 60);
  6. var divisor_for_seconds = divisor_for_minutes % 60;
  7. var s = Math.ceil(divisor_for_seconds);
  8. return h + "h " + m + "m " + s + "s";
  9. }
  10. function printResources(r) {
  11. let enough = true;
  12. let html = "";
  13. html += `Requires:`;
  14. if (r.Metal <= user.Resources.Metal) {
  15. html += ` Metal: <b style="color:lime;">` + r.Metal + `</b>`;
  16. } else {
  17. enough = false;
  18. html += ` Metal: <b style="color:red;">` + r.Metal + `</b>`;
  19. }
  20. if (r.Crystal <= user.Resources.Crystal) {
  21. html += ` Crystal: <b style="color:lime;">` + r.Crystal + `</b>`;
  22. } else {
  23. enough = false;
  24. html += ` Crystal: <b style="color:red;">` + r.Crystal + `</b>`;
  25. }
  26. if (r.Deuterium <= user.Resources.Deuterium) {
  27. html += ` Deuterium: <b style="color:lime;">` + r.Deuterium + `</b>`;
  28. } else {
  29. enough = false;
  30. html += ` Deuterium: <b style="color:red;">` + r.Deuterium + `</b>`;
  31. }
  32. if (r.Energy <= user.Resources.Energy) {
  33. html += ` Energy: <b style="color: lime;">` + r.Energy + `</b>`;
  34. } else {
  35. enough = false;
  36. html += ` Energy: <b style="color: red;">` + r.Energy + `</b>`;
  37. }
  38. return {html, enough};
  39. }
  40. function printPlanet(planet) {
  41. let r = {};
  42. document.getElementById("planetname").innerHTML = planet.Name;
  43. if (planet.CurrentBuild.Title !== "") {
  44. document.getElementById("currentBuild").innerHTML = `
  45. Currently building: <b>` + planet.CurrentBuild.Title + `</b>
  46. <br>
  47. Finishes at: <b>` + planet.CurrentBuild.Ends + `</b>
  48. `
  49. } else {
  50. document.getElementById("currentBuild").innerHTML = "";
  51. }
  52. // metalmine
  53. if (planet.Buildings.metalmine == undefined) {
  54. document.getElementById("btnBuildMetalMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('metalmine')">Build building</div>`;
  55. r = metalmineCost(1);
  56. t = constructionTime(r, 1);
  57. resrourcesHtml = printResources(r);
  58. document.getElementById("metalmineResources").innerHTML = resrourcesHtml.html + `
  59. <br>
  60. Construction time: ` + secondsToTime(t);
  61. } else {
  62. document.getElementById("metalmineLevel").innerHTML = "(Level " + planet.Buildings.metalmine + ")";
  63. document.getElementById("btnBuildMetalMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('metalmine')">Build level ` + (+ (planet.Buildings.metalmine) + + (1)) + `</div>`;
  64. r = metalmineCost((+ (planet.Buildings.metalmine) + + (1)));
  65. t = constructionTime(r, (+ (planet.Buildings.metalmine) + + (1)));
  66. resrourcesHtml = printResources(r);
  67. document.getElementById("metalmineResources").innerHTML = resrourcesHtml.html + `
  68. <br>
  69. Construction time: ` + secondsToTime(t);
  70. }
  71. if (!resrourcesHtml.enough) {
  72. document.getElementById("btnBuildMetalMine").innerHTML = `<span style="color: red;">not enough resources</span>`;
  73. }
  74. if (planet.CurrentBuild.Title !== "") {
  75. document.getElementById("btnBuildMetalMine").innerHTML = `<span style="color: red;">building</span>`;
  76. }
  77. // crystalmine
  78. if (planet.Buildings.crystalmine == undefined) {
  79. document.getElementById("btnBuildCrystalMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('crystalmine')">Build building</div>`;
  80. r = crystalmineCost(1);
  81. t = constructionTime(r, 1);
  82. resrourcesHtml = printResources(r);
  83. document.getElementById("crystalmineResources").innerHTML = resrourcesHtml.html + `
  84. <br>
  85. Construction time: ` + secondsToTime(t);
  86. } else {
  87. document.getElementById("crystalmineLevel").innerHTML = "(Level " + planet.Buildings.crystalmine + ")";
  88. document.getElementById("btnBuildCrystalMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('crystalmine')">Build level ` + (+ (planet.Buildings.crystalmine) + + (1)) + `</div>`;
  89. r = crystalmineCost((+ (planet.Buildings.crystalmine) + + (1)));
  90. t = constructionTime(r, (+ (planet.Buildings.crystalmine) + + (1)));
  91. resrourcesHtml = printResources(r);
  92. document.getElementById("crystalmineResources").innerHTML = resrourcesHtml.html + `
  93. <br>
  94. Construction time: ` + secondsToTime(t);
  95. }
  96. if (!resrourcesHtml.enough) {
  97. document.getElementById("btnBuildCrystalMine").innerHTML = `<span style="color: red;">not enough resources</span>`;
  98. }
  99. if (planet.CurrentBuild.Title !== "") {
  100. document.getElementById("btnBuildCrystalMine").innerHTML = `<span style="color: red;">building</span>`;
  101. }
  102. // deuteriummine{
  103. if (planet.Buildings.deuteriummine == undefined) {
  104. document.getElementById("btnBuildDeuteriumMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('deuteriummine')">Build building</div>`;
  105. r = deuteriummineCost(1);
  106. t = constructionTime(r, 1);
  107. resrourcesHtml = printResources(r);
  108. document.getElementById("deuteriummineResources").innerHTML = resrourcesHtml.html + `
  109. <br>
  110. Construction time: ` + secondsToTime(t);
  111. } else {
  112. document.getElementById("deuteriummineLevel").innerHTML = "(Level " + planet.Buildings.deuteriummine + ")";
  113. document.getElementById("btnBuildDeuteriumMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('deuteriummine')">Build level ` + (+ (planet.Buildings.deuteriummine) + + (1)) + `</div>`;
  114. r = deuteriummineCost((+ (planet.Buildings.deuteriummine) + + (1)));
  115. t = constructionTime(r, (+ (planet.Buildings.deuteriummine) + + (1)));
  116. resrourcesHtml = printResources(r);
  117. document.getElementById("deuteriummineResources").innerHTML = resrourcesHtml.html + `
  118. <br>
  119. Construction time: ` + secondsToTime(t);
  120. }
  121. if (!resrourcesHtml.enough) {
  122. document.getElementById("btnBuildDeuteriumMine").innerHTML = `<span style="color: red;">not enough resources</span>`;
  123. }
  124. if (planet.CurrentBuild.Title !== "") {
  125. document.getElementById("btnBuildDeuteriumMine").innerHTML = `<span style="color: red;">building</span>`;
  126. }
  127. // energymine
  128. if (planet.Buildings.energymine == undefined) {
  129. document.getElementById("btnBuildEnergyMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('energymine')">Build building</div>`;
  130. r = energymineCost(1);
  131. t = constructionTime(r, 1);
  132. resrourcesHtml = printResources(r);
  133. document.getElementById("energymineResources").innerHTML = resrourcesHtml.html + `
  134. <br>
  135. Construction time: ` + secondsToTime(t);
  136. } else {
  137. document.getElementById("energymineLevel").innerHTML = "(Level " + planet.Buildings.energymine + ")";
  138. document.getElementById("btnBuildEnergyMine").innerHTML = `<div style="color:lime;" onclick="buildBuilding('energymine')">Build level ` + (+ (planet.Buildings.energymine) + + (1)) + `</div>`;
  139. r = energymineCost((+ (planet.Buildings.energymine) + + (1)));
  140. t = constructionTime(r, (+ (planet.Buildings.energymine) + + (1)));
  141. resrourcesHtml = printResources(r);
  142. document.getElementById("energymineResources").innerHTML = resrourcesHtml.html + `
  143. <br>
  144. Construction time: ` + secondsToTime(t);
  145. }
  146. if (!resrourcesHtml.enough) {
  147. document.getElementById("btnBuildEnergyMine").innerHTML = `<span style="color: red;">not enough resources</span>`;
  148. }
  149. if (planet.CurrentBuild.Title !== "") {
  150. document.getElementById("btnBuildEnergyMine").innerHTML = `<span style="color: red;">building</span>`;
  151. }
  152. // fusionreactor
  153. if (planet.Buildings.fusionreactor == undefined) {
  154. document.getElementById("btnBuildFusionReactor").innerHTML = `<div style="color:lime;" onclick="buildBuilding('fusionreactor')">Build building</div>`;
  155. r = fusionreactorCost(1);
  156. t = constructionTime(r, 1);
  157. resrourcesHtml = printResources(r);
  158. document.getElementById("fusionreactorResources").innerHTML = resrourcesHtml.html + `
  159. <br>
  160. Construction time: ` + secondsToTime(t);
  161. } else {
  162. document.getElementById("fusionreactorLevel").innerHTML = "(Level " + planet.Buildings.fusionreactor + ")";
  163. document.getElementById("btnBuildFusionReactor").innerHTML = `<div style="color:lime;" onclick="buildBuilding('fusionreactor')">Build level ` + (+ (planet.Buildings.fusionreactor) + + (1)) + `</div>`;
  164. r = fusionreactorCost((+ (planet.Buildings.fusionreactor) + + (1)));
  165. t = constructionTime(r, (+ (planet.Buildings.fusionreactor) + + (1)));
  166. resrourcesHtml = printResources(r);
  167. document.getElementById("fusionreactorResources").innerHTML = resrourcesHtml.html + `
  168. <br>
  169. Construction time: ` + secondsToTime(t);
  170. }
  171. if (!resrourcesHtml.enough) {
  172. document.getElementById("btnBuildFusionReactor").innerHTML = `<span style="color: red;">not enough resources</span>`;
  173. }
  174. if (planet.CurrentBuild.Title !== "") {
  175. document.getElementById("btnBuildFusionReactor").innerHTML = `<span style="color: red;">building</span>`;
  176. }
  177. // roboticsfactory
  178. if (planet.Buildings.roboticsfactory == undefined) {
  179. document.getElementById("btnBuildRoboticsFactory").innerHTML = `<div style="color:lime;" onclick="buildBuilding('roboticsfactory')">Build building</div>`;
  180. r = roboticsfactoryCost(1);
  181. t = constructionTime(r, 1);
  182. resrourcesHtml = printResources(r);
  183. document.getElementById("roboticsfactoryResources").innerHTML = resrourcesHtml.html + `
  184. <br>
  185. Construction time: ` + secondsToTime(t);
  186. } else {
  187. document.getElementById("roboticsfactoryLevel").innerHTML = "(Level " + planet.Buildings.roboticsfactory + ")";
  188. document.getElementById("btnBuildRoboticsFactory").innerHTML = `<div style="color:lime;" onclick="buildBuilding('roboticsfactory')">Build level ` + (+ (planet.Buildings.roboticsfactory) + + (1)) + `</div>`;
  189. r = roboticsfactoryCost((+ (planet.Buildings.roboticsfactory) + + (1)));
  190. t = constructionTime(r, (+ (planet.Buildings.roboticsfactory) + + (1)));
  191. resrourcesHtml = printResources(r);
  192. document.getElementById("roboticsfactoryResources").innerHTML = resrourcesHtml.html + `
  193. <br>
  194. Construction time: ` + secondsToTime(t);
  195. }
  196. if (!resrourcesHtml.enough) {
  197. document.getElementById("btnBuildRoboticsFactory").innerHTML = `<span style="color: red;">not enough resources</span>`;
  198. }
  199. if (planet.CurrentBuild.Title !== "") {
  200. document.getElementById("btnBuildRoboticsFactory").innerHTML = `<span style="color: red;">building</span>`;
  201. }
  202. // shipyard
  203. if (planet.Buildings.shipyard == undefined) {
  204. document.getElementById("btnBuildShipyard").innerHTML = `<div style="color:lime;" onclick="buildBuilding('shipyard')">Build building</div>`;
  205. r = shipyardCost(1);
  206. t = constructionTime(r, 1);
  207. resrourcesHtml = printResources(r);
  208. document.getElementById("shipyardResources").innerHTML = resrourcesHtml.html + `
  209. <br>
  210. Construction time: ` + secondsToTime(t);
  211. } else {
  212. document.getElementById("shipyardLevel").innerHTML = "(Level " + planet.Buildings.shipyard + ")";
  213. document.getElementById("btnBuildShipyard").innerHTML = `<div style="color:lime;" onclick="buildBuilding('shipyard')">Build level ` + (+ (planet.Buildings.shipyard) + + (1)) + `</div>`;
  214. r = shipyardCost((+ (planet.Buildings.shipyard) + + (1)));
  215. t = constructionTime(r, (+ (planet.Buildings.shipyard) + + (1)));
  216. resrourcesHtml = printResources(r);
  217. document.getElementById("shipyardResources").innerHTML = resrourcesHtml.html + `
  218. <br>
  219. Construction time: ` + secondsToTime(t);
  220. }
  221. if (!resrourcesHtml.enough) {
  222. document.getElementById("btnBuildShipyard").innerHTML = `<span style="color: red;">not enough resources</span>`;
  223. }
  224. if (planet.CurrentBuild.Title !== "") {
  225. document.getElementById("btnBuildShipyard").innerHTML = `<span style="color: red;">building</span>`;
  226. }
  227. // metalstorage
  228. if (planet.Buildings.metalstorage == undefined) {
  229. document.getElementById("btnBuildMetalStorage").innerHTML = `<div style="color:lime;" onclick="buildBuilding('metalstorage')">Build building</div>`;
  230. r = metalstorageCost(1);
  231. t = constructionTime(r, 1);
  232. resrourcesHtml = printResources(r);
  233. document.getElementById("metalstorageResources").innerHTML = resrourcesHtml.html + `
  234. <br>
  235. Construction time: ` + secondsToTime(t);
  236. } else {
  237. document.getElementById("metalstorageLevel").innerHTML = "(Level " + planet.Buildings.metalstorage + ")";
  238. document.getElementById("btnBuildMetalStorage").innerHTML = `<div style="color:lime;" onclick="buildBuilding('metalstorage')">Build level ` + (+ (planet.Buildings.metalstorage) + + (1)) + `</div>`;
  239. r = metalstorageCost((+ (planet.Buildings.metalstorage) + + (1)));
  240. t = constructionTime(r, (+ (planet.Buildings.metalstorage) + + (1)));
  241. resrourcesHtml = printResources(r);
  242. document.getElementById("metalstorageResources").innerHTML = resrourcesHtml.html + `
  243. <br>
  244. Construction time: ` + secondsToTime(t);
  245. }
  246. if (!resrourcesHtml.enough) {
  247. document.getElementById("btnBuildMetalStorage").innerHTML = `<span style="color: red;">not enough resources</span>`;
  248. }
  249. if (planet.CurrentBuild.Title !== "") {
  250. document.getElementById("btnBuildMetalStorage").innerHTML = `<span style="color: red;">building</span>`;
  251. }
  252. // crystalstorage
  253. if (planet.Buildings.crystalstorage == undefined) {
  254. document.getElementById("btnBuildCrystalStorage").innerHTML = `<div style="color:lime;" onclick="buildBuilding('crystalstorage')">Build building</div>`;
  255. r = crystalstorageCost(1);
  256. t = constructionTime(r, 1);
  257. resrourcesHtml = printResources(r);
  258. document.getElementById("crystalstorageResources").innerHTML = resrourcesHtml.html + `
  259. <br>
  260. Construction time: ` + secondsToTime(t);
  261. } else {
  262. document.getElementById("crystalstorageLevel").innerHTML = "(Level " + planet.Buildings.crystalstorage + ")";
  263. document.getElementById("btnBuildCrystalStorage").innerHTML = `<div style="color:lime;" onclick="buildBuilding('crystalstorage')">Build level ` + (+ (planet.Buildings.crystalstorage) + + (1)) + `</div>`;
  264. r = crystalstorageCost((+ (planet.Buildings.crystalstorage) + + (1)));
  265. t = constructionTime(r, (+ (planet.Buildings.crystalstorage) + + (1)));
  266. resrourcesHtml = printResources(r);
  267. document.getElementById("crystalstorageResources").innerHTML = resrourcesHtml.html + `
  268. <br>
  269. Construction time: ` + secondsToTime(t);
  270. }
  271. if (!resrourcesHtml.enough) {
  272. document.getElementById("btnBuildCrystalStorage").innerHTML = `<span style="color: red;">not enough resources</span>`;
  273. }
  274. if (planet.CurrentBuild.Title !== "") {
  275. document.getElementById("btnBuildCrystalStorage").innerHTML = `<span style="color: red;">building</span>`;
  276. }
  277. // deuteriumstorage
  278. if (planet.Buildings.deuteriumstorage == undefined) {
  279. document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<div style="color:lime;" onclick="buildBuilding('deuteriumstorage')">Build building</div>`;
  280. r = deuteriumstorageCost(1);
  281. t = constructionTime(r, 1);
  282. resrourcesHtml = printResources(r);
  283. document.getElementById("deuteriumstorageResources").innerHTML = resrourcesHtml.html + `
  284. <br>
  285. Construction time: ` + secondsToTime(t);
  286. } else {
  287. document.getElementById("deuteriumstorageLevel").innerHTML = "(Level " + planet.Buildings.deuteriumstorage + ")";
  288. document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<div style="color:lime;" onclick="buildBuilding('deuteriumstorage')">Build level ` + (+ (planet.Buildings.deuteriumstorage) + + (1)) + `</div>`;
  289. r = deuteriumstorageCost((+ (planet.Buildings.deuteriumstorage) + + (1)));
  290. t = constructionTime(r, (+ (planet.Buildings.deuteriumstorage) + + (1)));
  291. resrourcesHtml = printResources(r);
  292. document.getElementById("deuteriumstorageResources").innerHTML = resrourcesHtml.html + `
  293. <br>
  294. Construction time: ` + secondsToTime(t);
  295. }
  296. if (!resrourcesHtml.enough) {
  297. document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<span style="color: red;">not enough resources</span>`;
  298. }
  299. if (planet.CurrentBuild.Title !== "") {
  300. document.getElementById("btnBuildDeuteriumStorage").innerHTML = `<span style="color: red;">building</span>`;
  301. }
  302. // ressearchlab
  303. if (planet.Buildings.ressearchlab == undefined) {
  304. document.getElementById("btnBuildRessearchLab").innerHTML = `<div style="color:lime;" onclick="buildBuilding('ressearchlab')">Build building</div>`;
  305. r = ressearchlabCost(1);
  306. t = constructionTime(r, 1);
  307. resrourcesHtml = printResources(r);
  308. document.getElementById("ressearchlabResources").innerHTML = resrourcesHtml.html + `
  309. <br>
  310. Construction time: ` + secondsToTime(t);
  311. } else {
  312. document.getElementById("ressearchlabLevel").innerHTML = "(Level " + planet.Buildings.ressearchlab + ")";
  313. document.getElementById("btnBuildRessearchLab").innerHTML = `<div style="color:lime;" onclick="buildBuilding('ressearchlab')">Build level ` + (+ (planet.Buildings.ressearchlab) + + (1)) + `</div>`;
  314. r = ressearchlabCost((+ (planet.Buildings.ressearchlab) + + (1)));
  315. t = constructionTime(r, (+ (planet.Buildings.ressearchlab) + + (1)));
  316. resrourcesHtml = printResources(r);
  317. document.getElementById("ressearchlabResources").innerHTML = resrourcesHtml.html + `
  318. <br>
  319. Construction time: ` + secondsToTime(t);
  320. }
  321. if (!resrourcesHtml.enough) {
  322. document.getElementById("btnBuildRessearchLab").innerHTML = `<span style="color: red;">not enough resources</span>`;
  323. }
  324. if (planet.CurrentBuild.Title !== "") {
  325. document.getElementById("btnBuildRessearchLab").innerHTML = `<span style="color: red;">building</span>`;
  326. }
  327. // alliancedepot
  328. if (planet.Buildings.alliancedepot == undefined) {
  329. document.getElementById("btnBuildAllianceDepot").innerHTML = `<div style="color:lime;" onclick="buildBuilding('alliancedepot')">Build building</div>`;
  330. r = alliancedepotCost(1);
  331. t = constructionTime(r, 1);
  332. resrourcesHtml = printResources(r);
  333. document.getElementById("alliancedepotResources").innerHTML = resrourcesHtml.html + `
  334. <br>
  335. Construction time: ` + secondsToTime(t);
  336. } else {
  337. document.getElementById("alliancedepotLevel").innerHTML = "(Level " + planet.Buildings.alliancedepot + ")";
  338. document.getElementById("btnBuildAllianceDepot").innerHTML = `<div style="color:lime;" onclick="buildBuilding('alliancedepot')">Build level ` + (+ (planet.Buildings.alliancedepot) + + (1)) + `</div>`;
  339. r = alliancedepotCost((+ (planet.Buildings.alliancedepot) + + (1)));
  340. t = constructionTime(r, (+ (planet.Buildings.alliancedepot) + + (1)));
  341. resrourcesHtml = printResources(r);
  342. document.getElementById("alliancedepotResources").innerHTML = resrourcesHtml.html + `
  343. <br>
  344. Construction time: ` + secondsToTime(t);
  345. }
  346. if (!resrourcesHtml.enough) {
  347. document.getElementById("btnBuildAllianceDepot").innerHTML = `<span style="color: red;">not enough resources</span>`;
  348. }
  349. if (planet.CurrentBuild.Title !== "") {
  350. document.getElementById("btnBuildAllianceDepot").innerHTML = `<span style="color: red;">building</span>`;
  351. }
  352. // missilesilo
  353. if (planet.Buildings.missilesilo == undefined) {
  354. document.getElementById("btnBuildMissileSilo").innerHTML = `<div style="color:lime;" onclick="buildBuilding('missilesilo')">Build building</div>`;
  355. r = missilesiloCost(1);
  356. t = constructionTime(r, 1);
  357. resrourcesHtml = printResources(r);
  358. document.getElementById("missilesiloResources").innerHTML = resrourcesHtml.html + `
  359. <br>
  360. Construction time: ` + secondsToTime(t);
  361. } else {
  362. document.getElementById("missilesiloLevel").innerHTML = "(Level " + planet.Buildings.missilesilo + ")";
  363. document.getElementById("btnBuildMissileSilo").innerHTML = `<div style="color:lime;" onclick="buildBuilding('missilesilo')">Build level ` + (+ (planet.Buildings.missilesilo) + + (1)) + `</div>`;
  364. r = missilesiloCost((+ (planet.Buildings.missilesilo) + + (1)));
  365. t = constructionTime(r, (+ (planet.Buildings.missilesilo) + + (1)));
  366. resrourcesHtml = printResources(r);
  367. document.getElementById("missilesiloResources").innerHTML = resrourcesHtml.html + `
  368. <br>
  369. Construction time: ` + secondsToTime(t);
  370. }
  371. if (!resrourcesHtml.enough) {
  372. document.getElementById("btnBuildMissileSilo").innerHTML = `<span style="color: red;">not enough resources</span>`;
  373. }
  374. if (planet.CurrentBuild.Title !== "") {
  375. document.getElementById("btnBuildMissileSilo").innerHTML = `<span style="color: red;">building</span>`;
  376. }
  377. // spacedock
  378. if (planet.Buildings.spacedock == undefined) {
  379. document.getElementById("btnBuildSpacedock").innerHTML = `<div style="color:lime;" onclick="buildBuilding('spacedock')">Build building</div>`;
  380. r = spacedockCost(1);
  381. t = constructionTime(r, 1);
  382. resrourcesHtml = printResources(r);
  383. document.getElementById("spacedockResources").innerHTML = resrourcesHtml.html + `
  384. <br>
  385. Construction time: ` + secondsToTime(t);
  386. } else {
  387. document.getElementById("spacedockLevel").innerHTML = "(Level " + planet.Buildings.spacedock + ")";
  388. document.getElementById("btnBuildSpacedock").innerHTML = `<div style="color:lime;" onclick="buildBuilding('spacedock')">Build level ` + (+ (planet.Buildings.spacedock) + + (1)) + `</div>`;
  389. r = spacedockCost((+ (planet.Buildings.spacedock) + + (1)));
  390. t = constructionTime(r, (+ (planet.Buildings.spacedock) + + (1)));
  391. resrourcesHtml = printResources(r);
  392. document.getElementById("spacedockResources").innerHTML = resrourcesHtml.html + `
  393. <br>
  394. Construction time: ` + secondsToTime(t);
  395. }
  396. if (!resrourcesHtml.enough) {
  397. document.getElementById("btnBuildSpacedock").innerHTML = `<span style="color: red;">not enough resources</span>`;
  398. }
  399. if (planet.CurrentBuild.Title !== "") {
  400. document.getElementById("btnBuildSpacedock").innerHTML = `<span style="color: red;">building</span>`;
  401. }
  402. }
  403. let planetid = localStorage.getItem("mainplanet");
  404. let planet = {};
  405. // get user data
  406. function getPlanet() {
  407. axios.get(url + "/planets/" + planetid, config).then(function(res) {
  408. console.log("buildings", res.data);
  409. planet = res.data.planet;
  410. printPlanet(planet);
  411. }).catch(function(error) {
  412. console.log(error);
  413. });
  414. }
  415. getPlanet();
  416. setInterval(getPlanet, 5000);
  417. function buildBuilding(building) {
  418. console.log("build " + building);
  419. const data = {
  420. planetid: planetid,
  421. building: building
  422. }
  423. axios.post(url + "/buildings", data, config).then(function(res) {
  424. console.log("buildings", res.data);
  425. planet = res.data.planet;
  426. printPlanet(planet);
  427. }).catch(function(error) {
  428. console.log(error);
  429. });
  430. }