0
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet-module.git synced 2024-07-05 08:14:23 +03:00
salet-module/lib/dialogue.coffee
Alexander Yakovlev b51d54e227 Issue #7: renaming content to dsc
There are two reasons to make this change:

1. Consistency because objects also have `dsc`
2. `content` is not a good property name.
`dsc` is much more self-explanatory.
2016-01-18 17:29:14 +07:00

35 lines
945 B
CoffeeScript

room = require("./room.coffee")
randomid = () ->
alphabet = "abcdefghijklmnopqrstuvwxyz0123456789" # see the dreaded linkRe expression in Undum
rndstr = []
for i in [1..10]
rndstr.push alphabet.charAt(Math.floor(Math.random() * alphabet.length))
return rndstr.join('').toString()
###
A dialogue shortcut.
Usage:
dialogue "Point out a thing in her purse (mildly)", "start", "mild", """
Point out a thing in her purse (mildly)
""", "character.sandbox.mild = true"
###
dialogue = (title, startTag, endTag, text, effect) ->
retval = room(randomid(), {
optionText: title
dsc: text
clear: false # backlog is useful in dialogues
choices: "#"+endTag
})
if typeof(startTag) == "string"
retval.tags = [startTag]
else if typeof(startTag) == "object"
retval.tags = startTag
if effect?
retval.before = (character, system) ->
eval(effect)
return retval
module.exports = dialogue