Planets.nu - Extended History Graphs Plugin

Adds graphs to plot histories for ships and bases to NEW planets.nu. Also adds new game speed display based on the turn of reaching the ship limit. Pie charts are also added back in, but not final.

  1. // ==UserScript==
  2. // @name Planets.nu - Extended History Graphs Plugin
  3. // @namespace Planets.nu
  4. // @description Adds graphs to plot histories for ships and bases to NEW planets.nu. Also adds new game speed display based on the turn of reaching the ship limit. Pie charts are also added back in, but not final.
  5. // @include http://planets.nu/*
  6. // @include http://play.planets.nu/*
  7. // @include http://test.planets.nu/*
  8. // @resource userscript https://greasyfork.org/en/scripts/12315-planets-nu-extended-history-graphs-plugin
  9. // @homepage http://planets.nu/discussion/utility-script-extended-plots-for-game-page
  10. // @author kedalion
  11. // @version 0.61
  12. // ==/UserScript==
  13.  
  14. /* -----------------------------------------------------------------------
  15. Change log:
  16. 0.61
  17. - Moved script location to greasyfork.org [2015-09-09]
  18. 0.6
  19. - Moved script location to monkeyguts.com [2014-05-30]
  20. v0.53
  21. - fixed path inclusion for panets.nu (without play or test)
  22. v0.5
  23. - fixed compatibility issues planets.nu due to cross domain CSS sheet inclusion
  24. v0.4
  25. - compatible with NEW version of planets.nu (also formerly play.planets.nu)
  26. - removed pbp graphs (can be easily readded if wanted--> feedback)
  27. - added a new graph showing history of total number of ships with comparison to typical games of same type
  28. - added pie charts back for new planets.nu UI. (preliminary)
  29. v0.3
  30. - adjusted script to work with Game Data Alliance Addon
  31. v0.2
  32. - added bases, ships, and pbps graphs
  33. ----------------------------------------------------------------------- */
  34.  
  35. function exec(fn) {
  36. var script = document.createElement('script');
  37. script.setAttribute("type", "application/javascript");
  38. script.textContent = '(' + wrapper + ')(); (' + fn + ')();';
  39. document.body.appendChild(script);
  40. document.body.removeChild(script);
  41. };
  42.  
  43. exec(function() {
  44.  
  45. //resize tabs in game detail page
  46. console.log("Creating space in game menu.");
  47. var css_success = nu.adjustCSS();
  48. console.log("Inserting new tabs in game menu.");
  49. if (css_success) {
  50.  
  51. html_menu_section = "<ul id=\"etabs\"> <li id=\"eplayers\" data-tab=\"\"> {{t.players}} </li> <li id=\"eactivity\" data-tab=\"/activity\"> {{t.activity}} </li> <li id=\"eallies\" data-tab=\"/allies\"> {{t.allies}} </li> <li id=\"eplanets\" data-tab=\"/planets\"> {{t.planets}} </li> <li id=\"emilitary\" data-tab=\"/military\"> {{t.military}} </li> <li id=\"edata\" data-tab=\"/data\"> {{t.data}} </li> <li id=\"eevents\" data-tab=\"/events\"> {{t.events}} </li> <li id=\"eships\" data-tab=\"/ships\"> Ships </li><li id=\"ebases\" data-tab=\"/bases\"> Bases </li><li id=\"egamespeed\" data-tab=\"/gamespeed\"> Speed </li><li id=\"epiemilitary\" data-tab=\"/piemilitary\"> M-Pie </li><li id=\"epieplanets\" data-tab=\"/pieplanets\"> P-Pie </li> </ul>";
  52. } else {
  53. html_menu_section = "<ul id=\"etabs\"> <li id=\"eplayers\" data-tab=\"\" style=\"width:60px\"> {{t.players}} </li> <li id=\"eactivity\" data-tab=\"/activity\" style=\"width:60px\"> {{t.activity}} </li> <li id=\"eallies\" data-tab=\"/allies\" style=\"width:60px\"> {{t.allies}} </li> <li id=\"eplanets\" data-tab=\"/planets\" style=\"width:60px\"> {{t.planets}} </li> <li id=\"emilitary\" data-tab=\"/military\" style=\"width:60px\"> {{t.military}} </li> <li id=\"edata\" data-tab=\"/data\" style=\"width:60px\"> {{t.data}} </li> <li id=\"eevents\" data-tab=\"/events\" style=\"width:60px\"> {{t.events}} </li> <li id=\"eships\" data-tab=\"/ships\" style=\"width:60px\"> Ships </li><li id=\"ebases\" data-tab=\"/bases\" style=\"width:60px\"> Bases </li><li id=\"egamespeed\" data-tab=\"/gamespeed\" style=\"width:60px\"> Speed </li><li id=\"epiemilitary\" data-tab=\"/piemilitary\" style=\"width:60px\"> M-Pie </li><li id=\"epieplanets\" data-tab=\"/pieplanets\" style=\"width:60px\"> P-Pie </li> </ul>";
  54.  
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. html_start = "<div id=\"GameContent\"> <img id=\"egamelocmap\" src=\"http://play.planets.nu/img/maps/1000.png\" /> <div id=\"egameinfo\"> <div id=\"egamecircle\"></div> <div class=\"GameInfoTurn\">{{t.turn}} <b>{{game.turn}}</b> - {{timetohost}}</div> {{#ishost}}<div id=\"ehostcontrols\">{{t.host}}: <span id=\"eeditgame\">{{t.edit}}</span><span id=\"epausegame\">{{pausetext}}</span><span id=\"edeletegame\">{{t.del}}</span></div>{{/ishost}} <div class=\"GameInfoTitle\"> {{fullname}} ( {{yearfrom}} - {{yearto}} ) </div> <div class=\"SectorDescription\">{{game.description!}} <div id=\"eresources\"> <table class=\"ecleantable\"> <tr> <td> <div id=\"eneu\" class=\"evertbar\" title=\"Neutronium Level - {{settings.neutroniumlevel}}\"><span style=\"margin-top:{{mneu}}px;height:{{hneu}}px;\"></span></div> </td> <td> <div id=\"edur\" class=\"evertbar\" title=\"Duranium Level - {{settings.duraniumlevel}}\"><span style=\"margin-top:{{mdur}}px;height:{{hdur}}px;\"></span></div> </td> <td> <div id=\"etri\" class=\"evertbar\" title=\"Tritanium Level - {{settings.tritaniumlevel}}\"><span style=\"margin-top:{{mtri}}px;height:{{htri}}px;\"></span></div> </td> <td> <div id=\"emol\" class=\"evertbar\" title=\"Molybdenum Level - {{settings.molybdenumlevel}}\"><span style=\"margin-top:{{mmol}}px;height:{{hmol}}px;\"></span></div> </td> <td> <div id=\"eden\" class=\"evertbar\" title=\"Average Mineral Density - {{settings.averagedensitypercent}}%\"><span style=\"margin-top:{{mden}}px;height:{{hden}}px;\"></span></div> </td> </tr> <tr> <td> Neu </td> <td> Dur </td> <td> Tri </td> <td> Mol </td> <td> D% </td> </tr> </table> </div> <ul style=\"margin:0;padding:0;width:200px;float:right;\"> <li>{{t.planets}}: {{settings.numplanets}}</li> <li>{{t.starclusters}}: {{settings.stars}}</li> <li>{{t.nebulas}}: {{settings.nebulas}}</li> <li>{{t.debrisdisks}}: {{settings.ndebrisdiscs}}</li> <li>{{t.maxionstorms}}: {{settings.maxions}}</li> </ul> <ul> <li>{{t.battleid}}: {{game.id}}</li> <li>{{t.created}}: {{game.datecreated}}</li> {{#settings.campaignmode}} <li>{{t.campaignmodeenabled}}</li> <li>{{t.maxadvantage}}: {{settings.maxadvantage}}</li> {{/settings.campaignmode}} <li>{{t.hostdays}}: {{game.hostdays}} at {{game.hosttime}}</li> <li>{{t.wincondition}}: {{wincondition}}</li> <li>{{t.maxallies}}: {{settings.maxallies}}</li> <li>{{t.minimumrank}}: {{game.requiredlevelname}}</li> <li>{{t.maximumrank}}: {{game.maxlevelname}}</li> {{#game.iscustom}}<li>{{t.hostedby}}: <a href=\"#/account/{{game.createdby}}/hosting\" style=\"text-transform: capitalize;\">{{game.createdby}}</a></li>{{/game.iscustom}} </ul> <p>{{{game.description}}}</p> </div> <div id=\"egametabs\"> ";
  63. html_end = " </div> <div id=\"etabcontent\" class=\"etabcontent\"> </div> </div></div>";
  64.  
  65. html["GameOverview"] = html_start + html_menu_section + html_end;
  66. nu.view.show();
  67.  
  68. //console.log("Done.");
  69.  
  70.  
  71. });
  72.  
  73. function wrapper() { // wrapper for injection
  74.  
  75. Nuniverse.prototype.adjustCSS = function() {
  76. var tab_width = "60px";
  77. try {
  78. var old_rule = nu.getCSSRule("#egametabs #etabs li", false);
  79. old_rule.style.width = tab_width;
  80. //potentially also needed, but width seems overwritten by above rule
  81. //old_rule = nu.getCSSRule("#etabs li", false);
  82. //old_rule.style.width = tab_width;
  83. //console.log("CSS manipulation succeeded.");
  84. return true;
  85. } catch (err) {
  86. //console.log("CSS manipulation failed due to cross domain CSS sheet. Manual correction will be applied.");
  87. return false;
  88. }
  89. };
  90.  
  91. Nuniverse.prototype.getCSSRule = function(ruleName, deleteFlag) { // Return requested style obejct
  92. //css manipulation code from: http://www.hunlock.com/blogs/Totally_Pwn_CSS_with_Javascript
  93. //console.log("Invoked with :" + ruleName);
  94. //ruleName=ruleName.toLowerCase(); // Convert test string to lower case.
  95. if (document.styleSheets) { // If browser can play with stylesheets
  96. for (var i=0; i<document.styleSheets.length; i++) { // For each stylesheet
  97. //console.log(i);
  98. var styleSheet=document.styleSheets[i]; // Get the current Stylesheet
  99. var ii=0; // Initialize subCounter.
  100. var cssRule=false; // Initialize cssRule.
  101. var num_rules;
  102. if (styleSheet.cssRules) { // Browser uses cssRules?
  103. num_rules = styleSheet.cssRules.length; // Yes --Mozilla Style
  104. } else { // Browser usses rules?
  105. num_rules = styleSheet.rules.length; // Yes IE style.
  106. }
  107. for (var ii=0; ii<num_rules; ii++) {
  108. if (styleSheet.cssRules) { // Browser uses cssRules?
  109. cssRule = styleSheet.cssRules[ii]; // Yes --Mozilla Style
  110. } else { // Browser usses rules?
  111. cssRule = styleSheet.rules[ii]; // Yes IE style.
  112. }
  113. //console.log(i + ", " + ii + ":" + cssRule.selectorText);
  114. if (cssRule.selectorText==ruleName) { // match ruleName?
  115. if (deleteFlag=='delete') { // Yes. Are we deleteing?
  116. if (styleSheet.cssRules) { // Yes, deleting...
  117. styleSheet.deleteRule(ii); // Delete rule, Moz Style
  118. } else { // Still deleting.
  119. styleSheet.removeRule(ii); // Delete rule IE style.
  120. } // End IE check.
  121. return true; // return true, class deleted.
  122. } else { // found and not deleting.
  123. return cssRule; // return the style object.
  124. } // End delete Check
  125. }
  126.  
  127. }
  128. /*
  129. do { // For each rule in stylesheet
  130. if (styleSheet.cssRules) { // Browser uses cssRules?
  131. cssRule = styleSheet.cssRules[ii]; // Yes --Mozilla Style
  132. } else { // Browser usses rules?
  133. cssRule = styleSheet.rules[ii]; // Yes IE style.
  134. } // End IE check.
  135. if (cssRule) { // If we found a rule...
  136. if (cssRule.selectorText==ruleName) { // match ruleName?
  137. if (deleteFlag=='delete') { // Yes. Are we deleteing?
  138. if (styleSheet.cssRules) { // Yes, deleting...
  139. styleSheet.deleteRule(ii); // Delete rule, Moz Style
  140. } else { // Still deleting.
  141. styleSheet.removeRule(ii); // Delete rule IE style.
  142. } // End IE check.
  143. return true; // return true, class deleted.
  144. } else { // found and not deleting.
  145. return cssRule; // return the style object.
  146. } // End delete Check
  147. } // End found rule name
  148. } // end found cssRule
  149. ii++; // Increment sub-counter
  150. } while (cssRule) */ // end While loop
  151. } // end For loop
  152. } // end styleSheet ability check
  153. return false; // we found NOTHING!
  154. }; // end getCSSRule
  155.  
  156. Nuniverse.prototype.killCSSRule = function(ruleName) { // Delete a CSS rule
  157. return getCSSRule(ruleName,'delete'); // just call getCSSRule w/delete flag.
  158. }; // end killCSSRule
  159.  
  160. Nuniverse.prototype.addCSSRule = function(ruleName) { // Create a new css rule
  161. if (document.styleSheets) { // Can browser do styleSheets?
  162. if (!getCSSRule(ruleName)) { // if rule doesn't exist...
  163. if (document.styleSheets[0].addRule) { // Browser is IE?
  164. document.styleSheets[0].addRule(ruleName, null,0); // Yes, add IE style
  165. } else { // Browser is IE?
  166. document.styleSheets[0].insertRule(ruleName+' { }', 0); // Yes, add Moz style.
  167. } // End browser check
  168. } // End already exist check.
  169. } // End browser ability check.
  170. return getCSSRule(ruleName); // return rule we just created.
  171. };
  172.  
  173.  
  174.  
  175. ViewGame.prototype.show = function() {
  176.  
  177. //show this screen
  178. //empty the content area
  179. nu.frame.content.empty();
  180.  
  181. var gameid = nu.view.parseGameId();
  182.  
  183. if (!nu.data.games["game" + gameid]) {
  184. nu.api.loadGameInfo(gameid);
  185. return;
  186. }
  187.  
  188. var data = nu.data.games["game" + gameid];
  189. nu.view.massageGameData(data);
  190.  
  191. //load the screen
  192. var screen = html.get("GameOverview", data).appendTo(nu.frame.content);
  193. screen.tabs.find("li").tclick(function () { window.location = "#/sector/" + gameid + $(this).data("tab"); });
  194.  
  195. if (data.ishost) {
  196. screen.deletegame.tclick(function () {
  197. nu.confirm("Are you sure you want to delete this game?", function () {
  198. nu.confirm("<b style='color:#ff6600;'>This is a live running game. Are you sure?</b>", function () {
  199. nu.api.deleteGame(data.game.id, function () {
  200. window.location = nu.getPlayerPath(nu.data.account.username) + "/hosting";
  201. });
  202. });
  203. });
  204. });
  205. screen.pausegame.tclick(function () { nu.api.pauseGame(data.game.id); });
  206. screen.editgame.tclick(function () {
  207.  
  208. data.game.days = [{ day: "Sunday" }, { day: "Monday" }, { day: "Tuesday" }, { day: "Wednesday" }, { day: "Thursday" }, { day: "Friday" }, { day: "Saturday" }];
  209. for (var i = 0; i < data.game.hostdays.length; i++) {
  210. var ch = data.game.hostdays[i];
  211. if (ch != "_")
  212. data.game.days[i].selected = true;
  213. data.game.days[i].index = i + 1;
  214. }
  215. var win = html.get("EditGame", data.game);
  216. nu.modal(win, "Edit Game", "800px");
  217. win.cancel.tclick(nu.closemodal);
  218. win.save.tclick(function () {
  219.  
  220. var settings = {};
  221. settings.name = win.gamename.val();
  222. settings.description = win.gamedescription.val();
  223. settings.hosttime = win.hosttime.val();
  224. settings.password = win.gamepassword.val();
  225. settings.nexthost = win.nexthost.val();
  226. settings.isprivate = !win.ispublic.is(":checked");
  227.  
  228. var days = ["", "S", "M", "T", "W", "T", "F", "S"];
  229. var hostdays = "";
  230. for (var i = 1; i <= 7; i++) {
  231. if ($("#HostDay" + i).is(':checked'))
  232. hostdays += days[i];
  233. else
  234. hostdays += "_";
  235. }
  236. settings.hostdays = hostdays;
  237.  
  238. nu.api.updateGame(gameid, settings);
  239. nu.closemodal();
  240. });
  241. });
  242. }
  243.  
  244. nu.view.positionMap(screen, data);
  245.  
  246. //direct load subscreens
  247. if (window.location.hash.indexOf("/activity") > 0) {
  248. screen.activity.addClass("eselected");
  249. nu.view.showActivity(screen, data, gameid);
  250. return;
  251. }
  252. else if (window.location.hash.indexOf("/allies") > 0) {
  253. screen.allies.addClass("eselected");
  254. nu.view.showAllies(screen, data);
  255. return;
  256. }
  257. else if (window.location.hash.indexOf("/planets") > 0) {
  258. screen.planets.addClass("eselected");
  259. nu.view.showPlanets(screen, data);
  260. return;
  261. }
  262. else if (window.location.hash.indexOf("/military") > 0) {
  263. screen.military.addClass("eselected");
  264. nu.view.showMilitary(screen, data);
  265. return;
  266. }
  267. else if (window.location.hash.indexOf("/data") > 0) {
  268. screen.data.addClass("eselected");
  269. nu.view.showData(screen, data);
  270. return;
  271. }
  272. else if (window.location.hash.indexOf("/events") > 0) {
  273. screen.events.addClass("eselected");
  274. nu.view.showEvents(screen, data);
  275. return;
  276. }
  277. else if (window.location.hash.indexOf("/ships") > 0) {
  278. screen.ships.addClass("eselected");
  279. nu.view.showShips(screen, data);
  280. return;
  281. }
  282. else if (window.location.hash.indexOf("/bases") > 0) {
  283. screen.bases.addClass("eselected");
  284. nu.view.showBases(screen, data);
  285. return;
  286. }
  287. else if (window.location.hash.indexOf("/gamespeed") > 0) {
  288. screen.gamespeed.addClass("eselected");
  289. nu.view.showGamespeed(screen, data);
  290. return;
  291. }
  292. else if (window.location.hash.indexOf("/piemilitary") > 0) {
  293. screen.piemilitary.addClass("eselected");
  294. nu.view.showMilitaryPie(screen, data);
  295. //console.log("Here");
  296. return;
  297. }
  298. else if (window.location.hash.indexOf("/pieplanets") > 0) {
  299. screen.pieplanets.addClass("eselected");
  300. nu.view.showPlanetsPie(screen, data);
  301. return;
  302. }
  303.  
  304.  
  305.  
  306. screen.players.addClass("eselected");
  307. nu.view.showPlayers(screen, data);
  308.  
  309.  
  310. };
  311.  
  312. ViewGame.prototype.scoresToScoreData = function (data) {
  313. var bases = new Array();
  314. var ships = new Array();
  315. var labels = new Array();
  316. var slots = data.game.slots;
  317. var turns = data.game.turn;
  318. labels.push("Turn");
  319. //get player names and entries
  320. for (var i=0; i<slots; i++) {
  321. labels.push(data.scores[i].name);
  322. }
  323. bases.push(labels);
  324. ships.push(labels);
  325. //start reading in all the scores
  326. for (var t=1; t<=turns; t++) {
  327. var ship_turn = new Array();
  328. ship_turn.push(t);
  329. var base_turn = new Array();
  330. base_turn.push(t);
  331. for (var s=1; s<=slots; s++) {
  332. var index = (t-1) * slots + (s - 1);
  333. base_turn.push(data.scores[index].starbases);
  334. ship_turn.push(data.scores[index].capitalships + data.scores[index].freighters);
  335. }
  336. bases.push(base_turn);
  337. ships.push(ship_turn);
  338. }
  339. data.game.scoredata.bases = bases;
  340. data.game.scoredata.ships = ships;
  341. //console.log("Test");
  342. }
  343.  
  344. ViewGame.prototype.showBases = function (screen, data) {
  345.  
  346. if (data.game.turn <= 1) {
  347. $("<div style='padding:30px;'>Game has not started yet.</div>").appendTo(screen.tabcontent);
  348. return;
  349. }
  350.  
  351. if (!data.game.scoredata) {
  352. nu.api.loadScoreData(data.game);
  353. return;
  354. }
  355. if (!data.scores) {
  356. nu.api.loadGameScores(data.game.id);
  357. return;
  358. }
  359. if (!data.game.scoredata.bases) {
  360. nu.view.scoresToScoreData(data);
  361. }
  362.  
  363. $("<div id='echartdisplay'></div>").appendTo(screen.tabcontent);
  364.  
  365.  
  366. var data = google.visualization.arrayToDataTable(data.game.scoredata.bases);
  367.  
  368. // Create and draw the visualization.
  369. new google.visualization.LineChart(document.getElementById("echartdisplay")).draw(data,
  370. {
  371. chartArea:{left:30,top:20,width:"75%",height:"90%"},
  372. legend: { position: "right", textStyle: { color: '#fff', fontSize: 11 } },
  373. lineWidth: 4,
  374. pointSize: 2,
  375. width: 1000,
  376. height: 600,
  377. backgroundColor: "transparent",
  378. hAxis: { textStyle: { color: '#fff', fontSize: 13 }, gridlines: { color: '#444', count: 4 } },
  379. vAxis: { textStyle: { color: '#fff', fontSize: 13 }, gridlines: { color: '#444', count: 4 } }
  380. }
  381. );
  382. };
  383. ViewGame.prototype.showShips = function (screen, data) {
  384.  
  385. if (data.game.turn <= 1) {
  386. $("<div style='padding:30px;'>Game has not started yet.</div>").appendTo(screen.tabcontent);
  387. return;
  388. }
  389.  
  390. if (!data.game.scoredata) {
  391. nu.api.loadScoreData(data.game);
  392. return;
  393. }
  394. if (!data.scores) {
  395. nu.api.loadGameScores(data.game.id);
  396. return;
  397. }
  398. if (!data.game.scoredata.ships) {
  399. nu.view.scoresToScoreData(data);
  400. }
  401.  
  402. $("<div id='echartdisplay'></div>").appendTo(screen.tabcontent);
  403.  
  404.  
  405. var data = google.visualization.arrayToDataTable(data.game.scoredata.ships);
  406.  
  407. // Create and draw the visualization.
  408. new google.visualization.LineChart(document.getElementById("echartdisplay")).draw(data,
  409. {
  410. chartArea:{left:30,top:20,width:"75%",height:"90%"},
  411. legend: { position: "right", textStyle: { color: '#fff', fontSize: 11 } },
  412. lineWidth: 4,
  413. pointSize: 2,
  414. width: 1000,
  415. height: 600,
  416. backgroundColor: "transparent",
  417. hAxis: { textStyle: { color: '#fff', fontSize: 13 }, gridlines: { color: '#444', count: 4 } },
  418. vAxis: { textStyle: { color: '#fff', fontSize: 13 }, gridlines: { color: '#444', count: 4 } }
  419. }
  420. );
  421. };
  422. ViewGame.prototype.loadSpeedData = function(data) {
  423. //console.log("Calculating speed data");
  424. var speedDataGames = [[38553, 1001, 55866], [43890, 42421, 53007], [33817, 43835, 43387]];
  425. var type_index = data.game.gametype - 2;
  426. //treat championship games as standard games here
  427. if (data.game.gametype == 6)
  428. type_index = 0;
  429. var requested = false;
  430. for (var i=0; i<3; i++) {
  431. var game_name = "game" + speedDataGames[type_index][i];
  432. //console.log("Iter: " + i + " name: " + game_name + ".");
  433. if (!nu.data.games[game_name]) {
  434. nu.api.loadGameInfo(speedDataGames[type_index][i]);
  435. requested = true;
  436. }
  437. // console.log("y");
  438. }
  439. if (requested)
  440. return;
  441. for (var i=0; i<3; i++) {
  442. var game_name = "game" + speedDataGames[type_index][i];
  443. //console.log("Iter2: " + i + " name: " + game_name + ".");
  444. if (!nu.data.games[game_name].scores) {
  445. nu.api.loadGameScores(speedDataGames[type_index][i]);
  446. // console.log("X");
  447. requested = true;
  448. }
  449. //console.log("x");
  450. }
  451. if (requested)
  452. return;
  453. //now build the arrays of ship counts
  454. var ships = new Array();
  455. var labels = new Array();
  456. labels.push("Turn");
  457. labels.push("Fastest game: " + nu.data.games["game" + speedDataGames[type_index][0]].game.name + " (" + nu.data.games["game" + speedDataGames[type_index][0]].game.id + ")");
  458. labels.push("Median speed game: " + nu.data.games["game" + speedDataGames[type_index][1]].game.name + " (" + nu.data.games["game" + speedDataGames[type_index][1]].game.id + ")");
  459. labels.push("Slowest game: " + nu.data.games["game" + speedDataGames[type_index][2]].game.name + " (" + nu.data.games["game" + speedDataGames[type_index][2]].game.id + ")");
  460. labels.push("Current game: " + data.game.name);
  461. labels.push("Ship limit 500");
  462. ships.push(labels);
  463. //var slots = data.game.slots;
  464. var turns = data.game.turn;
  465. var games = new Array();
  466. games.push(speedDataGames[type_index][0]);
  467. games.push(speedDataGames[type_index][1]);
  468. games.push(speedDataGames[type_index][2]);
  469. games.push(data.game.id);
  470. //start reading in all the scores for game and references
  471. for (var t=1; t<=turns; t++) {
  472. var ship_turn = new Array();
  473. ship_turn.push(t);
  474. //loop over games in array
  475. for (var g=0; g<games.length; g++) {
  476. var slots = nu.data.games["game"+games[g]].game.slots;
  477. var ships_sum = 0;
  478. if (t > nu.data.games["game"+games[g]].game.turn) {
  479. ship_turn.push(500);
  480. }
  481. else {
  482. for (var s=1; s<=slots; s++) {
  483. var index = (t-1) * slots + (s - 1);
  484. ships_sum += nu.data.games["game"+games[g]].scores[index].capitalships + nu.data.games["game"+games[g]].scores[index].freighters;
  485. }
  486. ship_turn.push(ships_sum);
  487. }
  488. }
  489. ship_turn.push(500);
  490. ships.push(ship_turn);
  491. }
  492. data.speeddata = ships;
  493. //console.log("Done creating speeddata");
  494. }
  495.  
  496. ViewGame.prototype.showGamespeed = function (screen, data) {
  497.  
  498. if (data.game.turn <= 1) {
  499. $("<div style='padding:30px;'>Game has not started yet.</div>").appendTo(screen.tabcontent);
  500. return;
  501. }
  502. if (data.game.gametype < 2 || (data.game.gametype > 4 && data.game.gametype != 6)) { //championship games like standard
  503. $("<div style='padding:30px;'>Gametype not supported yet.</div>").appendTo(screen.tabcontent);
  504. return;
  505. }
  506. if (!data.scores) {
  507. nu.api.loadGameScores(data.game.id);
  508. return;
  509. }
  510. //console.log("Check for speed data");
  511. if (!data.speeddata) {
  512. nu.view.loadSpeedData(data);
  513. return;
  514. }
  515. //console.log("there should be a graph soon...");
  516. // if (!nu.data.speeddata) {
  517. // nu.view.scoresToSpeedData(data);
  518. // }
  519.  
  520. // if (!data.speeddata)
  521. // console.log("I see the data.");
  522.  
  523.  
  524. $("<div id='echartdisplay'></div>").appendTo(screen.tabcontent);
  525.  
  526.  
  527. var data = google.visualization.arrayToDataTable(data.speeddata);
  528.  
  529. // Create and draw the visualization.
  530. new google.visualization.LineChart(document.getElementById("echartdisplay")).draw(data,
  531. {
  532. chartArea:{left:30,top:20,width:"75%",height:"90%"},
  533. legend: { position: "right", textStyle: { color: '#fff', fontSize: 11 } },
  534. lineWidth: 4,
  535. pointSize: 2,
  536. width: 1000,
  537. height: 600,
  538. backgroundColor: "transparent",
  539. hAxis: { textStyle: { color: '#fff', fontSize: 13 }, gridlines: { color: '#444', count: 4 } },
  540. vAxis: { textStyle: { color: '#fff', fontSize: 13 }, gridlines: { color: '#444', count: 4 } }
  541. }
  542. );
  543. //console.log("Done: there should be a graph now...");
  544. };
  545.  
  546.  
  547. ViewGame.prototype.showMilitaryPie = function (screen, data) {
  548.  
  549. if (data.game.turn <= 1) {
  550. $("<div style='padding:30px;'>Game has not started yet.</div>").appendTo(screen.tabcontent);
  551. return;
  552. }
  553. if (!data.scores) {
  554. nu.api.loadGameScores(data.game.id);
  555. return;
  556. }
  557. var military_pie_data = new Array();
  558. var row = new Array();
  559. row.push("Player");
  560. row.push("Military Percentage");
  561. military_pie_data.push(row);
  562. for (var s=1; s<=data.game.slots; s++) {
  563. row = new Array();
  564. var index = (data.game.turn-1) * data.game.slots + (s - 1);
  565. row.push(data.scores[index].name);
  566. row.push(data.scores[index].percent);
  567. military_pie_data.push(row);
  568. }
  569. $("<div id='echartdisplay'></div>").appendTo(screen.tabcontent);
  570.  
  571. var data = google.visualization.arrayToDataTable(military_pie_data);
  572.  
  573. // Create and draw the visualization.
  574. new google.visualization.PieChart(document.getElementById("echartdisplay")).draw(data,
  575. {
  576. chartArea:{left:330,top:20,width:"75%",height:"90%"},
  577. legend: { position: "right", textStyle: { color: '#fff', fontSize: 11 } },
  578. lineWidth: 4,
  579. pointSize: 2,
  580. width: 1000,
  581. height: 600,
  582. backgroundColor: "transparent",
  583. hAxis: { textStyle: { color: '#fff', fontSize: 13 }, gridlines: { color: '#444', count: 4 } },
  584. vAxis: { textStyle: { color: '#fff', fontSize: 13 }, gridlines: { color: '#444', count: 4 } }
  585. }
  586. );
  587. };
  588. ViewGame.prototype.showPlanetsPie = function (screen, data) {
  589.  
  590. if (data.game.turn <= 1) {
  591. $("<div style='padding:30px;'>Game has not started yet.</div>").appendTo(screen.tabcontent);
  592. return;
  593. }
  594. if (!data.scores) {
  595. nu.api.loadGameScores(data.game.id);
  596. return;
  597. }
  598. var military_pie_data = new Array();
  599. var row = new Array();
  600. row.push("Player");
  601. row.push("Planets Owned Percentage");
  602. military_pie_data.push(row);
  603. for (var s=1; s<=data.game.slots; s++) {
  604. row = new Array();
  605. var index = (data.game.turn-1) * data.game.slots + (s - 1);
  606. row.push(data.scores[index].name);
  607. row.push(data.scores[index].planets);
  608. military_pie_data.push(row);
  609. }
  610. $("<div id='echartdisplay'></div>").appendTo(screen.tabcontent);
  611.  
  612. var data = google.visualization.arrayToDataTable(military_pie_data);
  613.  
  614. // Create and draw the visualization.
  615. new google.visualization.PieChart(document.getElementById("echartdisplay")).draw(data,
  616. {
  617. chartArea:{left:330,top:20,width:"75%",height:"90%"},
  618. legend: { position: "right", textStyle: { color: '#fff', fontSize: 11 } },
  619. lineWidth: 4,
  620. pointSize: 2,
  621. //pieSliceText: "label",
  622. width: 1000,
  623. height: 600,
  624. backgroundColor: "transparent",
  625. hAxis: { textStyle: { color: '#fff', fontSize: 13 }, gridlines: { color: '#444', count: 4 } },
  626. vAxis: { textStyle: { color: '#fff', fontSize: 13 }, gridlines: { color: '#444', count: 4 } }
  627. }
  628. );
  629. };
  630. } //wrapper for injection