2016-01-15 03:06:03 +02:00
|
|
|
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
|
|
|
|
content: text
|
2016-01-15 10:10:12 +02:00
|
|
|
clear: false # backlog is useful in dialogues
|
2016-01-15 03:06:03 +02:00
|
|
|
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
|