2023-10-17 04:16:35 +00:00
|
|
|
db := 'db/game.rec'
|
|
|
|
|
2022-10-10 17:19:24 +00:00
|
|
|
# show all commands
|
|
|
|
default:
|
|
|
|
just --list --unsorted
|
|
|
|
|
|
|
|
# super plain boring output
|
|
|
|
_map:
|
2023-10-17 04:16:35 +00:00
|
|
|
recsel -t game {{db}} | recfmt '"{{{{name}}": "{{{{id}}", '
|
2022-10-10 17:19:24 +00:00
|
|
|
|
|
|
|
# build dot file
|
|
|
|
# TODO: change id to name? or id /and/ name?
|
2023-10-17 04:16:35 +00:00
|
|
|
# TODO: how do you document a wicked sed script?
|
2022-10-10 17:19:24 +00:00
|
|
|
_dot:
|
|
|
|
#!/usr/bin/env zsh
|
2023-10-17 04:16:35 +00:00
|
|
|
echo "digraph {" > tmp/dot
|
|
|
|
recsel -t game {{db}} \
|
|
|
|
| recfmt '{{{{id}} -> {{{{text}}|' \
|
|
|
|
| sed -e 's/|/\n\n/g' \
|
|
|
|
| sed -e '/./{H;$!d;}' -e 'x; s/\n//g; G;' \
|
|
|
|
| sed -e 's/}}[^{]*{{{{/}} {{{{/g' -e 's/> [^{]* {{{{/> {{{{/' \
|
|
|
|
| sed -e 's/}}[^{]*/}} /' \
|
|
|
|
| sed -e '/{{{{/!d' -e 's/\.$//' \
|
|
|
|
| sed -e 's/> \(.*\)$/> { \1 };/' \
|
|
|
|
>> tmp/dot
|
|
|
|
echo "}" >> tmp/dot
|
|
|
|
|
|
|
|
# an alternative syntax to dot that allows for unicode graphs
|
|
|
|
_grapheasy:
|
|
|
|
#!/usr/bin/env zsh
|
|
|
|
recsel -t game {{db}} \
|
2022-10-10 17:19:24 +00:00
|
|
|
| recfmt '{{{{id}} -> {{{{text}}|' \
|
|
|
|
| sed -e 's/|/\n\n/g' \
|
|
|
|
| sed -e '/./{H;$!d;}' -e 'x; s/\n//g; G;' \
|
|
|
|
| sed -e 's/}}[^{]*{{{{/}} {{{{/g' -e 's/> [^{]* {{{{/> {{{{/' \
|
|
|
|
| sed -e 's/}}[^{]*/}} /' \
|
|
|
|
| sed -e '/{{{{/!d' -e 's/\.$//' \
|
|
|
|
| sed -e 's/> \(.*\)$/> { \1 };/' \
|
2023-10-17 04:16:35 +00:00
|
|
|
| sed -e 's/^\([0-9]*\) -> {/[ \1 ] -->/' \
|
|
|
|
| sed 's/};$//' \
|
|
|
|
| sed 's/}} {{{{/>> ], [ <</g' \
|
|
|
|
| sed 's/{{{{/[ <</' \
|
|
|
|
| sed 's/}}/>> ]/' \
|
|
|
|
| sed 's/<</{{{{/g' \
|
|
|
|
| sed 's/>>/}}/g' \
|
|
|
|
> tmp/grapheasy
|
|
|
|
mustache tmp/data tmp/grapheasy \
|
|
|
|
| gsed '1 i graph { flow: south; }' \
|
|
|
|
| graph-easy --as=boxart \
|
|
|
|
| less
|
2022-10-10 17:19:24 +00:00
|
|
|
|
|
|
|
# build a graph of all the nodes
|
|
|
|
graph: _data _dot
|
2023-10-17 04:16:35 +00:00
|
|
|
mustache tmp/data tmp/dot | dot -Tpng > out/graph.png
|
2022-10-10 17:19:24 +00:00
|
|
|
|
|
|
|
# build data object
|
|
|
|
_data:
|
|
|
|
echo "{" $(just _map) "}" \
|
|
|
|
| sed -e 's/, }/ }/' \
|
2023-10-17 04:16:35 +00:00
|
|
|
> tmp/data
|
2022-10-10 17:19:24 +00:00
|
|
|
|
|
|
|
# plain output
|
|
|
|
build: _data
|
2023-10-17 04:16:35 +00:00
|
|
|
mustache tmp/data {{db}} \
|
2022-10-10 17:19:24 +00:00
|
|
|
| recfmt '{{{{id}}: {{{{text}}|' \
|
|
|
|
| sed -e 's/|/\n\n/g' \
|
|
|
|
|
|
|
|
# read the story
|
|
|
|
browse:
|
|
|
|
just build | fmt | less
|
|
|
|
|
|
|
|
# remove generated files
|
|
|
|
clean:
|
2023-10-17 04:16:35 +00:00
|
|
|
rm -f tmp/* out/*
|
2022-10-10 17:19:24 +00:00
|
|
|
|
2023-10-17 13:23:32 +00:00
|
|
|
# word count and number of nodes
|
|
|
|
info:
|
|
|
|
echo "$(recinf -t game {{db}}) nodes" \
|
|
|
|
&& echo "$(recsel -t game -P text {{db}} | wc -w | awk '{ print $1}') words"
|
2023-10-17 04:16:35 +00:00
|
|
|
|
|
|
|
# rebulid graph on change
|
|
|
|
watch:
|
|
|
|
ls {{db}} | entr -c just graph
|
|
|
|
|
|
|
|
# shuffle ids
|
|
|
|
_shuffle:
|
|
|
|
recsel -t game -P id db/game.rec \
|
|
|
|
| sed '/^$/d' \
|
|
|
|
| shuf --random-source=/dev/urandom \
|
|
|
|
| gsed -e '/^0$/d' -e '1 i 0'
|
|
|
|
|
|
|
|
# story in random order, starting with 1
|
|
|
|
randomize:
|
|
|
|
for n in $(just _shuffle); do recsel -t game -e "id='$n'" db/game.rec; echo; done
|
|
|
|
|
|
|
|
# renumber the randomized list
|
|
|
|
renumber:
|
|
|
|
#!/usr/bin/env zsh
|
|
|
|
tmpfile=$(mktemp)
|
|
|
|
echo "$tmpfile"
|
|
|
|
#cp {{db}} {{db}}.bak
|
|
|
|
just randomize > "$tmpfile"
|
|
|
|
j=$(recinf -t game "$tmpfile")
|
|
|
|
recdel -t game -n 0-$((j - 1)) {{db}}
|
|
|
|
for i in {0..$((j - 1))}
|
|
|
|
do
|
|
|
|
name=$(recsel -n "$i" -P name "$tmpfile")
|
|
|
|
text=$(recsel -n "$i" -P text "$tmpfile")
|
|
|
|
echo "$i $name $text"
|
|
|
|
recins -t game -f name -v "$name" -f text -v "$text" {{db}}
|
|
|
|
done
|
|
|
|
rm "$tmpfile"
|
|
|
|
|
|
|
|
# get json
|
|
|
|
json:
|
|
|
|
recsel -t game {{db}} \
|
|
|
|
| rec2csv \
|
|
|
|
| csvjson \
|
|
|
|
| jq '. | { data: . }'
|
|
|
|
|
|
|
|
# make ms
|
|
|
|
_ms: _data
|
|
|
|
just json \
|
|
|
|
| mustache - templates/story.ms.template \
|
|
|
|
> tmp/story.ms
|
|
|
|
|
|
|
|
# make pdf
|
|
|
|
pdf: _ms
|
|
|
|
mustache tmp/data tmp/story.ms \
|
|
|
|
| groff -ms -Tpdf \
|
|
|
|
> out/story.pdf
|
|
|
|
|
|
|
|
# make ascii doc
|
|
|
|
ascii: _ms
|
|
|
|
mustache tmp/data tmp/story.ms \
|
|
|
|
| groff -ms -Tascii \
|
|
|
|
| sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" \
|
|
|
|
> out/story.txt
|
|
|
|
|
|
|
|
# generate tags
|
|
|
|
tags:
|
|
|
|
ctags --options=./lib/game.ctags db/game.rec
|