Skip to content

Commit

Permalink
feat: checkout bar repo and do some magic
Browse files Browse the repository at this point in the history
  • Loading branch information
wezzle committed Sep 3, 2024
0 parents commit b4f75cb
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
.idea
*.log
tmp/
.direnv
bar-repo
57 changes: 57 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
inputs = {
utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
utils,
}:
utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
just
lua
lua54Packages.dkjson
jq
];
};
}
);
}
25 changes: 25 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
init:
#!/usr/bin/env bash
git clone --filter=blob:none --no-checkout --depth 1 --sparse [email protected]:beyond-all-reason/Beyond-All-Reason.git bar-repo
cd bar-repo
git sparse-checkout set --no-cone "units" "language/en"
git sparse-checkout list
git checkout
find-by-name name:
cat bar-repo/language/en/units.json | jq '.units.names | to_entries | .[] | select(.value=="{{name}}") | .key'\

file key:
find bar-repo/units -name "{{key}}.lua";

data key:
cat `just file {{key}}`

data-json key:
lua tojson.lua `just file {{key}} | sed 's/.lua//'`

data-json-by-name name:
#!/usr/bin/env bash
set -euxo pipefail
key=`just find-by-name {{name}}`
lua tojson.lua `just file $key | sed 's/.lua//'` | jq '.[] | { metalcost: .metalcost, energycost: .energycost, buildtime: (.buildtime/100) }'
7 changes: 7 additions & 0 deletions tojson.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
local json = require ("dkjson")

local data = require(arg[1])

local str = json.encode (data, { indent = true })

print(str)

0 comments on commit b4f75cb

Please sign in to comment.