From cd757564b30309ea7c3361b64480149252cf1e76 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Wed, 11 Sep 2019 12:46:57 +0700 Subject: [PATCH] use dialogue and phrase as modules --- game/_dialogue.coffee | 23 ------------- game/_dialogue.js | 28 ++++++++++++++++ game/_phrase.coffee | 26 --------------- game/_phrase.js | 29 +++++++++++++++++ game/story.coffee | 76 ++----------------------------------------- html/index.html | 2 +- package.json | 1 + pnpm-lock.yaml | 8 ++--- 8 files changed, 64 insertions(+), 129 deletions(-) delete mode 100644 game/_dialogue.coffee create mode 100644 game/_dialogue.js delete mode 100644 game/_phrase.coffee create mode 100644 game/_phrase.js diff --git a/game/_dialogue.coffee b/game/_dialogue.coffee deleted file mode 100644 index 7ea5a53..0000000 --- a/game/_dialogue.coffee +++ /dev/null @@ -1,23 +0,0 @@ -### -A dialogue shortcut. -Usage: - - dialogue "Point out a thing in her purse (mildly)", "start", "mild", """ - Point out a thing in her purse (mildly) - """, "character.mild = true" -### -exports = (title, startTag, endTag, text, effect) -> - retval = room("dialogue_"+Object.keys(salet.rooms).length, { - 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 diff --git a/game/_dialogue.js b/game/_dialogue.js new file mode 100644 index 0000000..5a07ec7 --- /dev/null +++ b/game/_dialogue.js @@ -0,0 +1,28 @@ +/** +A dialogue shortcut. +Usage: + + dialogue "Point out a thing in her purse (mildly)", "start", "mild", """ + Point out a thing in her purse (mildly) + """, "character.mild = true" +*/ +export default function dialogue (title, startTag, endTag, text, effect) { + let retval = room("dialogue_"+Object.keys(salet.rooms).length, { + 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 !== undefined) { + retval.before = function (character, system) { + eval(effect); + } + } + return retval; +} diff --git a/game/_phrase.coffee b/game/_phrase.coffee deleted file mode 100644 index e7b20ba..0000000 --- a/game/_phrase.coffee +++ /dev/null @@ -1,26 +0,0 @@ -### -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 -### -exports = (title, tag, text, effect) -> - retval = room("phrase_"+salet.rooms.length, { - 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 diff --git a/game/_phrase.js b/game/_phrase.js new file mode 100644 index 0000000..4bf5e95 --- /dev/null +++ b/game/_phrase.js @@ -0,0 +1,29 @@ +/** +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 +*/ +export default function phrase (title, tag, text, effect) { + let retval = room("phrase_"+salet.rooms.length, { + optionText: title, + dsc: text, + clear: false, // backlog is useful in dialogues + choices: "#"+tag, + tags: [tag], + }); + if (effect !== undefined) { + retval.before = function (character, system) { + eval(effect); + }; + } + return retval; +} diff --git a/game/story.coffee b/game/story.coffee index 50d4dc6..8f4f3b2 100644 --- a/game/story.coffee +++ b/game/story.coffee @@ -1,3 +1,6 @@ +import dialogue from './_dialogue' +import phrase from './_phrase' + salet.game_id = "your-game-id-here" salet.game_version = "1.6" $(document).ready(() -> @@ -40,56 +43,6 @@ textlink = (content, ref) -> actlink = (content, ref) -> return "#{content}" -### -A dialogue shortcut. -Usage: - - dialogue "Point out a thing in her purse (mildly)", "start", "mild", """ - Point out a thing in her purse (mildly) - """, "character.mild = true" -### -dialogue = (title, startTag, endTag, text, effect) -> - retval = room("dialogue_"+Object.keys(salet.rooms).length, { - 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 - -### -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, tag, text, effect) -> - retval = room("phrase_"+salet.rooms.length, { - 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 # The first room of the game. # For accessibility reasons the text is provided in HTML, not here. room "start", @@ -99,29 +52,6 @@ room "start", """, choices: "#start" -# This is a special inventory room. -# The inventory button is a regular link to this room. -# You may alter these as much as you like or scrap it along with the button. -room "inventory", - canSave: false # saving the game here is forbidden. Aautosaving too. - enter: () -> - $("#inventory").hide() - exit: () -> - $("#inventory").show() - dsc: () -> - if salet.character.inventory.length == 0 - text = "You are carrying nothing." - else - text = "You are carrying:\n\n" - for thing in salet.character.inventory - text += "* #{salet.character.listinv(thing.name)}\n" - return text+"\n\n"+""" -
- """ - actions: - exit: () -> - return salet.goBack() - room "world", tags: ["start"], optionText: "Enter the world", diff --git a/html/index.html b/html/index.html index 7987fa6..c266593 100644 --- a/html/index.html +++ b/html/index.html @@ -17,7 +17,6 @@
-
@@ -82,6 +81,7 @@ + diff --git a/package.json b/package.json index a5ea604..859880b 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@babel/plugin-syntax-dynamic-import": "^7.2.0", "@babel/plugin-transform-runtime": "^7.5.5", "@babel/preset-env": "^7.5.5", + "babel-loader": "^8.0.6", "browser-sync": "^2.26.7", "browser-sync-webpack-plugin": "2.2.2", "coffee-loader": "^0.9.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 16eb3ab..0a4df75 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,12 +1,12 @@ dependencies: bootstrap: 4.3.1 - salet: 2.0.1 devDependencies: '@babel/core': 7.5.5 '@babel/plugin-proposal-object-rest-spread': 7.5.5_@babel+core@7.5.5 '@babel/plugin-syntax-dynamic-import': 7.2.0_@babel+core@7.5.5 '@babel/plugin-transform-runtime': 7.5.5_@babel+core@7.5.5 '@babel/preset-env': 7.5.5_@babel+core@7.5.5 + babel-loader: 8.0.6_@babel+core@7.5.5+webpack@4.39.3 browser-sync: 2.26.7 browser-sync-webpack-plugin: 2.2.2_c0b23e126045a5ff546049302d1a0a79 coffee-loader: 0.9.0_coffeescript@2.4.1 @@ -6558,10 +6558,6 @@ packages: dev: true resolution: integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== - /salet/2.0.1: - dev: false - resolution: - integrity: sha512-Xj4W2+AOB/8LeGo9kmWvT2gXmLeC4GnPy2uhorHF8W/YVPMd+GtZ92MJ3ue2ZfuLAX9EixVtYjBBsU3XKI2t2g== /sass-graph/2.2.4: dependencies: glob: 7.1.4 @@ -8167,6 +8163,7 @@ specifiers: '@babel/plugin-syntax-dynamic-import': ^7.2.0 '@babel/plugin-transform-runtime': ^7.5.5 '@babel/preset-env': ^7.5.5 + babel-loader: ^8.0.6 bootstrap: ^4.0.0 browser-sync: ^2.26.7 browser-sync-webpack-plugin: 2.2.2 @@ -8176,7 +8173,6 @@ specifiers: laravel-mix: ^4.1.2 node-sass: ^4.12.0 postcss-loader: ^3.0.0 - salet: ^2.0.1 sass-loader: 7.* style-loader: ^1.0.0 vue-template-compiler: ^2.6.10