Downloading output of $Anacreon.objList

General discussion for the game Anacreon
Post Reply
Watch TV, Do Nothing
Militia Captain
Militia Captain
Posts: 803
Joined: Sun Feb 05, 2012 12:22 am
Contact:

I recently started messing around with my browser's JavaScript console but I don't actually know anything whatsoever about JavaScript.

Can anyone think of any way to output the nested array produced by $Anacreon.objList into something like a csv, dbf or xls? I am interested in playing around with a snapshot of the game state and creating interesting visualizations of it.
Watch TV, Do Nothing
Militia Captain
Militia Captain
Posts: 803
Joined: Sun Feb 05, 2012 12:22 am
Contact:

I was able to copy it to a UTM-8 notepad file but further attempts to process it as a JSON (e.g. with jsonlite in R) are throwing errors relating to premature end-of-file and illegal byte-order-mark, I'm not sure how to proceed.
Lazygun
Anarchist
Anarchist
Posts: 8
Joined: Sat Sep 17, 2016 12:13 am

I experimented a bit and ran into a few gotchas when trying to access the $Anacreon.objList programatically based on the browser:

Chrome displays it as more nested than it is, as a workaround. There are so many entries in the array and Chrome gives an arrow that you click to expand each entry onto its own line. tens of thousands of lines is just too much for Chrome to cope with at once. To access the object with id objID you need just $Anacreon.objList[objID]

The array has many missing elements so you might prefer

Code: Select all

for var ao in ($Anacreon.objList) {...}
which works in Chrome at least, rather than

Code: Select all

for (var i = 0; i < $Anacreon.ObjList.length; ++i) { var ao =$Anacreon.ObjList[i]; if (ao !== undefined) { ... }}
Each entry in $Anacreon.objList does contain some arrays. For instance worlds have $Anacreon.objList[objID].resources[]

And unfortunately it isn't as simple as the first item in the array being trillum and the second being hexacarbide. Instead the even numbered entries (starting at 0) give the kind of resource as an index into $Anacreon.designTypes[] and the odd numbered entries give the amounts.

Speaking of $Anacreon.designTypes[], you'll want to explore that one too because so very often all you have is an ID and you need to find out whether it refers to a ship type, a mineral concentration, a resource, a jumpship autofac or whatever, and designtypes[] is where you'll get that info.

Here's a snippet I was using that you might be able to adapt:

Code: Select all

for ($$i in $Anacreon.designTypes) {
	if ($Anacreon.designTypes[$$i].category == "commodity") {
		console.log($Anacreon.designTypes[$$i].id + "/" + $Anacreon.designTypes[$$i].name));
	}
}
copy and paste the whole lot into the console command line and if that doesn't work remove the line breaks and spaces.
Watch TV, Do Nothing
Militia Captain
Militia Captain
Posts: 803
Joined: Sun Feb 05, 2012 12:22 am
Contact:

For fellow javascript innocents also wanting to follow along at home, Lazygun's script, which uses a for loop on Anacreon.designTypes to find and names all design ids that are commodities, worked for me as:

Code: Select all

for ($$i in $Anacreon.designTypes) {
   if ($Anacreon.designTypes[$$i].category == "commodity") {
      console.log($Anacreon.designTypes[$$i].id + "/" + $Anacreon.designTypes[$$i].nameDesc));
   }
}
so I then just modified it to work on $Anacreon.objList, which contains basically every planet and fleet plus some extraneous stuff, to give me comma-separated X, Y, sovereign and TL values:

Code: Select all

for ($$i in $Anacreon.objList) {
   if ($Anacreon.objList[$$i].class == "world") {
      console.log($Anacreon.objList[$$i].mapPosX + "," + $Anacreon.objList[$$i].mapPosY + "," + $Anacreon.objList[$$i].sovereignID + "," + $Anacreon.objList[$$i].techLevel);
      }
}
right-clicking and saving the log to desktop (this is in the Chrome javascript console) produces a CSV file (once you delete the initial code from the log)
User avatar
6cef
Commonwealth Pilot
Commonwealth Pilot
Posts: 61
Joined: Wed Dec 22, 2010 12:33 am
Location: Charm City

  • Login to the game.
    • Using Chrome's dev tools, go to the "network" tab.
  • Reload the page. You see a bunch of output in the dev tools pane.
  • Probably at the bottom, see the getObjects entry in the "Name" column.
  • Right click and select "Copy response".
  • Format the JSON. For instance, navigate to https://jsonformatter.curiousconcept.com/ and paste.
    • If not properly formatted JSON, something is wrong, please submit a bug report.
    • Nothing is wrong, it's properly formatted JSON.
