mirror of
https://gitlab.com/Oreolek/salet-module.git
synced 2024-06-16 15:10:52 +03:00
1.6.12 // Timer API
This commit is contained in:
parent
0b692db299
commit
6b5bbe3b72
|
@ -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",
|
||||
|
|
|
@ -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 <name> that will fire after <steps> clicks
|
||||
# with <action>.
|
||||
# @param name string timer ID
|
||||
# @param repeat boolean should it repeat every <step> 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
|
||||
|
||||
|
|
Loading…
Reference in a new issue