From f9fd118b6fb1521e53a511ec1ca15d08c42cc712 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Wed, 24 Feb 2016 19:45:02 +0700 Subject: [PATCH] Issue #15 - single phrases --- game/begin.coffee | 3 ++- game/story.coffee | 6 +++++- lib/util/README.md | 2 ++ lib/{ => util}/dialogue.coffee | 11 ++--------- lib/util/phrase.coffee | 30 ++++++++++++++++++++++++++++++ lib/util/randomid.coffee | 6 ++++++ 6 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 lib/util/README.md rename lib/{ => util}/dialogue.coffee (69%) create mode 100644 lib/util/phrase.coffee create mode 100644 lib/util/randomid.coffee diff --git a/game/begin.coffee b/game/begin.coffee index ddc2a91..4f95086 100644 --- a/game/begin.coffee +++ b/game/begin.coffee @@ -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') diff --git a/game/story.coffee b/game/story.coffee index 61744fc..44d86ee 100644 --- a/game/story.coffee +++ b/game/story.coffee @@ -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: """ diff --git a/lib/util/README.md b/lib/util/README.md new file mode 100644 index 0000000..18a711e --- /dev/null +++ b/lib/util/README.md @@ -0,0 +1,2 @@ +These functions are not used by Salet core. +But you can `require` them in your game and use thusly. diff --git a/lib/dialogue.coffee b/lib/util/dialogue.coffee similarity index 69% rename from lib/dialogue.coffee rename to lib/util/dialogue.coffee index 240a7c9..04b3fd6 100644 --- a/lib/dialogue.coffee +++ b/lib/util/dialogue.coffee @@ -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: diff --git a/lib/util/phrase.coffee b/lib/util/phrase.coffee new file mode 100644 index 0000000..bca234a --- /dev/null +++ b/lib/util/phrase.coffee @@ -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 diff --git a/lib/util/randomid.coffee b/lib/util/randomid.coffee new file mode 100644 index 0000000..f907d74 --- /dev/null +++ b/lib/util/randomid.coffee @@ -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()