Issue #15 - single phrases

This commit is contained in:
Alexander Yakovlev 2016-02-24 19:45:02 +07:00
parent 893f61032c
commit f9fd118b6f
6 changed files with 47 additions and 11 deletions

View file

@ -1,6 +1,7 @@
room = require("../../lib/room.coffee")
obj = require('../../lib/obj.coffee')
dialogue = require('../../lib/dialogue.coffee')
dialogue = require('../../lib/util/dialogue.coffee')
phrase = require('../../lib/util/phrase.coffee')
oneOf = require('../../lib/oneOf.coffee')
Salet = require('../../lib/salet.coffee')

View file

@ -73,9 +73,12 @@ room "lair", salet,
return "You eat the bugg mass. Delicious and raw. Perhaps it's a good lair to live in."
]
dialogue "Yes", salet, "merchant", "merchant", """
phrase "Yes", salet, "merchant", """
Yes.
"""
dialogue "No", salet, "merchant", "merchant", """
No.
"""
room "shop-inside", salet,
ways: ["shop"]
@ -104,6 +107,7 @@ lamp = obj "lamp",
takeable: true
lamp.put(salet, "shop-inside")
# The dialogue entry point has to be a room, in order to have an ID to go to.
room "merchdialogue", salet,
choices: "#merchant",
dsc: """

2
lib/util/README.md Normal file
View file

@ -0,0 +1,2 @@
These functions are not used by Salet core.
But you can `require` them in your game and use thusly.

View file

@ -1,12 +1,5 @@
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()
room = require("../room.coffee")
randomid = require("./randomid.coffee")
###
A dialogue shortcut.
Usage:

30
lib/util/phrase.coffee Normal file
View file

@ -0,0 +1,30 @@
room = require("../room.coffee")
randomid = require("./randomid.coffee")
###
A phrase shortcut.
Usage:
phrase "Point out a thing in her purse (mildly)", "start", """
Point out a thing in her purse (mildly)
""", "character.sandbox.mild = true"
@param title phrase Phrase (question)
@param salet Salet core
@param string tag tag marking viewing condition
@param string text Response
@param string effect an optional parameter, eval'd code
###
phrase = (title, salet, tag, text, effect) ->
retval = room(randomid(), salet, {
optionText: title
dsc: text
clear: false # backlog is useful in dialogues
choices: "#"+tag
tags: [tag]
})
if effect?
retval.before = (character, system) ->
eval(effect)
return retval
module.exports = phrase

6
lib/util/randomid.coffee Normal file
View file

@ -0,0 +1,6 @@
module.exports = () ->
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()