dozens 2022-09-29 16:25:51 -06:00
commit 23d719eff7
3 changed files with 141 additions and 0 deletions

31
README 100644
View File

@ -0,0 +1,31 @@
Choose Your Own Adventure
> doing it the bullshit way
## about
this is a choose your own adventure game fueled by recfiles and stuff
## requirements
- recutils v1.9: data and querying and templates
- mustache v4.2.0: more different templating
- just v1.4.0: command runner
- graphviz version 5.0.1: to make a graph
## getting started
the whole game is in a recfile
each record has an `id`.
each record has a `text` field that is the narrative text of the section, including branching choices.
branches should refernece the `name` of another field in {{mustachequotes}}.
to build the output, we will build a `data` object mapping all names to ids (with recsel and sed; see the justfile for details). next, mustache will use that data object to replace the template strings in the recfile with id numbers. finally the expanded data will be piped through recfmt, which will dump the text of the game.
you can also create a graph of the story nodes with `just graph` if you have graphviz installed. this is handy for visualing your story paths, studying the shape of your story, and seeing if you have any islands or orphan nodes. it does pretty much the same thing as `just build`, except it outputs a DOT file, and then creates `graph.png`.

65
game.rec 100644
View File

@ -0,0 +1,65 @@
%rec: game
%doc: a choose your own adventure
%key: id
%type: id int
%type: name line
%type: text line
%auto: id
id: 1
name: beginning
text: You wake up in the comfort of your own bed, in your own room. You open your eyes to see the golden sunlight come streaming in through your window. Golden like ears of corn. You suddenly remember what day it is. It is the day of the Harvest Festival! You throw back your favorite corn print bed covers and leap out of bed. You already know what you're going to wear. If you wear a corn dress, goto {{corndress}}. If you wear corn bib overalls, goto to {{cornoveralls}}
id: 2
name: deathbycorn
text: You eat way too much corn. Goto {{death}}.
id: 3
name: death
text: You die a horrible death. THE END.
id: 4
name: games
text: You decide to join the other little corn whelps in a game. A bunch of your friends are here, including Three Fingered Gerald, Eccentric Kevn, Dale, and Standard Ed. If you choose to play tag, goto 5. If you play hide-and-seek, goto {{hideandseek}}. If you play Lava Monster, goto {{lavamonster}}.
id: 5
name: tag
text: You have a fantastic time playing tag. Three Fingered Gerald plays a little too rough, tagging the other kids too hard and sometimes knocking them over. But you're so fast. Three Fingered Gerald can never catch you. You all have a great time, and then you decide to scurry along. Goto {{altar}}
id: 7
name: lavamonster
text: No. You should never play Lava Monster. Go back to {{games}}.
id: 8
name: hideandseek
text: You play hide and seek. You are so good at hiding that the other kids never find you. You eventually get tired and fall asleep, but not for too long: your snoring wakes you up. You decide to leave and seek out other Harvest Festival festivities. Goto {{altar}}
id: 9
name: corndress
text: You slip on a lovely corn pattern dress. Yes, you look awesome. It twirls when you spin around. And it has pockets! Which reminds you... Goto {{charm}}.
id: 10
name: cornoveralls
text: You pull on your overalls. They have a really nice looking corn pattern on them, and the bib pocket in the front is perfect for holding all kinds of things. Speaking of which... Goto {{charm}}
id: 11
name: charm
text: You grab your lucky corn charm from under your pillow. It is a small pointy rock in the shape of a corn cob that you found one time in the woods. There are even little pock marks all over the rock so that it looks like it has corn kernels! Very lucky indeed. You slip it into your pocket. There, now you're are ready for anything.
+ You run to the kitchen and have a quick breakfast of corn grits and cornbread. But you don't dally or dawdle. It's the Harvest Festival! You run outside. There are a bunch of kids playing games out in the corn field. They call your name, and you're tempted to join them. But you also want to go see the goings on down at the corn altar! The altar can wait, time to play. Goto {{games}}. Games are for stupid babies! Time to visit the altar! Goto {{altar}}.
id: 12
name: altarcorn
text: omg it's just lying there!
id: 13
name: altar
text: You head over to the Corn Altar. Every year during the harvest, you set aside a portion of the harvest for the Corn Mother. And then on the morning of the Harvest Festival, everybody wakes up and the offering has been taken, and there are lots of presents and feasting and dancing! It's the best!
+ You run through the streets, and the closer you get to the commons, the more you get the feeling something is wrong. The decorations are all out. (The villagers spent all week putting them up!) But nobody is singing or hollering or laughing. Or even talking, really.
+ You run through the commons, and up the hill to the Corn Altar, and then gasp out loud and skid to a stop before it.
+ The offering, the pile of ears of corn, is still lying on the altar where it was placed last night! People are milling about in groups of 3 or 5, whispering and casting quick, fearful glances at the spurned corn.
+ Go checkout the corn at the altar: Goto {{altarcorn}}
+ Listen in on some of the adults: Goto {{eavesdrop}}
id: 14
name: eavesdrop
text: psst psst pssst psst

45
justfile 100644
View File

@ -0,0 +1,45 @@
# show all commands
default:
just --list --unsorted
# super plain boring output
_map:
recsel game.rec | recfmt '"{{{{name}}": "{{{{id}}", '
# build dot file
_dot:
#!/usr/bin/env zsh
echo "digraph {" > dot
recsel game.rec \
| 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 '/{{{{/!d' -e 's/\.$//' \
| sed -e 's/> \(.*\)$/> { \1 };/' \
>> dot
echo "}" >> dot
# build a graph of all the nodes
graph: _data _dot
mustache data dot | dot -Tpng > graph.png
# build data object
_data:
echo "{" $(just _map) "}" \
| sed -e 's/, }/ }/' \
> data
# plain output
build: _data
mustache data game.rec \
| recfmt '{{{{id}}: {{{{text}}|' \
| sed -e 's/|/\n\n/g' \
# read the story
browse:
just build | fmt | less
# remove generated files
clean:
rm -f dot data graph.png