Last active
January 29, 2026 16:53
-
-
Save ackvf/464bc077f430cdd8677bbd9669d47605 to your computer and use it in GitHub Desktop.
Neptune's Pride
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Neptune's Pride 2 devel - Triton userscript | |
| // @version 1 | |
| // @description This plugin works with Triton's data structures and performs advanced tasks on them. | |
| // @namespace http://qry.me/ | |
| // @author Vitezslav Ackermann Ferko (Qwerty), [email protected] [email protected] | |
| // @copyright 2014+, 2021+, Vitezslav Ackermann Ferko (Qwerty) | |
| // @licence Released under MIT licence | |
| // @downloadURL https://gist.githubusercontent.com/ackvf/464bc077f430cdd8677bbd9669d47605/raw/9285c7c3be05d5fac70cab8dac6db5589921d9b1/qscript-nptriton.devel.intro.monkey.js | |
| // //run-at document-start | |
| // @match http*://triton.ironhelmet.com/gameu* | |
| // @match http*://tritonsandbox.appspot.com/game* | |
| // @match http*://np.ironhelmet.com/game* | |
| // @require http://code.jquery.com/jquery-latest.js | |
| // //require http://nptriton.cqproject.net/qscript-nptriton.devel.monkey.js | |
| // ==/UserScript== | |
| // http://tampermonkey.net/documentation.php | |
| console.log('qscript-devel-init') | |
| var $ = window.jQuery; | |
| $.getScript( "https://gist.githubusercontent.com/ackvf/464bc077f430cdd8677bbd9669d47605/raw/9285c7c3be05d5fac70cab8dac6db5589921d9b1/qscript-nptriton.devel.monkey.js" ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.log('qscript-devel') | |
| window.QQ = {}; // global | |
| QQ.vars = {}; | |
| // /* SETTINGS ---------------------------------------------------------------- | |
| // The values low and high (zoomed out) are the amount of shine for the alliance circles. Set off to (0|1) to force display when turned off. | |
| // Allowed values are 0-5 | |
| QQ.vars.alliances = {low:1,high:3,off:1}; | |
| // */ SETTINGS ---------------------------------------------------------------- | |
| // document.getElementsByTagName("script")[(3|16)] | |
| // Crux.crux.children[1].map; | |
| QQ.initUI = function() { | |
| $(".widget.fullscreen").append('<div id="qcontainer" class="off"><div id="qbtn" class="awesome"></div><div class="qreload qbutton" title="reload server data"></div><div class="qreloadUI qbutton" title="reload UI"></div><div id="qpanel"></div><div id="qdiv"></div></div>'); | |
| $("#qbtn").click(function() { $("#qcontainer").toggleClass('on off') }); | |
| $(".qreload").click(function() {QQ.reload()}); | |
| $(".qreloadUI").click(function() {QQ.reloadUI()}); | |
| QQ.refreshPanel(); | |
| $("#qdiv").append('<div id="qbtnpanel"></div><div id="qcontent"></div>'); | |
| $("#qbtnpanel").append( | |
| '<div type="button" class="qbtn tech">Compare Tech</div>'+( | |
| (!QQ.alliances.list || QQ.alliances.list[0].length == 0) ? "" : | |
| '<div type="button" class="qbtn techAlliance">Alliance Tech</div>')+ | |
| '<div type="button" class="qbtn screenshot">Make Screenshot</div>'+ | |
| '<div type="button" class="qbtn galaxyTab">Galaxy screen</div>'+ | |
| '<div type="button" class="qbtn researchTab">Research</div>' | |
| ); | |
| $(".qbtn.tech").click(function() { QQ.show.tech() }); | |
| $(".qbtn.techAlliance").click(function() { QQ.show.techAlliance() }); | |
| $(".qbtn.historyView").click(function() { QQ.show.historyView() }); | |
| $(".qbtn.screenshot").click(function() { QQ.show.screenshotInterface() }); | |
| $(".qbtn.galaxyTab").click(function() { QQ.show.galaxyTab() }); | |
| $(".qbtn.researchTab").click(function() { QQ.show.researchTab() }); | |
| Mousetrap.bind(["k", "K"], QQ.toggleAIDisplayed); | |
| Mousetrap.bind(["y", "Y"], QQ.togglePersonalData); | |
| Mousetrap.bind(["a", "A"], QQ.toggleAlliancesDisplayed); | |
| Mousetrap.bind(["j", "J"], QQ.toggleCrosshair); | |
| // quickupgrade key binds | |
| // Mousetrap.bind(["+"], function() { Crux.crux.trigger("upgrade_economy"); }); | |
| // Mousetrap.bind(["ě"], function() { Crux.crux.trigger("upgrade_industry"); }); | |
| // Mousetrap.bind(["š"], function() { Crux.crux.trigger("upgrade_science"); }); | |
| } | |
| QQ.reload = function() { | |
| // QQ = {}; // possibly do complete restart in the future. | |
| // QQ.vars = {}; | |
| $("#qcontainer").remove(); | |
| console.log("Reloading .."); | |
| QQ.getServerData(); | |
| } | |
| QQ.reloadUI = function() { | |
| $("#qcontainer").remove(); | |
| this.refreshData(); | |
| this.initUI(); | |
| console.log("UI reloaded"); | |
| } | |
| QQ.refreshData = function() { | |
| with (this) { | |
| // TODO: run all getters | |
| getBasicData(); | |
| getPlayers(); | |
| getAlliances(); | |
| getStars(); | |
| if (NeptunesPride.gameNumber == 6537227089739776) | |
| { | |
| exchangeStarData(); | |
| exchangeTechnologyData(); | |
| } | |
| } | |
| // TODO: refresh UI | |
| console.log("Data refreshed"); | |
| } | |
| QQ.refreshPanel = function() { | |
| $("#qpanel").html("Cycle "+QQ.cycle+" - Tick "+QQ.tick); | |
| } | |
| QQ.initExternalSources = function(callFunc) { | |
| if (callFunc === null) callFunc = function () {return 0}; | |
| // in order to not get two contentAreas we need to empty it first, so we can reload the np variables | |
| $("#contentArea").empty(); // reloads whole interface | |
| Crux.init("#contentArea"); | |
| Crux.templates = NeptunesPride.templates | |
| universe = NeptunesPride.Universe(); | |
| inbox = NeptunesPride.Inbox(universe); | |
| npui = NeptunesPride.Interface(universe, inbox); | |
| npuis = NeptunesPride.InterfaceScreens(npui, universe, inbox) | |
| np = NeptunesPride.Game(universe, inbox, npui); | |
| si = NeptunesPride.SharedInterface(npui); | |
| // np.serverRequest({type: "order", order:"full_universe_report"}); | |
| QQ.getServerData(callFunc); | |
| } | |
| QQ.screenshot = {}; | |
| QQ.screenshot.save = function() { | |
| // trying to get higher resolution from the canvas.. | |
| // var cf = 1 | |
| // var cw = 1920*cf; | |
| // var ch = 1080*cf; | |
| // $("body").css("overflow", "hidden"); | |
| // canvas = document.getElementsByTagName("canvas")[0]; | |
| // $(canvas).css("width", cw).css("height", ch); | |
| // canvas.width = cw; canvas.height = ch; | |
| window.location.href = document.getElementsByTagName("canvas")[0].toDataURL("image/jpeg").replace("image/jpeg", "image/octet-stream"); | |
| //window.location.href = document.getElementsByTagName("canvas")[0].toDataURL("image/png").replace("image/png", "image/octet-stream"); | |
| } | |
| QQ.screenshot.sendAsText = function() { | |
| var i = (document.getElementsByClassName("text_area")[1] == null) ? 0 : 1; | |
| document.getElementsByClassName("text_area")[i].value = document.getElementsByTagName("canvas")[0].toDataURL("image/jpeg"); | |
| } | |
| QQ.vars.toggledAIDisplayed = false; | |
| QQ.toggleAIDisplayed = function () { | |
| var ss = NeptunesPride.universe.galaxy.stars; | |
| with (QQ.vars) | |
| // if (!toggledAIDisplayed) { | |
| // QQ.vars.aiStars = {}; | |
| // for (var k in ss) | |
| // if (ss[k].player != null && ss[k].player.ai == 1) { | |
| // aiStars[k] = {}; | |
| // aiStars[k].sprite_spriteX = ss[k].sprite.spriteX; | |
| // aiStars[k].sprite_spriteY = ss[k].sprite.spriteY; | |
| // aiStars[k].spriteOwner_spriteX = ss[k].spriteOwner.spriteX; | |
| // aiStars[k].spriteOwner_spriteY = ss[k].spriteOwner.spriteY; | |
| // ss[k].sprite.spriteX = 512; | |
| // ss[k].sprite.spriteY = ss[k].spriteOwner.spriteY; | |
| // ss[k].spriteOwner.spriteX = 512; | |
| // ss[k].spriteOwner.spriteY = 0; | |
| // } | |
| // toggledAIDisplayed = true; | |
| // } else { | |
| // for (var k in ss) { | |
| // if (ss[k].player != null && ss[k].player.ai == 1) { | |
| // ss[k].sprite.spriteX = aiStars[k].sprite_spriteX; | |
| // ss[k].sprite.spriteY = aiStars[k].sprite_spriteY; | |
| // ss[k].spriteOwner.spriteX = aiStars[k].spriteOwner_spriteX; | |
| // ss[k].spriteOwner.spriteY = aiStars[k].spriteOwner_spriteY; | |
| // } | |
| // } | |
| // toggledAIDisplayed = false; | |
| // } | |
| Crux.crux.trigger('map_refresh'); | |
| } // Mousetrap.bind(["k", "K"], toggleAIDisplayed); | |
| QQ.vars.toggledPersonalData = false; | |
| QQ.togglePersonalData = function () { | |
| var npStars=NeptunesPride.universe.galaxy.stars; | |
| var npFleets=NeptunesPride.universe.galaxy.fleets; | |
| with (QQ.vars) | |
| // if (!toggledPersonalData) { | |
| // QQ.vars.stars = {}; | |
| // QQ.vars.fleets = {}; | |
| // for (var k in npStars) { | |
| // var ai = !(toggledAIDisplayed && aiStars[k] != null); | |
| // stars[k]={}; | |
| // stars[k].totalDefenses = npStars[k].totalDefenses; | |
| // stars[k].halo = npStars[k].halo; | |
| // stars[k].e = npStars[k].e; | |
| // stars[k].i = npStars[k].i; | |
| // stars[k].s = npStars[k].s; | |
| // if(ai) stars[k].sprite_spriteX = npStars[k].sprite.spriteX; | |
| // if(ai) stars[k].spriteGate_visible = (npStars[k].spriteGate != null) ? npStars[k].spriteGate.visible : null; | |
| // npStars[k].totalDefenses = 0; | |
| // npStars[k].halo = null; | |
| // npStars[k].e = 0; // While I can nullify the values for econ, ind and sci, the zeros are still shown above those stars. If I could just hide them, I wouldn't have to nullify them. | |
| // npStars[k].i = 0; | |
| // npStars[k].s = 0; | |
| // if(ai) npStars[k].sprite.spriteX = 64; | |
| // if(ai) if (npStars[k].spriteGate != null) npStars[k].spriteGate.visible = false; | |
| // } | |
| // for (var k in npFleets) { | |
| // fleets[k]={}; | |
| // fleets[k].sprite_visible = (npFleets[k].sprite != null) ? npFleets[k].sprite.visible : null; | |
| // fleets[k].spriteOwner_visible = (npFleets[k].spriteOwner != null) ? npFleets[k].spriteOwner.visible : null; | |
| // fleets[k].orbiting = npFleets[k].orbiting; | |
| // fleets[k].path = npFleets[k].path; | |
| // if (npFleets[k].sprite != null) npFleets[k].sprite.visible = false; | |
| // if (npFleets[k].spriteOwner != null) npFleets[k].spriteOwner.visible = false; | |
| // npFleets[k].orbiting = null; | |
| // npFleets[k].path = []; | |
| // } | |
| // toggledPersonalData = true; | |
| // } else { | |
| // for (var k in npStars) { | |
| // var ai = !(toggledAIDisplayed && aiStars[k] != null); | |
| // npStars[k].totalDefenses = stars[k].totalDefenses; | |
| // npStars[k].halo = stars[k].halo; | |
| // npStars[k].e = stars[k].e; | |
| // npStars[k].i = stars[k].i; | |
| // npStars[k].s = stars[k].s; | |
| // if(ai) npStars[k].sprite.spriteX = stars[k].sprite_spriteX; | |
| // if(ai) if (npStars[k].spriteGate != null) npStars[k].spriteGate.visible = stars[k].spriteGate_visible; | |
| // } | |
| // for (var k in npFleets) { | |
| // if (npFleets[k].sprite != null) npFleets[k].sprite.visible = fleets[k].sprite_visible; | |
| // if (npFleets[k].spriteOwner != null) npFleets[k].spriteOwner.visible = fleets[k].spriteOwner_visible; | |
| // npFleets[k].orbiting = fleets[k].orbiting; | |
| // npFleets[k].path = fleets[k].path; | |
| // } | |
| // toggledPersonalData = false; | |
| // } | |
| Crux.crux.trigger('map_refresh'); | |
| } // Mousetrap.bind(["y", "Y"], togglePersonalData); | |
| QQ.vars.toggledAlliancesDisplayed = false; | |
| QQ.toggleAlliancesDisplayed = function() { | |
| if ( QQ.alliances.list.length == 0 ) return 0; | |
| QQ.vars.toggledAlliancesDisplayed = !QQ.vars.toggledAlliancesDisplayed; | |
| QQ.vars.alliances.toggled = QQ.vars.toggledAlliancesDisplayed; | |
| Crux.crux.trigger('map_refresh'); | |
| }; // Mousetrap.bind(["a", "A"], QQ.toggleAlliancesDisplayed); | |
| // QPanel content ------------------------------------------------------------ | |
| QQ.show = {}; | |
| QQ.show.tech = function(sort_by, direction) { | |
| if (sort_by === null) sort_by = "infrastructure_value"; | |
| if (direction === null) direction = "desc"; | |
| if (!QQ.players) QQ.getPlayers(); | |
| var players = QQ.players; | |
| var html = ""; | |
| var techHtml = []; | |
| // sorting functions ----------------- | |
| var arr1 = []; var arr2 = []; | |
| QQ.vars.sorted = []; | |
| if (sort_by == "uid") { | |
| for (key in players) { | |
| arr1.push(players[key].uid); | |
| } | |
| QQ.vars.sorted = QQ.fn.sort(arr1,arr1,direction); | |
| } | |
| if (sort_by == "infrastructure_value") { | |
| for (key in players) { | |
| arr1.push(players[key].infrastructure_value); | |
| arr2.push(players[key].uid); | |
| } | |
| QQ.vars.sorted = QQ.fn.sort(arr1,arr2,direction); | |
| } | |
| if (sort_by == "alliance") { | |
| var pallied = QQ.fn.peel(QQ.alliances.list); | |
| var premaining = QQ.fn.substract(Object.keys(players).map(function(item) { return parseInt(item,10) }),pallied); | |
| var pconcat = [].concat(pallied,premaining); | |
| var sorted = []; | |
| for (var i=0; i<pconcat.length; i++) sorted.push([pconcat[i], pconcat[i]]); | |
| QQ.vars.sorted = sorted; | |
| } | |
| // hyperlinks for calling sorting functions - el.id : [<a>displayed txt</a>, function(call)] | |
| var hl = { | |
| uid : ["player.id", "uid"], | |
| inVal : ["infra.value*", "infrastructure_value"], | |
| ally : ["alliances", "alliance"] | |
| } | |
| for (key in hl) { hl[key][0] = '<a class="tech hotlinks" id="'+key+'">'+hl[key][0]+'</a>' }; // wrap keys in html tags | |
| for (key in players) { | |
| techHtml[key] = []; | |
| players[key].tech.forEach( function (item,index) { | |
| if (item > players[QQ.you].tech[index]) { compared = "higher" }; | |
| if (item < players[QQ.you].tech[index]) { compared = "lower" }; | |
| if (item == players[QQ.you].tech[index]) { compared = "same" }; | |
| if (key == QQ.you) { compared = "yours" }; | |
| // add style classes + pad the tech levels | |
| techHtml[key][index] = '<span class="'+compared+'">'+QQ.fn.rpad(item,4," ")+'</span>' | |
| }); | |
| }; | |
| html += "S H T E W B M = "+hl.inVal[0]+" | E I S | "+hl.uid[0]+" | "+hl.ally[0]+"\n"; | |
| QQ.vars.sorted.forEach( function (item) { // item[0] - sorted by, item[1] - player_id | |
| html += techHtml[item[1]].join("") +" = "+ QQ.fn.rpad(players[item[1]].infrastructure_value,5," ") +" "+ QQ.fn.rpad(players[item[1]].infrastructure.econ,4," ") +" "+ QQ.fn.rpad(players[item[1]].infrastructure.ind,4," ") +" "+ QQ.fn.rpad(players[item[1]].infrastructure.sci,4," ") +" "+ QQ.alliances.htmlColourOfPlayer(item[1]) + players[item[1]].hyperlink +" "+ (players[item[1]].active ? "<span style='font-size:75%'>"+players[item[1]].uid+"</span>" : "(AI)") + "\n"; //+" "+ players[key].color + "\n"; | |
| }); | |
| html += "*infrastructure value = ((E+1)E + 2(I+1)I + 8(S+1)S)/maxStars"; | |
| // QQ.sorted.forEach( function (item) { console.log(item) } ); | |
| // console.log(html); | |
| // brize(html); | |
| $("#qcontent").html(html.brize()); | |
| direction = (direction == "asc") ? "desc" : "asc"; | |
| for (key in hl) (function(key,hl) { $("#"+key).unbind("click").click( function() { QQ.show.tech(hl[key][1], direction); }) })(key,hl); | |
| } | |
| QQ.show.techAlliance = function(sort_by, direction) { | |
| if (sort_by === null) sort_by = "infrastructure_value"; | |
| if (direction === null) direction = "desc"; | |
| var alliances = QQ.alliances; | |
| var list = alliances.list; | |
| var html = ""; | |
| var techHtml = []; | |
| // sorting functions ----------------- | |
| var arr1 = []; var arr2 = []; | |
| QQ.vars.sortedAlliances = []; | |
| if (sort_by == "auid") { | |
| arr1 = Object.keys(list); | |
| QQ.vars.sortedAlliances = QQ.fn.sort(arr1,arr1,direction); | |
| } | |
| if (sort_by == "infrastructure_value") { | |
| for (key in list) { | |
| arr1.push(alliances.summaries[key].infrastructure_value); | |
| arr2.push(key); | |
| } | |
| QQ.vars.sortedAlliances = QQ.fn.sort(arr1,arr2,direction); | |
| } | |
| // hyperlinks for calling sorting functions - el.id : [<a>displayed txt</a>, function(call)] | |
| var hl = { | |
| uid : ["alliance.id", "auid"], | |
| inValS : ["inf_sum", "infrastructure_value"] | |
| } | |
| for (key in hl) { hl[key][0] = '<a class="tech hotlinks" id="'+key+'">'+hl[key][0]+'</a>' }; // wrap keys in html tags | |
| var totalTech = []; | |
| for (var auid in list) { | |
| techHtml[auid] = []; | |
| totalTech[auid] = 0; | |
| for (var tech in alliances.summaries[auid].tech) { | |
| var value = alliances.summaries[auid].tech[tech]; | |
| if (value > alliances.summaries[alliances.isInAlliance(QQ.you)].tech[tech]) { compared = "higher" }; | |
| if (value < alliances.summaries[alliances.isInAlliance(QQ.you)].tech[tech]) { compared = "lower" }; | |
| if (value == alliances.summaries[alliances.isInAlliance(QQ.you)].tech[tech]) { compared = "same" }; | |
| if (auid == alliances.isInAlliance(QQ.you)) { compared = "yours" }; | |
| totalTech[auid] += value; | |
| // add style classes + pad the tech levels | |
| var padding = 4; if (auid == list.length) padding = 1; | |
| techHtml[auid][tech] = '<span class="'+compared+'">'+QQ.fn.rpad(value,padding," ")+'</span>' | |
| }; | |
| }; | |
| totalTechHtml = []; | |
| for (var auid in totalTech) { | |
| var value = totalTech[auid]; | |
| if (value > totalTech[alliances.isInAlliance(QQ.you)]) { compared = "higher" }; | |
| if (value < totalTech[alliances.isInAlliance(QQ.you)]) { compared = "lower" }; | |
| if (value == totalTech[alliances.isInAlliance(QQ.you)]) { compared = "same" }; | |
| if (auid == alliances.isInAlliance(QQ.you)) { compared = "yours" }; | |
| totalTechHtml[auid] = '<span class="'+compared+'">'+QQ.fn.rpad(value,2," ")+'</span>' | |
| }; | |
| html += "S H T E W B M | X = "+hl.inValS[0]+" inf_avg | sum E I S | avg E I S | "+hl.uid[0]+"\n"; | |
| QQ.vars.sortedAlliances.forEach( function (item) { // item[0] - sorted by, item[1] - alliance_id | |
| html += techHtml[item[1]].join("") +"|"+ totalTechHtml[item[1]] +" = "+ QQ.fn.rpad(alliances.summaries[item[1]].infrastructure_value,5," ") +" "+ QQ.fn.rpad(alliances.averages[item[1]].infrastructure_value,0," ") +" | "+ QQ.fn.rpad(alliances.summaries[item[1]].infrastructure.econ,4," ") +" "+ QQ.fn.rpad(alliances.summaries[item[1]].infrastructure.ind,4," ") +" "+ QQ.fn.rpad(alliances.summaries[item[1]].infrastructure.sci,1," ") +" | "+ QQ.fn.rpad(alliances.averages[item[1]].infrastructure.econ,4," ") +" "+ QQ.fn.rpad(alliances.averages[item[1]].infrastructure.ind,4," ") +" "+ QQ.fn.rpad(alliances.averages[item[1]].infrastructure.sci,4," ") +" "+ QQ.alliances.htmlColourOfAlliance(item[1],'█▓▒░') +" "+ "<span style='font-size:75%'>"+item[1]+"</span>" + "\n"; //+" "+ players[key].color + "\n"; | |
| }); | |
| // html += ""; | |
| // QQ.sorted.forEach( function (item) { console.log(item) } ); | |
| // console.log(html); | |
| // brize(html); | |
| $("#qcontent").html(html.brize()); | |
| direction = (direction == "asc") ? "desc" : "asc"; | |
| for (key in hl) (function(key,hl) { $("#"+key).unbind("click").click( function() { QQ.show.techAlliance(hl[key][1], direction); }) })(key,hl); | |
| } | |
| QQ.show.historyView = function() { | |
| if (!QQ.historyView.enabled) { | |
| QQ.historyView.enabled = true; | |
| QQ.historyView.init(); | |
| } | |
| else QQ.historyView.disable(); | |
| } | |
| QQ.show.screenshotInterface = function() { | |
| if (!QQ.vars.screenshotInterface) { | |
| QQ.vars.screenshotInterface = true; | |
| $("html").css("overflow", "hidden"); | |
| $("body").css("overflow", "hidden"); | |
| $("#qcontent").empty(); | |
| $(".qbtn.screenshot").toggleClass('enabled'); | |
| $("#qdiv").toggleClass('screenshotInterface'); | |
| $("#qcontent").append('<div type="button" class="qbtn screenshot makeScreenshot">Save Screenshot</div><div type="button" class="qbtn screenshot sendScreenshot">Send as Message</div>'); | |
| $(".makeScreenshot").click(function() { QQ.screenshot.save() }); | |
| $(".sendScreenshot").click(function() { QQ.screenshot.sendAsText() }); | |
| QQ.toggleCrosshair(0); | |
| } | |
| else { | |
| QQ.vars.screenshotInterface = false; | |
| $(".qbtn.screenshot").toggleClass('enabled'); | |
| $("#qdiv").toggleClass('screenshotInterface'); | |
| $("#qcontent").empty(); | |
| QQ.toggleCrosshair(1); | |
| $("body").css("overflow", "auto"); | |
| $("html").css("overflow", "auto"); | |
| } | |
| } | |
| QQ.vars.toggledCrosshair = false; | |
| QQ.toggleCrosshair = function() { | |
| var chtoggled = QQ.vars.toggledCrosshair; | |
| console.log(); | |
| if (!chtoggled) { | |
| $("body").append('<div id="scrcrosshair"><div style="position:fixed; z-index:9999; border-left:1px solid red; width:1px; height:100%; left:50%;"></div><div style="position:fixed; z-index:9999; border-top:1px solid red; height:1px; width:100%; top:50%;"></div></div>'); | |
| QQ.vars.toggledCrosshair=true; | |
| } else { | |
| $("#scrcrosshair").remove(); | |
| QQ.vars.toggledCrosshair=false; | |
| } | |
| }; // Mousetrap.bind(["j", "J"], QQ.toggleCrosshair); | |
| QQ.show.galaxyTab = function() { | |
| $("#qcontent").empty(); | |
| $("#qdiv").toggleClass('galaxyTab'); | |
| var headerDict = { // layout | |
| uid : "S", | |
| puid : "P", | |
| "_1" : " ", | |
| e : "e", | |
| i : "i", | |
| s : "s", | |
| "_2" : " ", | |
| next_econ : "$e", | |
| next_ind : "$i", | |
| next_sci : "$s", | |
| "_3" : " ", | |
| r : "res", | |
| hyperlink : "name"}; | |
| var thead="<thead style='text-align:left;'><tr>"; | |
| Object.keys(headerDict).forEach(function(key) { | |
| if (key[0] == "_") thead+="<th><span style=\"position:relative; padding-left:10px\"> </span></th>"; | |
| else thead+="<th>"+headerDict[key]+"</th>"; | |
| }); | |
| thead+="</tr></thead>"; | |
| var html="<table style='width:100%'>"; | |
| html+=thead; | |
| QQ.vars.allianceStars.forEach(function(k) { // the actual printing of the table | |
| html+="<tr>"; | |
| html+="<td>"+k.uid+"</td><td>"+k.puid+"</td><td> </td>"+ | |
| "<td>"+k.e+"</td><td>"+k.i+"</td><td>"+k.s+"</td><td> </td>"+ | |
| "<td>"+k.next_econ+"</td><td>"+k.next_ind+"</td><td>"+k.next_sci+"</td><td> </td>"+ | |
| "<td>"+k.r+"</td><td>"+k.hyperlink+"</td>"; | |
| html+="</tr>"; | |
| }); | |
| html+="</table>"; | |
| $("#qcontent").html(html); | |
| } | |
| QQ.show.researchTab = function() { | |
| $("#qcontent").empty(); | |
| $("#qdiv").toggleClass('researchTab'); | |
| // $("#qcontent").html(QQ.vars.technology.brize()); | |
| var dict = { | |
| "scanning" : "scan", | |
| "propulsion" : "range", | |
| "terraforming" : "terra", | |
| "research" : "exp", | |
| "weapons" : "weap", | |
| "banking" : "bank", | |
| "manufacturing" : "manu"}; | |
| var headerDict = { | |
| "puid" : "P", | |
| "cash" : "cash", | |
| "r" : "r_now", | |
| "r_next" : "r_next", | |
| "r_eta" : "ETA", | |
| "sci" : "sci", | |
| "s" : "S", | |
| "h" : "R", | |
| "t" : "T", | |
| "e" : "E", | |
| "w" : "W", | |
| "b" : "B", | |
| "m" : "M"}; | |
| var thead="<thead style='text-align:left;'><tr>"; | |
| Object.keys(headerDict).forEach(function(key) { | |
| thead+="<th>"+headerDict[key]+"</th>"; | |
| }); | |
| thead+="</tr></thead>"; | |
| var html="<table style='width:100%'>"; | |
| html+=thead; | |
| QQ.vars.technology.forEach(function(z,k) { | |
| html+="<tr>"; | |
| Object.keys(QQ.vars.technology[k]).forEach(function(key,i) { | |
| cssClass=""; | |
| if (key == "r_next" || i-6 == Object.keys(dict).indexOf(QQ.vars.technology[k]["r_next"])) cssClass="_r_next"; | |
| if (key == "r" || i-6 == Object.keys(dict).indexOf(QQ.vars.technology[k]["r"])) cssClass="_r_now"; // the order controls what has higher priority as a style | |
| if (key == "r" || key == "r_next") html+="<td class='td-research"+cssClass+"'>"+dict[QQ.vars.technology[k][key]]+"</td>" // translates long research name to shorter (dict) | |
| else html+="<td"+((cssClass != "")?" class='td-research"+cssClass+"'":"")+">"+QQ.vars.technology[k][key]+"</td>"; | |
| }); | |
| html+="</tr>"; | |
| }); | |
| html+="</table>"; | |
| $("#qcontent").html(html); | |
| } | |
| // alliances ------------------------------------------------------------ | |
| QQ.alliances = {}; | |
| QQ.alliances.colourList = ["purple", "violet", "red", "orange", "yellow", "green", "cyan", "blue"]; | |
| QQ.alliances.isInAlliance = function (pid) { | |
| for (var i=0; i<QQ.alliances.list.length; i++) { | |
| if (QQ.alliances.list[i].indexOf(pid) != -1) return i; | |
| } | |
| return -1; | |
| } | |
| QQ.alliances.htmlColourOfPlayer = function (pid,symbol) { | |
| if (symbol === null) symbol = "█"; // 176:░,177:▒,178:▓ | |
| var auid = QQ.alliances.isInAlliance(pid); | |
| return (auid != -1) ? QQ.alliances.htmlColourOfAlliance(auid,symbol) : ""; | |
| } | |
| QQ.alliances.htmlColourOfAlliance = function (auid,symbol) { | |
| if (symbol === null) symbol = "█"; // 176:░,177:▒,178: | |
| return "<span style='color:"+QQ.alliances.colourList[auid]+"'>"+symbol+"</span>"; | |
| } | |
| QQ.alliances.initOverride = function (check) { | |
| if (check != 1) { console.log("must call with true parameter"); return; } | |
| NeptunesPride.npui.map.drawAlliances = function() { | |
| var map = NeptunesPride.npui.map; | |
| var i, ii, star, ratio; | |
| for (i = map.startVisisbleStarIndex, ii = map.endVisisbleStarIndex; i < ii; i+=1) { | |
| star = map.sortedStarSprites[i]; | |
| if ((QQ.vars.alliances.toggled || QQ.vars.alliances.off) && star.visible && star.alliance) { | |
| ratio = 1; | |
| star.alliance.screenX = star.screenX; | |
| star.alliance.screenY = star.screenY; | |
| if (map.scale <= 500) | |
| star.alliance.scale = star.alliance.scaleratio * map.pixelRatio * map.scale / 250 / ratio; | |
| if (map.scale == 50) // allowed values are 0 <= x <=5 | |
| star.alliance.spriteX = ((0 <= QQ.vars.alliances.high) && QQ.vars.alliances.high || 0) && ((QQ.vars.alliances.high <= 5) && QQ.vars.alliances.high || 5) * 64; // add some shine when zoomed out (minimap) | |
| else | |
| star.alliance.spriteX = ((0 <= QQ.vars.alliances.low) && QQ.vars.alliances.low || 0) && ((QQ.vars.alliances.low <= 5) && QQ.vars.alliances.low || 5) * 64; | |
| if (!QQ.vars.alliances.toggled && QQ.vars.alliances.off) | |
| star.alliance.spriteX = 0; | |
| map.drawSprite(star.alliance); | |
| }; | |
| } | |
| }; | |
| NeptunesPride.npui.map.createSpritesAlliances = function() { | |
| var map = NeptunesPride.npui.map; | |
| var universe = NeptunesPride.universe; | |
| var i, star, container; | |
| var sortedAllianceSprites = []; | |
| for (i in universe.galaxy.stars) { | |
| star = universe.galaxy.stars[i]; | |
| container = {}; | |
| container.uid = star.uid; | |
| container.worldY = star.y; // needed for sorting to match the map.sortedStarSprites array | |
| container.allianceSprite = null; | |
| if (universe.galaxy.stars[star.uid].player && (universe.galaxy.stars[star.uid].player.alliance != undefined)) | |
| container.allianceSprite = {width: 64, height: 64, pivotX: 32, pivotY: 32, rotation: 0, | |
| image: map.allianceSrc, scaleratio: 10, // see drawAlliances() | |
| spriteX: 0*64, spriteY: (7 - universe.galaxy.stars[star.uid].player.alliance) * 64 + 64 | |
| }; // alliance colours are in reversed order => 7-id | |
| sortedAllianceSprites.push(container); | |
| } | |
| sortedAllianceSprites.sort(function(a, b) { return a.worldY - b.worldY; }); // now the IDs should match with sortedStarSprites | |
| for (i in map.sortedStarSprites) { | |
| var starSprite = map.sortedStarSprites[i]; | |
| var allianceSprite = sortedAllianceSprites[i]; | |
| starSprite.alliance = allianceSprite.allianceSprite; | |
| } | |
| }; | |
| if (!NeptunesPride.npui.map.old_draw) | |
| NeptunesPride.npui.map.old_draw = NeptunesPride.npui.map.draw; | |
| // inject drawAlliances() | |
| (function() { | |
| var draw = NeptunesPride.npui.map.old_draw.toString(), | |
| parts = draw.match("([^,; ]*).drawStars..(.)"), | |
| cutStops = [draw.indexOf("{")+1,draw.indexOf(".drawStars")-(parts[1].length)]; | |
| eval("NeptunesPride.npui.map.draw = function() {\n var map = o = NeptunesPride.npui.map;\n var universe = t = NeptunesPride.universe;\n"+draw.slice(cutStops[0],cutStops[1])+"\n"+parts[1]+".drawAlliances()"+parts[2]+"\n"+draw.slice(cutStops[1])) | |
| })() | |
| // must remap | |
| Crux.tickCallbacks[0] = NeptunesPride.npui.map.draw; | |
| if (!NeptunesPride.npui.map.old_createSprites) | |
| NeptunesPride.npui.map.old_createSprites = NeptunesPride.npui.map.createSprites; | |
| // override old function | |
| NeptunesPride.npui.map.createSprites = function () { | |
| var o = NeptunesPride.npui.map; | |
| NeptunesPride.universe.galaxy.stars&&( | |
| o.createEssentialSprites(), | |
| o.createSpritesStars(), | |
| o.createSpritesAlliances(), | |
| o.createSpritesFleets(), | |
| o.createSpritesNebular(), | |
| Crux.drawReqired=!0 | |
| )}; | |
| // must rebind | |
| Crux.crux.on("map_rebuild", NeptunesPride.npui.map.createSprites); | |
| Crux.crux.trigger("map_rebuild"); | |
| }; | |
| // history ------------------------------------------------------------ | |
| QQ.historyView = {}; | |
| QQ.historyView.init = function () { | |
| QQ.initExternalSources(function (data) { np.onServerResponse(data); if (QQ.historyView.enabled) QQ.historyView.enable(); }); | |
| } | |
| QQ.historyView.enable = function() { | |
| QQ.historyView.enabled = true; | |
| $(".qbtn.historyView").toggleClass('enabled').html(('Disable historyView')); | |
| $("#qcontainer").removeClass('off').addClass('on'); | |
| $("#qdiv").toggleClass('historyView'); | |
| $(".qbtn.tech").remove(); | |
| universe.galaxy.fleets = {} // remove fleets | |
| } | |
| QQ.historyView.disable = function() { | |
| // QQ.historyView.enabled = false; | |
| // QQ.historyView.init(); | |
| location.reload(); | |
| // $(".qbtn.historyView").toggleClass('enabled').html(('Enable historyView')); | |
| // $("#qdiv").toggleClass('historyView'); | |
| } | |
| QQ.historyView.refresh = function() { | |
| } | |
| QQ.historyView.next = function(count) { }; | |
| QQ.historyView.previous = function(count) { }; | |
| // TODO .nextPayment() calls next(number_of_ticks) | |
| // GETTERS ------------------------------------------------------------ | |
| QQ.getServerData = function(callFunc) { | |
| if (callFunc === null) callFunc = function () {return 0}; | |
| var requestVars = { | |
| "type" : "order", | |
| "order" : "full_universe_report", | |
| "version" : NeptunesPride.version, | |
| "game_number" : NeptunesPride.gameNumber | |
| }; | |
| $.ajax({ | |
| type: "POST", | |
| url: "/grequest/order", | |
| async: true, | |
| data: requestVars, | |
| success: function(data) { console.log("Ajax call succeeded"); QQ.report = data.report; QQ.refreshData(); QQ.initUI(); callFunc(data);/* re-run all getters? */}, // TODO: initUI and refresh isn't meant to be run together. init only on first start and reload. | |
| error: function() { console.log("Ajax call failed") }, | |
| complete: function() { }, | |
| dataType: "json" | |
| }); | |
| } | |
| QQ.getBasicData = function() { | |
| QQ.tick = QQ.report.tick; | |
| QQ.cycle = QQ.report.productions; | |
| QQ.you = QQ.report.player_uid; | |
| } | |
| QQ.getAlliances = function() { | |
| // usage: http://triton.ironhelmet.com/game/5309705807200256?[[0,1,2,3],[4,5,6]] | |
| // where numbers in arrays are player IDs | |
| var list = JSON.parse(decodeURI(location.hash.substr(1)) || "[[]]"); | |
| if ( Object.prototype.toString.call(list) != "[object Array]" ) return 0; | |
| for (var i in NeptunesPride.universe.galaxy.players) | |
| NeptunesPride.universe.galaxy.players[i].alliance = null; | |
| QQ.alliances.list = []; | |
| for ( var k in list ) { | |
| QQ.alliances.list[k] = []; | |
| for ( var j in list[k]) { | |
| if ( typeof list[k][j] == "number" ) { | |
| QQ.alliances.list[k].push(list[k][j]); | |
| NeptunesPride.universe.galaxy.players[list[k][j]].alliance = k; | |
| } | |
| } | |
| } | |
| QQ.alliances.summaries = {}; | |
| QQ.alliances.averages = {}; | |
| with (QQ) | |
| alliances.list.forEach(function(item,auid) { | |
| alliances.summaries[auid] = {}; | |
| alliances.averages[auid] = {}; | |
| var as = alliances.summaries[auid]; | |
| as.infrastructure = {econ:0,ind:0,sci:0}; | |
| as.infrastructure_value = 0; | |
| as.ships = 0; | |
| as.shipsPerDay = 0; | |
| as.tech = {}; | |
| var totalMembers = 0; // totalMembers of an alliance | |
| item.forEach(function(puid,i) { totalMembers = i+1; | |
| as.infrastructure.econ += players[puid].infrastructure.econ; | |
| as.infrastructure.ind += players[puid].infrastructure.ind; | |
| as.infrastructure.sci += players[puid].infrastructure.sci; | |
| as.infrastructure_value += players[puid].infrastructure_value; | |
| as.ships += players[puid].ships; | |
| as.shipsPerDay += players[puid].shipsPerDay; | |
| for (var k in players[puid].tech) { | |
| as.tech[k] = (players[puid].tech[k] > (as.tech[k] || 0)) ? players[puid].tech[k] : as.tech[k]; | |
| } | |
| }) | |
| var aa = alliances.averages[auid]; | |
| aa.infrastructure = {}; | |
| aa.tech = {}; | |
| aa.infrastructure.econ = as.infrastructure.econ / totalMembers >> 0; | |
| aa.infrastructure.ind = as.infrastructure.ind / totalMembers >> 0; | |
| aa.infrastructure.sci = as.infrastructure.sci / totalMembers >> 0; | |
| aa.infrastructure_value = as.infrastructure_value / totalMembers >> 0; | |
| aa.ships = as.ships / totalMembers >> 0; | |
| aa.shipsPerDay = as.shipsPerDay / totalMembers >> 0; | |
| for (var k in as.tech) { | |
| aa.tech[k] = as.tech[k]; | |
| } | |
| }) | |
| } | |
| QQ.getStars = function() { | |
| // // all stars | |
| // v: visibility (within your scanner range) | |
| // x: coordinate x | |
| // y: coordinate y | |
| // n: name | |
| // uid: star uid | |
| // puid: player uid (-1 neutral) | |
| // // only at scanned stars | |
| // c: ? 0 or 0.5 | |
| // e: economy | |
| // i: industry | |
| // s: science | |
| // ga: gate | |
| // r: resources | |
| // nr: natural resources | |
| // st: ? - always 0 | |
| QQ.stars = QQ.report.stars; | |
| Object.keys(QQ.stars).forEach(function(id) {QQ.stars[id].hyperlink = "<a onClick=\"Crux.crux.trigger('show_star_uid', '"+id+"' )\">"+QQ.stars[id].n+"</a>"}) | |
| } | |
| QQ.getStarsOfAPlayer = function() { | |
| } | |
| QQ.getPlayers = function() { | |
| var rpl = QQ.report.players; | |
| var players = {}; | |
| // get the maximum number of stars a player has | |
| // var starCounts = []; | |
| var maxStars = 0; | |
| Object.keys(rpl).forEach(function(i) { | |
| // starCounts.push(rpl[i].total_stars); | |
| if (rpl[i].total_stars > maxStars) maxStars = rpl[i].total_stars; | |
| }); | |
| for (key in Object.keys(rpl)) { | |
| players[key] = { | |
| uid : rpl[key].uid, | |
| alias : rpl[key].alias, | |
| hyperlink : "<a onClick=\"Crux.crux.trigger('show_player_uid', '"+rpl[key].uid+"' )\">"+rpl[key].alias+"</a>", | |
| color : rpl[key].colorName, | |
| active : ((rpl[key].conceded == 0) && (rpl[key].ai == 0)), | |
| infrastructure_value : (((rpl[key].total_economy+1)*rpl[key].total_economy/2 | |
| + (rpl[key].total_industry+1)*rpl[key].total_industry | |
| + (rpl[key].total_science+1)*rpl[key].total_science*4)/maxStars) >>> 0, | |
| // infrastructure_value : rpl[key].total_economy | |
| // + rpl[key].total_industry*2 | |
| // + rpl[key].total_science*8, | |
| infrastructure : { econ: rpl[key].total_economy, ind: rpl[key].total_industry, sci: rpl[key].total_science }, | |
| tech_names: [ "scanning", "hyperspace range", "terraforming", "experimentation", "weapons", "banking", "manufacturing" ], | |
| tech : [ rpl[key].tech.scanning.level, rpl[key].tech.propulsion.level, rpl[key].tech.terraforming.level, rpl[key].tech.research.level, rpl[key].tech.weapons.level, rpl[key].tech.banking.level, rpl[key].tech.manufacturing.level ], | |
| ships : rpl[key].total_strength, | |
| // shipsPerDay : 24*rpl[key].shipsPerTick | |
| shipsPerDay : rpl[key].total_industry*(rpl[key].tech.manufacturing.value+5)/24 | |
| } | |
| } | |
| QQ.players = players; | |
| } | |
| NeptunesPride.np.preTrigger = function (ek, ed) { | |
| if (ek == "special_ripple_star") console.log("player", ed.player && ed.player.uid || null, "object", ed.uid || ed.puid); | |
| return true; | |
| } | |
| // -------------------------------------------------------------------- | |
| // OVERRIDE functions ------------------------------------------------- | |
| QQ.initOverride = function(check) { | |
| if (check != 1) { console.log("must call with true parameter"); return; } | |
| // custom resources | |
| NeptunesPride.npui.map.allianceSrc = $('<img id="img_alliances" src="http://nptriton.cqproject.net/alliances.png" crossOrigin="anonymous">')[0]; | |
| // override functions | |
| NeptunesPride.np.preTrigger = function (ek, ed) { | |
| if (ek == "special_ripple_star") console.log(ed.player.uid, ed.uid || ed.puid); | |
| return true; | |
| }; | |
| // modules | |
| QQ.alliances.initOverride(1); | |
| } | |
| // -------------------------------------------------------------------- | |
| // other functions ---------------------------------------------------- | |
| QQ.inform = function() { | |
| $.ajax({ | |
| type: "POST", | |
| url: "http://nptriton.cqproject.net/parse.php", | |
| async: true, | |
| // data: {0:[[NeptunesPride.gameNumber,QQ.tick,NeptunesPride.universe.galaxy.player_uid,NeptunesPride.universe.galaxy.players[NeptunesPride.universe.galaxy.player_uid].alias],[NeptunesPride.account.alias,NeptunesPride.account.user_id,NeptunesPride.account.premium]]}, | |
| data: {0:[[],[NeptunesPride.account.alias,NeptunesPride.account.user_id,NeptunesPride.account.premium]]}, | |
| dataType: "text", | |
| success: function(data) {console.log(data);} | |
| }); | |
| } | |
| QQ.purchaseWarpGates = function (check,initialized) { | |
| if (check != 1) { console.log('must call with true parameter'); return 0; } | |
| if (initialized === null) initialized = 0; | |
| var count = 0, | |
| price = 0; | |
| // init required | |
| if (!initialized) { QQ.initExternalSources(function (data) { np.onServerResponse(data); QQ.purchaseWarpGates("yes",1); }); } | |
| else { | |
| for (key in universe.galaxy.stars) | |
| if ((universe.galaxy.stars[key].puid == universe.galaxy.player_uid) && (!universe.galaxy.stars[key].ga)) | |
| { | |
| var selectedStar = universe.galaxy.stars[key]; | |
| var uid = selectedStar.uid; | |
| var ucg = selectedStar.ucg; | |
| console.log(count + ": " + uid + "=$" + ucg); | |
| np.trigger("server_request", {type: "batched_order", order: "buy_warp_gate," + uid + "," + ucg}); | |
| // universe.buyWarpGate(universe.galaxy.stars[key]); // passing star as argument won't take effect | |
| // using following instead | |
| universe.player.cash -= ucg; | |
| selectedStar.ucg = 0; | |
| selectedStar.ga = 1; | |
| count++; | |
| price+=ucg; | |
| } | |
| np.trigger("refresh_interface"); | |
| np.trigger("map_rebuild"); | |
| console.log(count + " Warpgates purchased for $" + price + "."); | |
| } | |
| } | |
| QQ.missedTurns = function() { | |
| Object.keys(NeptunesPride.universe.galaxy.players).forEach(function(val) {var pl = NeptunesPride.universe.galaxy.players[val]; (pl.missed_turns > 0)?console.log(val, pl.alias, ", missed", pl.missed_turns):""}); | |
| } | |
| QQ.exchangeStarData = function() { | |
| var starData = {}; | |
| Object.keys(QQ.stars).forEach(function(i) { if (QQ.stars[i].puid == QQ.you) {var s = QQ.stars[i]; starData[i] = {"e":s["e"],"i":s["i"],"s":s["s"],"r":s["r"],"n":s["n"],"uid":s["uid"],"puid":s["puid"]}} }); | |
| $.ajax({ | |
| type: "POST", | |
| url: "http://nptriton.cqproject.net/parse_star_data.php", | |
| async: true, | |
| data: starData, | |
| success: function(data) { console.log("Star Data Exchanged."); | |
| QQ.vars.allianceStars = data; | |
| QQ.vars.allianceStars.forEach(function(star) {star.hyperlink = "<a onClick=\"Crux.crux.trigger('show_star_uid', '"+star.uid+"' )\">"+star.n+"</a>"}); | |
| // console.log(data); | |
| }, | |
| error: function() { console.log("Could not exchange Star Data."); }, | |
| dataType: "JSON" | |
| }); | |
| } | |
| QQ.exchangeTechnologyData = function() { | |
| var u = NeptunesPride.universe.player; | |
| var techData = {"puid":u.uid,"cash":u.cash,"r":u.researching,"r_next":u.researching_next,"r_eta":Math.ceil((u.tech[u.researching].brr*u.tech[u.researching].level-u.tech[u.researching].research)/u.total_science),"sci":u.total_science,"tech":{"s":u.tech.scanning.research,"h":u.tech.propulsion.research,"t":u.tech.terraforming.research,"e":u.tech.research.research,"w":u.tech.weapons.research,"b":u.tech.banking.research,"m":u.tech.manufacturing.research}} | |
| $.ajax({ | |
| type: "POST", | |
| url: "http://nptriton.cqproject.net/parse_technology_data.php", | |
| async: true, | |
| data: techData, | |
| success: function(data) { console.log("Technology Data Exchanged."); | |
| QQ.vars.technology = data; | |
| // console.log(data); | |
| }, | |
| error: function() { console.log("Could not exchange Technology Data."); }, | |
| dataType: "JSON" | |
| }); | |
| } | |
| // -------------------------------------------------------------------- | |
| // helper functions --------------------------------------------------- | |
| QQ.fn = {}; | |
| QQ.fn.brize = function(text) { // converts new line to <br> | |
| return text.replace(new RegExp('\r?\n','g'), '<br>\n'); | |
| } | |
| String.prototype.brize = function() { | |
| return QQ.fn.brize(this); | |
| } | |
| QQ.fn.substract = function(carr,arr) { | |
| return carr.filter( function(item) { return !(arr.indexOf(item) >= 0); } ); | |
| } | |
| QQ.fn.peel = function(carr) { | |
| return carr.reduce( function(prev,cur) { return [].concat(prev,cur); } ); | |
| } | |
| QQ.fn.compare = function(a,b,direction) { | |
| if (direction === null) direction = "asc"; | |
| return (direction == "asc") ? (a - b) : (b - a); | |
| } | |
| QQ.fn.sort = function(arr1,arr2,direction) { | |
| if (arr1.length != arr2.length) return 0; | |
| if (direction === null) direction = "asc"; | |
| var sorted = []; | |
| for (var i=0; i<arr2.length; i++) { | |
| sorted.push([arr1[i], arr2[i]]); | |
| } | |
| sorted.sort(function(a,b) {return QQ.fn.compare(a[0],b[0],direction); } ); | |
| return sorted; | |
| } | |
| QQ.fn.lpad = function (n,len,del) { | |
| if (del === null) del = " "; | |
| len = (len - String(n).length + 1); | |
| if (len < 0) len = 0; | |
| return (new Array(len)).join(del).concat(n); | |
| } | |
| QQ.fn.rpad = function (n,len,del) { | |
| if (del === null) del = " "; | |
| len = (len - String(n).length + 1); | |
| if (len < 0) len = 0; | |
| return String(n).concat((new Array(len)).join(del)); | |
| } | |
| $(document).ready(function() { | |
| $('head').append("<link rel='stylesheet' href='http://nptriton.cqproject.net/style.css' type='text/css'>"); | |
| //window.setTimeout(QQ.initUI, 2500); // wait until the client loads and initializes javascript UI | |
| QQ.getServerData(QQ.inform); // calls initUI() | |
| // QQ.initOverride(1); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Neptune's Pride 2 - Triton userscript | |
| // @version 0.11.10 | |
| // @description This plugin works with Triton's data structures and performs advanced tasks on them. | |
| // @namespace http://cqproject.net/ | |
| // @author Vitezslav Ferko (Qwerty), [email protected] | |
| // @copyright 2014+, Vitezslav Ferko (Qwerty), [email protected] | |
| // @licence Released under MIT licence | |
| // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), | |
| // to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
| // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so. | |
| // @downloadURL http://nptriton.cqproject.net/qscript-nptriton.monkey.js | |
| // //run-at document-start | |
| // @match http*://triton.ironhelmet.com/game/* | |
| // //match http*://triton.ironhelmet.com/game* | |
| // //match http*://tritonsandbox.appspot.com/game* | |
| // @require http://code.jquery.com/jquery-latest.js | |
| // ==/UserScript== | |
| unsafeWindow.QQ = {}; // global | |
| QQ.vars = {}; | |
| // document.getElementsByTagName("script")[(3|16)] | |
| // Crux.crux.children[1].map; | |
| $(document).ready(function() { | |
| // $("#contentArea").empty(); | |
| // Crux.init("#contentArea"); | |
| // Crux.templates = NeptunesPride.templates | |
| // unsafeWindow.np = {}; | |
| // np.universe = NeptunesPride.Universe(); | |
| // np.inbox = NeptunesPride.Inbox(np.universe); | |
| // np.npui = NeptunesPride.Interface(np.universe, np.inbox); | |
| // np.npuis = NeptunesPride.InterfaceScreens(np.npui, np.universe, np.inbox) | |
| // np.np = NeptunesPride.Game(np.universe, np.inbox, np.npui); | |
| // np.si = NeptunesPride.SharedInterface(np.npui); | |
| // // make the np.universe easy to access from the console. | |
| // NeptunesPride.universe = np.universe; | |
| // np.np.serverRequest({type: "order", order:"full_universe_report"}); | |
| $('head').append("<link rel='stylesheet' href='http://nptriton.cqproject.net/style.css' type='text/css'>"); | |
| //window.setTimeout(QQ.initUI, 2500); // wait until the client loads and initializes javascript UI | |
| QQ.getServerData(QQ.inform); | |
| }); | |
| QQ.initUI = function() { | |
| $(".widget.fullscreen").append('<div id="qcontainer" class="off"><div id="qbtn" class="awesome"></div><div class="qreload qbutton" title="reload server data"></div><div class="qreloadUI qbutton" title="reload UI"></div><div id="qpanel"></div><div id="qdiv"></div></div>'); | |
| $("#qbtn").click(function() { $("#qcontainer").toggleClass('on off') }); | |
| $(".qreload").click(function() {QQ.reload()}); | |
| $(".qreloadUI").click(function() {QQ.reloadUI()}); | |
| QQ.refreshPanel(); | |
| $("#qdiv").append('<div id="qbtnpanel"></div><div id="qcontent"></div>'); | |
| $("#qbtnpanel").append( | |
| '<div type="button" class="qbtn tech">Compare Tech</div>'+( | |
| (!QQ.alliances.list || QQ.alliances.list[0].length == 0) ? "" : | |
| '<div type="button" class="qbtn techAlliance">Alliance Tech</div>')+ | |
| '<div type="button" class="qbtn screenshot">Make Screenshot</div>'+ | |
| '<div type="button" class="qbtn galaxyTab">Galaxy screen</div>'+ | |
| '<div type="button" class="qbtn researchTab">Research</div>' | |
| ); | |
| $(".qbtn.tech").click(function() { QQ.show.tech() }); | |
| $(".qbtn.techAlliance").click(function() { QQ.show.techAlliance() }); | |
| $(".qbtn.historyView").click(function() { QQ.show.historyView() }); | |
| $(".qbtn.screenshot").click(function() { QQ.show.screenshotInterface() }); | |
| $(".qbtn.galaxyTab").click(function() { QQ.show.galaxyTab() }); | |
| $(".qbtn.researchTab").click(function() { QQ.show.researchTab() }); | |
| Mousetrap.bind(["k", "K"], QQ.toggleAIDisplayed); | |
| Mousetrap.bind(["y", "Y"], QQ.togglePersonalData); | |
| Mousetrap.bind(["a", "A"], QQ.toggleAlliancesDisplayed); | |
| Mousetrap.bind(["j", "J"], QQ.toggleCrosshair); | |
| // quickupgrade key binds | |
| // Mousetrap.bind(["+"], function() { Crux.crux.trigger("upgrade_economy"); }); | |
| // Mousetrap.bind(["ě"], function() { Crux.crux.trigger("upgrade_industry"); }); | |
| // Mousetrap.bind(["š"], function() { Crux.crux.trigger("upgrade_science"); }); | |
| } | |
| QQ.reload = function() { | |
| // QQ = {}; // possibly do complete restart in the future. | |
| // QQ.vars = {}; | |
| $("#qcontainer").remove(); | |
| console.log("Reloading .."); | |
| QQ.getServerData(); | |
| } | |
| QQ.reloadUI = function() { | |
| $("#qcontainer").remove(); | |
| this.refreshData(); | |
| this.initUI(); | |
| console.log("UI reloaded"); | |
| } | |
| QQ.refreshData = function() { | |
| with (this) { | |
| // TODO: run all getters | |
| getBasicData(); | |
| getPlayers(); | |
| getAlliances(); | |
| getStars(); | |
| if (NeptunesPride.gameNumber == 6537227089739776) | |
| { | |
| exchangeStarData(); | |
| exchangeTechnologyData(); | |
| historyView.sendUniverseData(); | |
| } | |
| } | |
| // TODO: refresh UI | |
| console.log("Data refreshed"); | |
| } | |
| QQ.refreshPanel = function() { | |
| $("#qpanel").html("Cycle "+QQ.cycle+" - Tick "+QQ.tick); | |
| } | |
| QQ.initExternalSources = function(callFunc) { | |
| if (callFunc === undefined) callFunc = function () {return 0}; | |
| // in order to not get two contentAreas we need to empty it first, so we can reload the np variables | |
| $("#contentArea").empty(); // reloads whole interface | |
| Crux.init("#contentArea"); | |
| Crux.templates = NeptunesPride.templates | |
| universe = NeptunesPride.Universe(); | |
| inbox = NeptunesPride.Inbox(universe); | |
| npui = NeptunesPride.Interface(universe, inbox); | |
| npuis = NeptunesPride.InterfaceScreens(npui, universe, inbox) | |
| np = NeptunesPride.Game(universe, inbox, npui); | |
| si = NeptunesPride.SharedInterface(npui); | |
| // np.serverRequest({type: "order", order:"full_universe_report"}); | |
| QQ.getServerData(callFunc); | |
| } | |
| QQ.screenshot = {}; | |
| QQ.screenshot.save = function() { | |
| // trying to get higher resolution from the canvas.. | |
| // var cf = 1 | |
| // var cw = 1920*cf; | |
| // var ch = 1080*cf; | |
| // $("body").css("overflow", "hidden"); | |
| // canvas = document.getElementsByTagName("canvas")[0]; | |
| // $(canvas).css("width", cw).css("height", ch); | |
| // canvas.width = cw; canvas.height = ch; | |
| window.location.href = document.getElementsByTagName("canvas")[0].toDataURL("image/jpeg").replace("image/jpeg", "image/octet-stream"); | |
| //window.location.href = document.getElementsByTagName("canvas")[0].toDataURL("image/png").replace("image/png", "image/octet-stream"); | |
| } | |
| QQ.screenshot.sendAsText = function() { | |
| var i = (document.getElementsByClassName("text_area")[1] == undefined) ? 0 : 1; | |
| document.getElementsByClassName("text_area")[i].value = document.getElementsByTagName("canvas")[0].toDataURL("image/jpeg"); | |
| } | |
| QQ.vars.toggleAIDisplayed = false; | |
| QQ.toggleAIDisplayed = function (){ | |
| var ss = NeptunesPride.universe.galaxy.stars; | |
| with (QQ.vars) | |
| if (!toggleAIDisplayed) { | |
| QQ.vars.aiStars = {}; | |
| for (var k in ss) | |
| if (ss[k].player != undefined && ss[k].player.ai == 1) { | |
| aiStars[k] = {}; | |
| aiStars[k].sprite_spriteX = ss[k].sprite.spriteX; | |
| aiStars[k].sprite_spriteY = ss[k].sprite.spriteY; | |
| aiStars[k].spriteOwner_spriteX = ss[k].spriteOwner.spriteX; | |
| aiStars[k].spriteOwner_spriteY = ss[k].spriteOwner.spriteY; | |
| ss[k].sprite.spriteX = 512; | |
| ss[k].sprite.spriteY = ss[k].spriteOwner.spriteY; | |
| ss[k].spriteOwner.spriteX = 512; | |
| ss[k].spriteOwner.spriteY = 0; | |
| } | |
| toggleAIDisplayed = true; | |
| } else { | |
| for (var k in ss) { | |
| if (ss[k].player != undefined && ss[k].player.ai == 1) { | |
| ss[k].sprite.spriteX = aiStars[k].sprite_spriteX; | |
| ss[k].sprite.spriteY = aiStars[k].sprite_spriteY; | |
| ss[k].spriteOwner.spriteX = aiStars[k].spriteOwner_spriteX; | |
| ss[k].spriteOwner.spriteY = aiStars[k].spriteOwner_spriteY; | |
| } | |
| } | |
| toggleAIDisplayed = false; | |
| } | |
| Crux.crux.trigger('map_refresh'); | |
| } // Mousetrap.bind(["k", "K"], toggleAIDisplayed); | |
| QQ.vars.togglePersonalData = false; | |
| QQ.togglePersonalData = function (){ | |
| var npStars=NeptunesPride.universe.galaxy.stars; | |
| var npFleets=NeptunesPride.universe.galaxy.fleets; | |
| with (QQ.vars) | |
| if (!togglePersonalData) { | |
| QQ.vars.stars = {}; | |
| QQ.vars.fleets = {}; | |
| for (var k in npStars) { | |
| var ai = !(toggleAIDisplayed && aiStars[k] != undefined); | |
| stars[k]={}; | |
| stars[k].totalDefenses = npStars[k].totalDefenses; | |
| stars[k].halo = npStars[k].halo; | |
| stars[k].e = npStars[k].e; | |
| stars[k].i = npStars[k].i; | |
| stars[k].s = npStars[k].s; | |
| if(ai) stars[k].sprite_spriteX = npStars[k].sprite.spriteX; | |
| if(ai) stars[k].spriteGate_visible = (npStars[k].spriteGate != undefined) ? npStars[k].spriteGate.visible : undefined; | |
| npStars[k].totalDefenses = 0; | |
| npStars[k].halo = undefined; | |
| npStars[k].e = 0; // While I can nullify the values for econ, ind and sci, the zeros are still shown above those stars. If I could just hide them, I wouldn't have to nullify them. | |
| npStars[k].i = 0; | |
| npStars[k].s = 0; | |
| if(ai) npStars[k].sprite.spriteX = 64; | |
| if(ai) if (npStars[k].spriteGate != undefined) npStars[k].spriteGate.visible = false; | |
| } | |
| for (var k in npFleets) { | |
| fleets[k]={}; | |
| fleets[k].sprite_visible = (npFleets[k].sprite != undefined) ? npFleets[k].sprite.visible : undefined; | |
| fleets[k].spriteOwner_visible = (npFleets[k].spriteOwner != undefined) ? npFleets[k].spriteOwner.visible : undefined; | |
| fleets[k].orbiting = npFleets[k].orbiting; | |
| fleets[k].path = npFleets[k].path; | |
| if (npFleets[k].sprite != undefined) npFleets[k].sprite.visible = false; | |
| if (npFleets[k].spriteOwner != undefined) npFleets[k].spriteOwner.visible = false; | |
| npFleets[k].orbiting = null; | |
| npFleets[k].path = []; | |
| } | |
| togglePersonalData = true; | |
| } else { | |
| for (var k in npStars) { | |
| var ai = !(toggleAIDisplayed && aiStars[k] != undefined); | |
| npStars[k].totalDefenses = stars[k].totalDefenses; | |
| npStars[k].halo = stars[k].halo; | |
| npStars[k].e = stars[k].e; | |
| npStars[k].i = stars[k].i; | |
| npStars[k].s = stars[k].s; | |
| if(ai) npStars[k].sprite.spriteX = stars[k].sprite_spriteX; | |
| if(ai) if (npStars[k].spriteGate != undefined) npStars[k].spriteGate.visible = stars[k].spriteGate_visible; | |
| } | |
| for (var k in npFleets) { | |
| if (npFleets[k].sprite != undefined) npFleets[k].sprite.visible = fleets[k].sprite_visible; | |
| if (npFleets[k].spriteOwner != undefined) npFleets[k].spriteOwner.visible = fleets[k].spriteOwner_visible; | |
| npFleets[k].orbiting = fleets[k].orbiting; | |
| npFleets[k].path = fleets[k].path; | |
| } | |
| togglePersonalData = false; | |
| } | |
| Crux.crux.trigger('map_refresh'); | |
| } // Mousetrap.bind(["y", "Y"], togglePersonalData); | |
| QQ.vars.toggleAlliancesDisplayed = false; | |
| QQ.toggleAlliancesDisplayed = function() { | |
| if ( QQ.alliances.list.length == 0 ) return 0; | |
| var ss = NeptunesPride.universe.galaxy.stars; | |
| with (QQ.vars) | |
| if (!toggleAlliancesDisplayed) { | |
| QQ.vars.allianceStars = {}; | |
| for (var k in ss) | |
| if (ss[k].player != undefined) { | |
| allianceStars[k] = {}; | |
| allianceStars[k].sprite_spriteX = ss[k].sprite.spriteX; | |
| allianceStars[k].sprite_spriteY = ss[k].sprite.spriteY; | |
| allianceStars[k].spriteOwner_spriteX = ss[k].spriteOwner.spriteX; | |
| allianceStars[k].spriteOwner_spriteY = ss[k].spriteOwner.spriteY; | |
| allianceStars[k].spriteGate_spriteY = ss[k].spriteOwner.spriteY; | |
| // sprite.sprite, spriteOwner.sprite | |
| var ssX, ssY, sOsX, sOsY; | |
| if (ss[k].player.ai != 1) { | |
| // ss[k].sprite.spriteX = 64*; | |
| // ss[k].sprite.spriteY = ss[k].spriteOwner.spriteY; | |
| ss[k].spriteOwner.spriteX = 64*(ss[k].puid/8>>0); | |
| ss[k].spriteOwner.spriteY = 64*(8-QQ.alliances.isInAlliance(ss[k].puid)); | |
| if (ss[k].spriteGate != undefined) ss[k].spriteGate.spriteY = 64*(8-QQ.alliances.isInAlliance(ss[k].puid)); | |
| } else { | |
| ss[k].sprite.spriteX = 512; | |
| ss[k].sprite.spriteY = ss[k].spriteOwner.spriteY; | |
| ss[k].spriteOwner.spriteX = 512; | |
| ss[k].spriteOwner.spriteY = 0; | |
| if (ss[k].spriteGate != undefined) ss[k].spriteGate.spriteY = ss[k].spriteOwner.spriteY; | |
| } | |
| } | |
| toggleAlliancesDisplayed = true; | |
| } else { | |
| for (var k in ss) { | |
| if (ss[k].player != undefined) { | |
| ss[k].sprite.spriteX = allianceStars[k].sprite_spriteX; | |
| ss[k].sprite.spriteY = allianceStars[k].sprite_spriteY; | |
| ss[k].spriteOwner.spriteX = allianceStars[k].spriteOwner_spriteX; | |
| ss[k].spriteOwner.spriteY = allianceStars[k].spriteOwner_spriteY; | |
| if (ss[k].spriteGate != undefined) ss[k].spriteGate.spriteY = allianceStars[k].spriteGate_spriteY; | |
| } | |
| } | |
| toggleAlliancesDisplayed = false; | |
| } | |
| Crux.crux.trigger('map_refresh'); | |
| }; // Mousetrap.bind(["a", "A"], QQ.toggleAlliancesDisplayed); | |
| // QPanel content ------------------------------------------------------------ | |
| QQ.show = {}; | |
| QQ.show.tech = function(sort_by, direction) { | |
| if (sort_by === undefined) sort_by = "infrastructure_value"; | |
| if (direction === undefined) direction = "desc"; | |
| if (!QQ.players) QQ.getPlayers(); | |
| var players = QQ.players; | |
| var html = ""; | |
| var techHtml = []; | |
| // sorting functions ----------------- | |
| var arr1 = []; var arr2 = []; | |
| QQ.vars.sorted = []; | |
| if (sort_by == "uid") { | |
| for (key in players) { | |
| arr1.push(players[key].uid); | |
| } | |
| QQ.vars.sorted = QQ.fn.sort(arr1,arr1,direction); | |
| } | |
| if (sort_by == "infrastructure_value") { | |
| for (key in players) { | |
| arr1.push(players[key].infrastructure_value); | |
| arr2.push(players[key].uid); | |
| } | |
| QQ.vars.sorted = QQ.fn.sort(arr1,arr2,direction); | |
| } | |
| if (sort_by == "alliance") { | |
| var pallied = QQ.fn.peel(QQ.alliances.list); | |
| var premaining = QQ.fn.substract(Object.keys(players).map(function(item) { return parseInt(item,10) }),pallied); | |
| var pconcat = [].concat(pallied,premaining); | |
| var sorted = []; | |
| for (var i=0; i<pconcat.length; i++) sorted.push([pconcat[i], pconcat[i]]); | |
| QQ.vars.sorted = sorted; | |
| } | |
| // hyperlinks for calling sorting functions - el.id : [<a>displayed txt</a>, function(call)] | |
| var hl = { | |
| uid : ["player.id", "uid"], | |
| inVal : ["infra.value*", "infrastructure_value"], | |
| ally : ["alliances", "alliance"] | |
| } | |
| for (key in hl) { hl[key][0] = '<a class="tech hotlinks" id="'+key+'">'+hl[key][0]+'</a>' }; // wrap keys in html tags | |
| for (key in players) { | |
| techHtml[key] = []; | |
| players[key].tech.forEach( function (item,index) { | |
| if (item > players[QQ.you].tech[index]) { compared = "higher" }; | |
| if (item < players[QQ.you].tech[index]) { compared = "lower" }; | |
| if (item == players[QQ.you].tech[index]) { compared = "same" }; | |
| if (key == QQ.you) { compared = "yours" }; | |
| // add style classes + pad the tech levels | |
| techHtml[key][index] = '<span class="'+compared+'">'+QQ.fn.rpad(item,4," ")+'</span>' | |
| }); | |
| }; | |
| html += "S H T E W B M = "+hl.inVal[0]+" | E I S | "+hl.uid[0]+" | "+hl.ally[0]+"\n"; | |
| QQ.vars.sorted.forEach( function (item) { // item[0] - sorted by, item[1] - player_id | |
| html += techHtml[item[1]].join("") +" = "+ QQ.fn.rpad(players[item[1]].infrastructure_value,5," ") +" "+ QQ.fn.rpad(players[item[1]].infrastructure.econ,4," ") +" "+ QQ.fn.rpad(players[item[1]].infrastructure.ind,4," ") +" "+ QQ.fn.rpad(players[item[1]].infrastructure.sci,4," ") +" "+ QQ.alliances.htmlColourOfPlayer(item[1]) + players[item[1]].hyperlink +" "+ (players[item[1]].active ? "<span style='font-size:75%'>"+players[item[1]].uid+"</span>" : "(AI)") + "\n"; //+" "+ players[key].color + "\n"; | |
| }); | |
| html += "*infrastructure value = ((E+1)E + 2(I+1)I + 8(S+1)S)/maxStars"; | |
| // QQ.sorted.forEach( function (item) { console.log(item) } ); | |
| // console.log(html); | |
| // brize(html); | |
| $("#qcontent").html(html.brize()); | |
| direction = (direction == "asc") ? "desc" : "asc"; | |
| for (key in hl) (function(key,hl){ $("#"+key).unbind("click").click( function() { QQ.show.tech(hl[key][1], direction); }) })(key,hl); | |
| } | |
| QQ.show.techAlliance = function(sort_by, direction) { | |
| if (sort_by === undefined) sort_by = "infrastructure_value"; | |
| if (direction === undefined) direction = "desc"; | |
| var alliances = QQ.alliances; | |
| var list = alliances.list; | |
| var html = ""; | |
| var techHtml = []; | |
| // sorting functions ----------------- | |
| var arr1 = []; var arr2 = []; | |
| QQ.vars.sortedAlliances = []; | |
| if (sort_by == "auid") { | |
| arr1 = Object.keys(list); | |
| QQ.vars.sortedAlliances = QQ.fn.sort(arr1,arr1,direction); | |
| } | |
| if (sort_by == "infrastructure_value") { | |
| for (key in list) { | |
| arr1.push(alliances.summaries[key].infrastructure_value); | |
| arr2.push(key); | |
| } | |
| QQ.vars.sortedAlliances = QQ.fn.sort(arr1,arr2,direction); | |
| } | |
| // hyperlinks for calling sorting functions - el.id : [<a>displayed txt</a>, function(call)] | |
| var hl = { | |
| uid : ["alliance.id", "auid"], | |
| inValS : ["inf_sum", "infrastructure_value"] | |
| } | |
| for (key in hl) { hl[key][0] = '<a class="tech hotlinks" id="'+key+'">'+hl[key][0]+'</a>' }; // wrap keys in html tags | |
| var totalTech = []; | |
| for (var auid in list) { | |
| techHtml[auid] = []; | |
| totalTech[auid] = 0; | |
| for (var tech in alliances.summaries[auid].tech) { | |
| var value = alliances.summaries[auid].tech[tech]; | |
| if (value > alliances.summaries[alliances.isInAlliance(QQ.you)].tech[tech]) { compared = "higher" }; | |
| if (value < alliances.summaries[alliances.isInAlliance(QQ.you)].tech[tech]) { compared = "lower" }; | |
| if (value == alliances.summaries[alliances.isInAlliance(QQ.you)].tech[tech]) { compared = "same" }; | |
| if (auid == alliances.isInAlliance(QQ.you)) { compared = "yours" }; | |
| totalTech[auid] += value; | |
| // add style classes + pad the tech levels | |
| var padding = 4; if (auid == list.length) padding = 1; | |
| techHtml[auid][tech] = '<span class="'+compared+'">'+QQ.fn.rpad(value,padding," ")+'</span>' | |
| }; | |
| }; | |
| totalTechHtml = []; | |
| for (var auid in totalTech) { | |
| var value = totalTech[auid]; | |
| if (value > totalTech[alliances.isInAlliance(QQ.you)]) { compared = "higher" }; | |
| if (value < totalTech[alliances.isInAlliance(QQ.you)]) { compared = "lower" }; | |
| if (value == totalTech[alliances.isInAlliance(QQ.you)]) { compared = "same" }; | |
| if (auid == alliances.isInAlliance(QQ.you)) { compared = "yours" }; | |
| totalTechHtml[auid] = '<span class="'+compared+'">'+QQ.fn.rpad(value,2," ")+'</span>' | |
| }; | |
| html += "S H T E W B M | X = "+hl.inValS[0]+" inf_avg | sum E I S | avg E I S | "+hl.uid[0]+"\n"; | |
| QQ.vars.sortedAlliances.forEach( function (item) { // item[0] - sorted by, item[1] - alliance_id | |
| html += techHtml[item[1]].join("") +"|"+ totalTechHtml[item[1]] +" = "+ QQ.fn.rpad(alliances.summaries[item[1]].infrastructure_value,5," ") +" "+ QQ.fn.rpad(alliances.averages[item[1]].infrastructure_value,0," ") +" | "+ QQ.fn.rpad(alliances.summaries[item[1]].infrastructure.econ,4," ") +" "+ QQ.fn.rpad(alliances.summaries[item[1]].infrastructure.ind,4," ") +" "+ QQ.fn.rpad(alliances.summaries[item[1]].infrastructure.sci,1," ") +" | "+ QQ.fn.rpad(alliances.averages[item[1]].infrastructure.econ,4," ") +" "+ QQ.fn.rpad(alliances.averages[item[1]].infrastructure.ind,4," ") +" "+ QQ.fn.rpad(alliances.averages[item[1]].infrastructure.sci,4," ") +" "+ QQ.alliances.htmlColourOfAlliance(item[1],'█▓▒░') +" "+ "<span style='font-size:75%'>"+item[1]+"</span>" + "\n"; //+" "+ players[key].color + "\n"; | |
| }); | |
| // html += ""; | |
| // QQ.sorted.forEach( function (item) { console.log(item) } ); | |
| // console.log(html); | |
| // brize(html); | |
| $("#qcontent").html(html.brize()); | |
| direction = (direction == "asc") ? "desc" : "asc"; | |
| for (key in hl) (function(key,hl){ $("#"+key).unbind("click").click( function() { QQ.show.techAlliance(hl[key][1], direction); }) })(key,hl); | |
| } | |
| QQ.show.historyView = function() { | |
| if (!QQ.historyView.enabled) { | |
| QQ.historyView.enabled = true; | |
| QQ.historyView.init(); | |
| } | |
| else QQ.historyView.disable(); | |
| } | |
| QQ.show.screenshotInterface = function() { | |
| if (!QQ.vars.screenshotInterface) { | |
| QQ.vars.screenshotInterface = true; | |
| $("html").css("overflow", "hidden"); | |
| $("body").css("overflow", "hidden"); | |
| $("#qcontent").empty(); | |
| $(".qbtn.screenshot").toggleClass('enabled'); | |
| $("#qdiv").toggleClass('screenshotInterface'); | |
| $("#qcontent").append('<div type="button" class="qbtn screenshot makeScreenshot">Save Screenshot</div><div type="button" class="qbtn screenshot sendScreenshot">Send as Message</div>'); | |
| $(".makeScreenshot").click(function() { QQ.screenshot.save() }); | |
| $(".sendScreenshot").click(function() { QQ.screenshot.sendAsText() }); | |
| QQ.toggleCrosshair(0); | |
| } | |
| else { | |
| QQ.vars.screenshotInterface = false; | |
| $(".qbtn.screenshot").toggleClass('enabled'); | |
| $("#qdiv").toggleClass('screenshotInterface'); | |
| $("#qcontent").empty(); | |
| QQ.toggleCrosshair(1); | |
| $("body").css("overflow", "auto"); | |
| $("html").css("overflow", "auto"); | |
| } | |
| } | |
| QQ.vars.toggleCrosshair = false; | |
| QQ.toggleCrosshair = function() { | |
| var chtoggle = QQ.vars.toggleCrosshair; | |
| console.log(); | |
| if (!chtoggle) { | |
| $("body").append('<div id="scrcrosshair"><div style="position:fixed; z-index:9999; border-left:1px solid red; width:1px; height:100%; left:50%;"></div><div style="position:fixed; z-index:9999; border-top:1px solid red; height:1px; width:100%; top:50%;"></div></div>'); | |
| QQ.vars.toggleCrosshair=true; | |
| } else { | |
| $("#scrcrosshair").remove(); | |
| QQ.vars.toggleCrosshair=false; | |
| } | |
| }; // Mousetrap.bind(["j", "J"], QQ.toggleCrosshair); | |
| QQ.show.galaxyTab = function() { | |
| $("#qcontent").empty(); | |
| $("#qdiv").toggleClass('galaxyTab'); | |
| var headerDict = { // layout | |
| uid : "S", | |
| puid : "P", | |
| "_1" : " ", | |
| e : "e", | |
| i : "i", | |
| s : "s", | |
| "_2" : " ", | |
| next_econ : "$e", | |
| next_ind : "$i", | |
| next_sci : "$s", | |
| "_3" : " ", | |
| r : "res", | |
| hyperlink : "name"}; | |
| var thead="<thead style='text-align:left;'><tr>"; | |
| Object.keys(headerDict).forEach(function(key){ | |
| if (key[0] == "_") thead+="<th><span style=\"position:relative; padding-left:10px\"> </span></th>"; | |
| else thead+="<th>"+headerDict[key]+"</th>"; | |
| }); | |
| thead+="</tr></thead>"; | |
| var html="<table style='width:100%'>"; | |
| html+=thead; | |
| QQ.vars.allianceStars.forEach(function(k){ // the actual printing of the table | |
| html+="<tr>"; | |
| html+="<td>"+k.uid+"</td><td>"+k.puid+"</td><td> </td>"+ | |
| "<td>"+k.e+"</td><td>"+k.i+"</td><td>"+k.s+"</td><td> </td>"+ | |
| "<td>"+k.next_econ+"</td><td>"+k.next_ind+"</td><td>"+k.next_sci+"</td><td> </td>"+ | |
| "<td>"+k.r+"</td><td>"+k.hyperlink+"</td>"; | |
| html+="</tr>"; | |
| }); | |
| html+="</table>"; | |
| $("#qcontent").html(html); | |
| } | |
| QQ.show.researchTab = function() { | |
| $("#qcontent").empty(); | |
| $("#qdiv").toggleClass('researchTab'); | |
| // $("#qcontent").html(QQ.vars.technology.brize()); | |
| var dict = { | |
| "scanning" : "scan", | |
| "propulsion" : "range", | |
| "terraforming" : "terra", | |
| "research" : "exp", | |
| "weapons" : "weap", | |
| "banking" : "bank", | |
| "manufacturing" : "manu"}; | |
| var headerDict = { | |
| "puid" : "P", | |
| "cash" : "cash", | |
| "r" : "r_now", | |
| "r_next" : "r_next", | |
| "r_eta" : "ETA", | |
| "sci" : "sci", | |
| "s" : "S", | |
| "h" : "R", | |
| "t" : "T", | |
| "e" : "E", | |
| "w" : "W", | |
| "b" : "B", | |
| "m" : "M"}; | |
| var thead="<thead style='text-align:left;'><tr>"; | |
| Object.keys(headerDict).forEach(function(key){ | |
| thead+="<th>"+headerDict[key]+"</th>"; | |
| }); | |
| thead+="</tr></thead>"; | |
| var html="<table style='width:100%'>"; | |
| html+=thead; | |
| QQ.vars.technology.forEach(function(z,k){ | |
| html+="<tr>"; | |
| Object.keys(QQ.vars.technology[k]).forEach(function(key,i){ | |
| cssClass=""; | |
| if (key == "r_next" || i-6 == Object.keys(dict).indexOf(QQ.vars.technology[k]["r_next"])) cssClass="_r_next"; | |
| if (key == "r" || i-6 == Object.keys(dict).indexOf(QQ.vars.technology[k]["r"])) cssClass="_r_now"; // the order controls what has higher priority as a style | |
| if (key == "r" || key == "r_next") html+="<td class='td-research"+cssClass+"'>"+dict[QQ.vars.technology[k][key]]+"</td>" // translates long research name to shorter (dict) | |
| else html+="<td"+((cssClass != "")?" class='td-research"+cssClass+"'":"")+">"+QQ.vars.technology[k][key]+"</td>"; | |
| }); | |
| html+="</tr>"; | |
| }); | |
| html+="</table>"; | |
| $("#qcontent").html(html); | |
| } | |
| // alliances ------------------------------------------------------------ | |
| QQ.alliances = {}; | |
| QQ.alliances.colourList = ["purple", "violet", "red", "orange", "yellow", "green", "cyan", "blue"]; | |
| QQ.alliances.isInAlliance = function (pid) { | |
| for (var i=0; i<QQ.alliances.list.length; i++) { | |
| if (QQ.alliances.list[i].indexOf(pid) != -1) return i; | |
| } | |
| return -1; | |
| } | |
| QQ.alliances.htmlColourOfPlayer = function (pid,symbol) { | |
| if (symbol === undefined) symbol = "█"; // 176:░,177:▒,178:▓ | |
| var auid = QQ.alliances.isInAlliance(pid); | |
| return (auid != -1) ? QQ.alliances.htmlColourOfAlliance(auid,symbol) : ""; | |
| } | |
| QQ.alliances.htmlColourOfAlliance = function (auid,symbol) { | |
| if (symbol === undefined) symbol = "█"; // 176:░,177:▒,178: | |
| return "<span style='color:"+QQ.alliances.colourList[auid]+"'>"+symbol+"</span>"; | |
| } | |
| // history ------------------------------------------------------------ | |
| QQ.historyView = {}; | |
| QQ.historyView.init = function () { | |
| QQ.initExternalSources(function (data){ np.onServerResponse(data); if (QQ.historyView.enabled) QQ.historyView.enable(); }); | |
| } | |
| QQ.historyView.enable = function() { | |
| QQ.historyView.enabled = true; | |
| $(".qbtn.historyView").toggleClass('enabled').html(('Disable historyView')); | |
| $("#qcontainer").removeClass('off').addClass('on'); | |
| $("#qdiv").toggleClass('historyView'); | |
| $(".qbtn.tech").remove(); | |
| universe.galaxy.fleets = {} // remove fleets | |
| } | |
| QQ.historyView.disable = function() { | |
| // QQ.historyView.enabled = false; | |
| // QQ.historyView.init(); | |
| location.reload(); | |
| // $(".qbtn.historyView").toggleClass('enabled').html(('Enable historyView')); | |
| // $("#qdiv").toggleClass('historyView'); | |
| } | |
| QQ.historyView.sendUniverseData = function() { | |
| } | |
| QQ.historyView.refresh = function() { | |
| var us = universe.galaxy.stars; | |
| // var tso; // template .spriteOwner | |
| // for (key in us) { // find some star which is owned by a player to use as later reference | |
| // if (us[key].player != undefined) | |
| // { | |
| // tso = us[key].spriteOwner; // star template | |
| // break; | |
| // } | |
| // } | |
| // for (key in us) { | |
| // us[key].totalDefenses = 0; // remove all ships from a star | |
| // if (us[key].spriteOwner === undefined) // if current == undefined and history != undefined | |
| // { | |
| // us[key].spriteOwner = tso; // inject data of the star template | |
| // us[key].spriteOwner.ox = us[key].sprite.ox; // change the spriteOwner coordinates to match the actual star | |
| // us[key].spriteOwner.oy = us[key].sprite.oy; | |
| // } | |
| // us[key].spriteOwner.spriteX = us[44].spriteOwner.spriteX; // sets the player icon | |
| // us[key].spriteOwner.spriteY = us[44].spriteOwner.spriteY; | |
| // if (us[key].spriteGate != undefined) // sets the warp gate icon | |
| // { | |
| // us[key].spriteGate.spriteX = us[44].spriteGate.spriteX; | |
| // us[key].spriteGate.spriteY = us[44].spriteGate.spriteY; | |
| // } | |
| // } | |
| var s = NeptunesPride.universe.galaxy.stars; | |
| for (var k in s) { | |
| console.log(k, (s[k].ga || 0), (s[k])); | |
| } | |
| var ss = NeptunesPride.universe.galaxy.stars; | |
| with (QQ.vars) | |
| if (!toggleAlliancesDisplayed) { | |
| QQ.vars.allianceStars = {}; | |
| for (var k in ss) | |
| if (ss[k].player != undefined) { | |
| allianceStars[k] = {}; | |
| allianceStars[k].sprite_spriteX = ss[k].sprite.spriteX; | |
| allianceStars[k].sprite_spriteY = ss[k].sprite.spriteY; | |
| allianceStars[k].spriteOwner_spriteX = ss[k].spriteOwner.spriteX; | |
| allianceStars[k].spriteOwner_spriteY = ss[k].spriteOwner.spriteY; | |
| allianceStars[k].spriteGate_spriteY = ss[k].spriteOwner.spriteY; | |
| // sprite.sprite, spriteOwner.sprite | |
| var ssX, ssY, sOsX, sOsY; | |
| if (ss[k].player.ai != 1) { | |
| // ss[k].sprite.spriteX = 64*; | |
| // ss[k].sprite.spriteY = ss[k].spriteOwner.spriteY; | |
| ss[k].spriteOwner.spriteX = 64*(ss[k].puid/8>>0); | |
| ss[k].spriteOwner.spriteY = 64*(8-QQ.alliances.isInAlliance(ss[k].puid)); | |
| if (ss[k].spriteGate != undefined) ss[k].spriteGate.spriteY = 64*(8-QQ.alliances.isInAlliance(ss[k].puid)); | |
| } else { | |
| ss[k].sprite.spriteX = 512; | |
| ss[k].sprite.spriteY = ss[k].spriteOwner.spriteY; | |
| ss[k].spriteOwner.spriteX = 512; | |
| ss[k].spriteOwner.spriteY = 0; | |
| if (ss[k].spriteGate != undefined) ss[k].spriteGate.spriteY = ss[k].spriteOwner.spriteY; | |
| } | |
| } | |
| toggleAlliancesDisplayed = true; | |
| } else { | |
| for (var k in ss) { | |
| if (ss[k].player != undefined) { | |
| ss[k].sprite.spriteX = allianceStars[k].sprite_spriteX; | |
| ss[k].sprite.spriteY = allianceStars[k].sprite_spriteY; | |
| ss[k].spriteOwner.spriteX = allianceStars[k].spriteOwner_spriteX; | |
| ss[k].spriteOwner.spriteY = allianceStars[k].spriteOwner_spriteY; | |
| if (ss[k].spriteGate != undefined) ss[k].spriteGate.spriteY = allianceStars[k].spriteGate_spriteY; | |
| } | |
| } | |
| toggleAlliancesDisplayed = false; | |
| } | |
| Crux.crux.trigger('map_refresh'); | |
| } | |
| QQ.historyView.next = function(count) { }; | |
| QQ.historyView.previous = function(count) { }; | |
| // TODO .nextPayment() calls next(number_of_ticks) | |
| // GETTERS ------------------------------------------------------------ | |
| QQ.getServerData = function(callFunc) { | |
| if (callFunc === undefined) callFunc = function () {return 0}; | |
| var requestVars = { | |
| "type" : "order", | |
| "order" : "full_universe_report", | |
| "version" : NeptunesPride.version, | |
| "game_number" : NeptunesPride.gameNumber | |
| }; | |
| $.ajax({ | |
| type: "POST", | |
| url: "/grequest/order", | |
| async: true, | |
| data: requestVars, | |
| success: function(data) { console.log("Ajax call succeeded"); QQ.report = data.report; QQ.refreshData(); QQ.initUI(); callFunc(data);/* re-run all getters? */}, // TODO: initUI and refresh isn't meant to be run together. init only on first start and reload. | |
| error: function() { console.log("Ajax call failed") }, | |
| complete: function() { }, | |
| dataType: "json" | |
| }); | |
| } | |
| QQ.getBasicData = function() { | |
| QQ.tick = QQ.report.tick; | |
| QQ.cycle = QQ.report.productions; | |
| QQ.you = QQ.report.player_uid; | |
| } | |
| QQ.getAlliances = function() { | |
| // usage: http://triton.ironhelmet.com/game/5309705807200256?[[0,1,2,3],[4,5,6]] | |
| // where numbers in arrays are player IDs | |
| var list = JSON.parse(decodeURI(location.hash.substr(1)) || "[[]]"); | |
| if ( Object.prototype.toString.call(list) != "[object Array]" ) return 0; | |
| QQ.alliances.list = []; | |
| for ( var k in list ) { | |
| QQ.alliances.list[k] = []; | |
| for ( var j in list[k]) { | |
| if ( typeof list[k][j] == "number" ) { | |
| QQ.alliances.list[k].push(list[k][j]) | |
| } else { | |
| //[[1,15,20,0,[1,2]],[9,10,16,[2,1]],[13,19,22,[3,1]],[5,6,23,[4,3]],[7,8,11,[5,4]],[3,4,21,[6,2]]] | |
| // TODO [[puid(s),[colour,shape]],[... | |
| } | |
| } | |
| } | |
| QQ.alliances.summaries = {}; | |
| QQ.alliances.averages = {}; | |
| with (QQ) | |
| alliances.list.forEach(function(item,auid){ | |
| alliances.summaries[auid] = {}; | |
| alliances.averages[auid] = {}; | |
| var as = alliances.summaries[auid]; | |
| as.infrastructure = {econ:0,ind:0,sci:0}; | |
| as.infrastructure_value = 0; | |
| as.ships = 0; | |
| as.shipsPerDay = 0; | |
| as.tech = {}; | |
| var totalMembers = 0; // totalMembers of an alliance | |
| item.forEach(function(puid,i){ totalMembers = i+1; | |
| as.infrastructure.econ += players[puid].infrastructure.econ; | |
| as.infrastructure.ind += players[puid].infrastructure.ind; | |
| as.infrastructure.sci += players[puid].infrastructure.sci; | |
| as.infrastructure_value += players[puid].infrastructure_value; | |
| as.ships += players[puid].ships; | |
| as.shipsPerDay += players[puid].shipsPerDay; | |
| for (var k in players[puid].tech) { | |
| as.tech[k] = (players[puid].tech[k] > (as.tech[k] || 0)) ? players[puid].tech[k] : as.tech[k]; | |
| } | |
| }) | |
| var aa = alliances.averages[auid]; | |
| aa.infrastructure = {}; | |
| aa.tech = {}; | |
| aa.infrastructure.econ = as.infrastructure.econ / totalMembers >> 0; | |
| aa.infrastructure.ind = as.infrastructure.ind / totalMembers >> 0; | |
| aa.infrastructure.sci = as.infrastructure.sci / totalMembers >> 0; | |
| aa.infrastructure_value = as.infrastructure_value / totalMembers >> 0; | |
| aa.ships = as.ships / totalMembers >> 0; | |
| aa.shipsPerDay = as.shipsPerDay / totalMembers >> 0; | |
| for (var k in as.tech) { | |
| aa.tech[k] = as.tech[k]; | |
| } | |
| }) | |
| } | |
| QQ.getStars = function() { | |
| // // all stars | |
| // v: visibility (within your scanner range) | |
| // x: coordinate x | |
| // y: coordinate y | |
| // n: name | |
| // uid: star uid | |
| // puid: player uid (-1 neutral) | |
| // // only at scanned stars | |
| // c: ? 0 or 0.5 | |
| // e: economy | |
| // i: industry | |
| // s: science | |
| // ga: gate | |
| // r: resources | |
| // nr: natural resources | |
| // st: ? - always 0 | |
| QQ.stars = QQ.report.stars; | |
| Object.keys(QQ.stars).forEach(function(id){QQ.stars[id].hyperlink = "<a onClick=\"Crux.crux.trigger('show_star_uid', '"+id+"' )\">"+QQ.stars[id].n+"</a>"}) | |
| } | |
| QQ.getStarsOfAPlayer = function() { | |
| } | |
| QQ.getPlayers = function() { | |
| var rpl = QQ.report.players; | |
| var players = {}; | |
| // get the maximum number of stars a player has | |
| // var starCounts = []; | |
| var maxStars = 0; | |
| Object.keys(rpl).forEach(function(i){ | |
| // starCounts.push(rpl[i].total_stars); | |
| if (rpl[i].total_stars > maxStars) maxStars = rpl[i].total_stars; | |
| }); | |
| for (key in Object.keys(rpl)) { | |
| players[key] = { | |
| uid : rpl[key].uid, | |
| alias : rpl[key].alias, | |
| hyperlink : "<a onClick=\"Crux.crux.trigger('show_player_uid', '"+rpl[key].uid+"' )\">"+rpl[key].alias+"</a>", | |
| color : rpl[key].colorName, | |
| active : ((rpl[key].conceded == 0) && (rpl[key].ai == 0)), | |
| infrastructure_value : (((rpl[key].total_economy+1)*rpl[key].total_economy/2 | |
| + (rpl[key].total_industry+1)*rpl[key].total_industry | |
| + (rpl[key].total_science+1)*rpl[key].total_science*4)/maxStars) >>> 0, | |
| // infrastructure_value : rpl[key].total_economy | |
| // + rpl[key].total_industry*2 | |
| // + rpl[key].total_science*8, | |
| infrastructure : { econ: rpl[key].total_economy, ind: rpl[key].total_industry, sci: rpl[key].total_science }, | |
| tech_names: [ "scanning", "hyperspace range", "terraforming", "experimentation", "weapons", "banking", "manufacturing" ], | |
| tech : [ rpl[key].tech.scanning.level, rpl[key].tech.propulsion.level, rpl[key].tech.terraforming.level, rpl[key].tech.research.level, rpl[key].tech.weapons.level, rpl[key].tech.banking.level, rpl[key].tech.manufacturing.level ], | |
| ships : rpl[key].total_strength, | |
| // shipsPerDay : 24*rpl[key].shipsPerTick | |
| shipsPerDay : rpl[key].total_industry*(rpl[key].tech.manufacturing.value+5)/24 | |
| } | |
| } | |
| QQ.players = players; | |
| } | |
| // -------------------------------------------------------------------- | |
| // other functions ---------------------------------------------------- | |
| QQ.inform = function(){ | |
| $.ajax({ | |
| type: "POST", | |
| url: "http://nptriton.cqproject.net/parse.php", | |
| async: true, | |
| // data: {0:[[NeptunesPride.gameNumber,QQ.tick,NeptunesPride.universe.galaxy.player_uid,NeptunesPride.universe.galaxy.players[NeptunesPride.universe.galaxy.player_uid].alias],[NeptunesPride.account.alias,NeptunesPride.account.user_id,NeptunesPride.account.premium]]}, | |
| data: {0:[[],[NeptunesPride.account.alias,NeptunesPride.account.user_id,NeptunesPride.account.premium]]}, | |
| dataType: "text", | |
| success: function(data) {console.log(data);} | |
| }); | |
| } | |
| QQ.purchaseWarpGates = function (check,initialized) { | |
| if (check != "yes") { console.log('must call with "yes" parameter'); return 0; } | |
| if (initialized === undefined) initialized = 0; | |
| var count = 0, | |
| price = 0; | |
| // init required | |
| if (!initialized) { QQ.initExternalSources(function (data){ np.onServerResponse(data); QQ.purchaseWarpGates("yes",1); }); } | |
| else { | |
| for (key in universe.galaxy.stars) | |
| if ((universe.galaxy.stars[key].puid == universe.galaxy.player_uid) && (!universe.galaxy.stars[key].ga)) | |
| { | |
| var selectedStar = universe.galaxy.stars[key]; | |
| var uid = selectedStar.uid; | |
| var ucg = selectedStar.ucg; | |
| console.log(count + ": " + uid + "=$" + ucg); | |
| np.trigger("server_request", {type: "batched_order", order: "buy_warp_gate," + uid + "," + ucg}); | |
| // universe.buyWarpGate(universe.galaxy.stars[key]); // passing star as argument won't take effect | |
| // using following instead | |
| universe.player.cash -= ucg; | |
| selectedStar.ucg = 0; | |
| selectedStar.ga = 1; | |
| count++; | |
| price+=ucg; | |
| } | |
| np.trigger("refresh_interface"); | |
| np.trigger("map_rebuild"); | |
| console.log(count + " Warpgates purchased for $" + price + "."); | |
| } | |
| } | |
| QQ.missedTurns = function(){ | |
| Object.keys(NeptunesPride.universe.galaxy.players).forEach(function(val){var pl = NeptunesPride.universe.galaxy.players[val]; (pl.missed_turns > 0)?console.log(val, pl.alias, ", missed", pl.missed_turns):""}); | |
| } | |
| QQ.exchangeStarData = function(){ | |
| var starData = {}; | |
| Object.keys(QQ.stars).forEach(function(i){ if (QQ.stars[i].puid == QQ.you) {var s = QQ.stars[i]; starData[i] = {"e":s["e"],"i":s["i"],"s":s["s"],"r":s["r"],"n":s["n"],"uid":s["uid"],"puid":s["puid"]}} }); | |
| $.ajax({ | |
| type: "POST", | |
| url: "http://nptriton.cqproject.net/parse_star_data.php", | |
| async: true, | |
| data: starData, | |
| success: function(data) { console.log("Star Data Exchanged."); | |
| QQ.vars.allianceStars = data; | |
| QQ.vars.allianceStars.forEach(function(star){star.hyperlink = "<a onClick=\"Crux.crux.trigger('show_star_uid', '"+star.uid+"' )\">"+star.n+"</a>"}); | |
| // console.log(data); | |
| }, | |
| error: function() { console.log("Could not exchange Star Data."); }, | |
| dataType: "JSON" | |
| }); | |
| } | |
| QQ.exchangeTechnologyData = function(){ | |
| var u = NeptunesPride.universe.player; | |
| var techData = {"puid":u.uid,"cash":u.cash,"r":u.researching,"r_next":u.researching_next,"r_eta":Math.ceil((u.tech[u.researching].brr*u.tech[u.researching].level-u.tech[u.researching].research)/u.total_science),"sci":u.total_science,"tech":{"s":u.tech.scanning.research,"h":u.tech.propulsion.research,"t":u.tech.terraforming.research,"e":u.tech.research.research,"w":u.tech.weapons.research,"b":u.tech.banking.research,"m":u.tech.manufacturing.research}} | |
| $.ajax({ | |
| type: "POST", | |
| url: "http://nptriton.cqproject.net/parse_technology_data.php", | |
| async: true, | |
| data: techData, | |
| success: function(data) { console.log("Technology Data Exchanged."); | |
| QQ.vars.technology = data; | |
| // console.log(data); | |
| }, | |
| error: function() { console.log("Could not exchange Technology Data."); }, | |
| dataType: "JSON" | |
| }); | |
| } | |
| // -------------------------------------------------------------------- | |
| // helper functions --------------------------------------------------- | |
| QQ.fn = {}; | |
| QQ.fn.brize = function(text) { // converts new line to <br> | |
| return text.replace(new RegExp('\r?\n','g'), '<br>\n'); | |
| } | |
| String.prototype.brize = function() { | |
| return QQ.fn.brize(this); | |
| } | |
| QQ.fn.substract = function(carr,arr) { | |
| return carr.filter( function(item) { return !(arr.indexOf(item) >= 0); } ); | |
| } | |
| QQ.fn.peel = function(carr) { | |
| return carr.reduce( function(prev,cur) { return [].concat(prev,cur); } ); | |
| } | |
| QQ.fn.compare = function(a,b,direction) { | |
| if (direction === undefined) direction = "asc"; | |
| return (direction == "asc") ? (a - b) : (b - a); | |
| } | |
| QQ.fn.sort = function(arr1,arr2,direction) { | |
| if (arr1.length != arr2.length) return 0; | |
| if (direction === undefined) direction = "asc"; | |
| var sorted = []; | |
| for (var i=0; i<arr2.length; i++) { | |
| sorted.push([arr1[i], arr2[i]]); | |
| } | |
| sorted.sort(function(a,b) {return QQ.fn.compare(a[0],b[0],direction); } ); | |
| return sorted; | |
| } | |
| QQ.fn.lpad = function (n,len,del) { | |
| if (del === undefined) del = " "; | |
| len = (len - String(n).length + 1); | |
| if (len < 0) len = 0; | |
| return (new Array(len)).join(del).concat(n); | |
| } | |
| QQ.fn.rpad = function (n,len,del) { | |
| if (del === undefined) del = " "; | |
| len = (len - String(n).length + 1); | |
| if (len < 0) len = 0; | |
| return String(n).concat((new Array(len)).join(del)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment