Does anyone know how Raconteur does actions links? I would love to see a working example of how this works, as I learn better looking at example code. Right now I’m muddling through what the API documentation has to say about it and not getting anywhere:
Action links in Raconteur are the same as in Undum:
# Markdown:
[Open the door.](./open-door)
# HTML (Also valid input for Raconteur):
<a href="./open-door">Open the door.</a>
# Element helpers (a = require('raconteur/lib/elements.js').a)
a('Open the door.').ref('./open-door') # Creates an object that stringifies as an <a> tag
Which one of those you use is a matter of preference. Element helpers are actively bad for performance (by a negligible margin) and have no actual functionality gain, but I wrote that module purely for legibility so I use that.
When an action link is clicked (Undum treats links with hrefs starting with ‘./’ as action links), makes a call to the current situation’s act method. This method is supplied by the Raconteur situation prototype, and what it does is look in your situation’s actions and writers properties.
If a link has a prefix (’./writer’, ‘./inserter’, ‘replacer’), Raconteur will look for a writer with the corresponding name; for instances, ‘./_writer_get-pig’ will look for [current situation].writers[‘get-pig’]. If there isn’t one, it’ll throw an error.
If the link doesn’t have a prefix, it’ll look for it in the current situation’s actions property.
Here’s a toy example:
situation 'stat-increase',
content: """
Here you can #{a('increase your strength').once().action('increase-strength')}.
"""
actions:
'increase-strength': (character, system) ->
system.setQuality('strength', character.qualities.strength + 1)
Thanks for your help! I think I get this now. If I were to code the action for your example, something like this appears to work just fine:
situation 'start',
content: """
Here you can #{a('increase your strength').once().action('increase-strength')}.
"""
actions:
"increase-strength": (character, system, action) ->
system.setQuality("strength", character.qualities.strength+1)