Last active
December 2, 2022 06:51
-
-
Save phrohdoh/e48928d763088f6d6917462ea631aff6 to your computer and use it in GitHub Desktop.
Querying the Age of Empires 1997 database (`empires.dat`) with jq and a custom `empires2json` tool
This file contains 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
# Requires: jq 1.5 | |
########## | |
# Hello and welcome! | |
# Quick note: Comments in a jq program file (which this is!) begin with a '#'. | |
# | |
# The comments in this file assume you have ran `empires2json` on your AoE's `empires.dat` file | |
# and stored the result in a `empires-dat.json` file on disk. | |
# | |
# To make use of this file you will need `jq` 1.5 (or a later version) installed (see https://stedolan.github.io/jq/). | |
# | |
# Below is an example invocation of jq (do not type the '$' into your shell): | |
# $ jq -f empires-helper.jq empires-dat.json | |
# | |
# How to use this file: | |
# Uncomment the filter you would like to use by removing the leading '#'s on each line (keep the double # lines as they explain what the filter does) | |
# then run the command given above (the line starting with "jq -f"). | |
# | |
# I recommend starting with this first filter so you can get a feel for what exactly is happening. | |
# | |
# When you run this filter jq will output a JSON array of objects | |
# containing the `id`, `name`, `short_name`, `slp_id`, and `frame_count` properties | |
# of all of the graphic objects in the input JSON whose name contains the string "Arrow". | |
# | |
# Please feel free to email me with questions, comments, concerns, etc. here: taryn@phrohdoh.com | |
########## | |
## Find all graphics with "Arrow" in the name | |
# [ | |
# .graphics[] | |
# | select(.name | contains("Arrow")) | |
# | {id, name, short_name, slp_id, frame_count} | |
# ] | |
## Find all graphics with associated delta graphics and get the delta graphic's `slp_id` property | |
#. as $root | | |
# [ | |
# .graphics[] | |
# | [ .deltas[] | .graphic_id ] as $delta_graphic_ids | |
# | [ $root | .graphics[] | select(.id | in($delta_graphic_ids)) | .slp_id ] as $delta_slp_ids | |
# | select($delta_slp_ids | length > 0) | |
# | { id | |
# , name | |
# , slp_id | |
# , delta_slp_ids: $delta_slp_ids } | |
# ] | |
## Find all units with `fly_mode` set to `false` | |
# [ | |
# .civilizations[] | |
# | .units | |
# | to_entries[] | |
# | .value | |
# | select(.fly_mode == false) | |
# | {id, name, standing_graphic} | |
# ] | |
## Find all units with at least 1 value in the `damage_graphics` array | |
# [ | |
# .civilizations[] | |
# | .units | |
# | to_entries[] | |
# | .value | |
# | select((.damage_graphics | length) > 0) | |
# | { id, | |
# name, | |
# graphic_ids: ([.damage_graphics[] | .graphic_id]) } | |
# ] | |
## Find the first 10 units with a name containing the string "Chariot" | |
# [ | |
# limit(10; .civilizations[] | |
# | .units | |
# | to_entries[] | |
# | .value | |
# | select(.name | contains("Chariot")) | |
# | { id | |
# , name | |
# , standing_graphic } | |
# ) | |
# ] | |
## Calculate how many `graphics` objects have a `short_name` of "None" | |
# [ | |
# .graphics[] | |
# | select(.short_name == "None") | |
# ] | length | |
## NOTE: To use this filter you must provide the value via the command-line. An example `jq` invocation follows (exclude the '$'). | |
## $ jq -f empires-helper.jq empires-dat.json --arg RESOURCE_TYPE "Gold" | |
## | |
## If you omit `--arg RESOURCE_TYPE "your value"` you will get an error similar to the following. | |
## jq: error: RESOURCE_TYPE/0 is not defined at <top-level>, line 78: | |
## Find all researches that have some amount of a resource cost (exactly which resource is provided on the command-line [see above]) | |
# [ | |
# .research[] | |
# | select(.resource_costs | any(.resource_type == $RESOURCE_TYPE)) | |
# | { id, name, required_techs } | |
# ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Real-world data
My local
empires.dat
has the following sha256:Running the following filter against the JSON produced from my local
empires.dat
fileresults in the following JSON