diff --git a/package.json b/package.json index e4fd3e3..72e249a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salet", - "version": "1.6.11", + "version": "1.6.12", "description": "A general client-side framework for cybertext interactive fiction games.", "keywords": ["ifiction", "interactive fiction", "games", "coffee-script", "text", "menu"], "homepage": "http://salet.oreolek.ru", diff --git a/src/salet.coffee b/src/salet.coffee index d8f600c..60c615a 100644 --- a/src/salet.coffee +++ b/src/salet.coffee @@ -6,7 +6,6 @@ There is only one instance of this class. ### class Salet constructor: (spec) -> - @version = "1.6.11" @character = new Character # REDEFINE THIS IN YOUR GAME @@ -269,10 +268,12 @@ class Salet if consumed != true room.act(action) - + if @afterAction @afterAction(room, action) + @checkTimer() + # This gets called when the user clicks a link to carry out an action. @processClick = (code) -> now = (new Date()).getTime() * 0.001 @@ -452,6 +453,39 @@ class Salet return Boolean place.visited return 0 + @timers = {} + + # Adds a one-time timer that will fire after clicks + # with . + # @param name string timer ID + # @param repeat boolean should it repeat every steps or not + # @param action string or function code to call + # @param step integer number of steps + @addTimer = (name, action, repeatable = false, step = 1) -> + @timers[name] = { + step: step + repeatable: repeatable + action: action + set: @progress.sequence.length + } + return @timers + + @dropTimer = (name) -> + delete @timers[name] + + @resetTimer = (name) -> + @timers[name].set = @progress.sequence.length + + @checkTimer = () -> + if Object.keys(@timers).length == 0 + return 1 + for tname, timer of @timers + if ((@progress.sequence.length - timer.set) == timer.step) + @view.append timer.action.fcall(this) + if !timer.repeatable + @dropTimer(tname) + return 1 + for index, value of spec this[index] = value