It's possible the clipboard text is too large, but it's more likely you paste it into a program or into a field on a website that doesn't like that much text.

Using the online JSON to csv converters easily found will not work. Using a naive JSON to csv converter will not work. This is because the JSON is JSON, not a rectangular array. What you need is to save each subset of objects in the JSON as a csv file and even then, you need to be smart about it. You'll need to extract all the worlds, fleets, regions, sovereigns, etc. and then output each set of those (all worlds, all fleets, etc.) as a distinct csv file. You must intelligently track properties: not all worlds (fleets,etc) will necessarily have all the same properties. You'll need to understand JSON to do all this. If you happen to know R, well, R is harder than JSON so have faith! ;)

There are also a lot of code numbers in the output of getObjects, like designation: 33. You can try

Code: Select all

JSON.stringify($Anacreon.designTypes)
in Chrome's dev tool console.

Still a lot of work to do, but the getObjects response is the entire game world as your empire sees it, and the $Anacreon.designTypes gives codes to help decipher things. Copy that JSON and run it through a formatter to make is more human readable. You'll find the same issues converting this to CSV, I suspect.

If you're feeling adventurous, when you right click getObjects, select "Copy as cURL". If you have access to a command line that has curl installed, paste that and use " > anacreon-get-objects.json" at the end of the command (without the quotes). curl will execute a call to the Anacreon server and the "> filename" bit will save the output. Might be easier to manipulate that way, certainly easier to script. Note the auth token, etc. in the curl script will change, so, again, there's more work to do making all this robust.

HTH,
Colin
starxplor
Militia Lieutenant
Militia Lieutenant
Posts: 117
Joined: Sun Mar 31, 2013 7:49 am

I know this is an old thread, but what on here isn't, heh.

Python has some really nice built in tools for mangling json objects. I can convert them directly to arrays and hashes which I have been able to use to track empire changes when playing in the past with a full galaxy map explored. Logging in and loading the galaxy is also trivial with the requests module.
getObjResponse.json() returns an array or table depending on the data so printing all objects the first time dealing with a response is helpful to figure out how to handle the data.

This was an attempt to store empire data for pattern mining that I gave up on because life got in the way (notice the last updated timestamp): http://starxplor.com/anacreon/empires.phtml
Check out empires Manasseh and NARN for examples of the info parse-able from a single login to the galaxy, this empire did not have much vision in the galaxy so these are the only two known.
Watch TV, Do Nothing
Militia Captain
Militia Captain
Posts: 803
Joined: Sun Feb 05, 2012 12:22 am
Contact:

Interesting work, thanks for sharing that. There is a lot of interesting data that can be accessed from querying, but I haven't figured out how to send meaningful orders to the server (e.g. moving fleets to destinations) through the console or by any other method than through the game client. I know that a few people have been able to do this.
starxplor
Militia Lieutenant
Militia Lieutenant
Posts: 117
Joined: Sun Mar 31, 2013 7:49 am

Watch TV, Do Nothing wrote:
Thu Feb 23, 2017 7:35 pm
Interesting work, thanks for sharing that. There is a lot of interesting data that can be accessed from querying, but I haven't figured out how to send meaningful orders to the server (e.g. moving fleets to destinations) through the console or by any other method than through the game client. I know that a few people have been able to do this.
The easiest way I know of is to write something that simulates exactly what your browser does (essentially a whole new web browser, without the GUI). I got bored and never got to that point in this game, but I have done it with others. The first step is to capture all the data back and forth, then write code that sends the exact same thing to the server. From there, play with what you send to see what changes can be made.

Maybe I should get back into the game and try my hand at text-mode client...
Post Reply