mirror of
https://gitlab.com/Oreolek/salet-module.git
synced 2024-06-26 03:50:49 +03:00
1.6.12 // Timer API
This commit is contained in:
parent
0b692db299
commit
6b5bbe3b72
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "salet",
|
"name": "salet",
|
||||||
"version": "1.6.11",
|
"version": "1.6.12",
|
||||||
"description": "A general client-side framework for cybertext interactive fiction games.",
|
"description": "A general client-side framework for cybertext interactive fiction games.",
|
||||||
"keywords": ["ifiction", "interactive fiction", "games", "coffee-script", "text", "menu"],
|
"keywords": ["ifiction", "interactive fiction", "games", "coffee-script", "text", "menu"],
|
||||||
"homepage": "http://salet.oreolek.ru",
|
"homepage": "http://salet.oreolek.ru",
|
||||||
|
|
|
@ -6,7 +6,6 @@ There is only one instance of this class.
|
||||||
###
|
###
|
||||||
class Salet
|
class Salet
|
||||||
constructor: (spec) ->
|
constructor: (spec) ->
|
||||||
@version = "1.6.11"
|
|
||||||
@character = new Character
|
@character = new Character
|
||||||
|
|
||||||
# REDEFINE THIS IN YOUR GAME
|
# REDEFINE THIS IN YOUR GAME
|
||||||
|
@ -269,10 +268,12 @@ class Salet
|
||||||
|
|
||||||
if consumed != true
|
if consumed != true
|
||||||
room.act(action)
|
room.act(action)
|
||||||
|
|
||||||
if @afterAction
|
if @afterAction
|
||||||
@afterAction(room, action)
|
@afterAction(room, action)
|
||||||
|
|
||||||
|
@checkTimer()
|
||||||
|
|
||||||
# This gets called when the user clicks a link to carry out an action.
|
# This gets called when the user clicks a link to carry out an action.
|
||||||
@processClick = (code) ->
|
@processClick = (code) ->
|
||||||
now = (new Date()).getTime() * 0.001
|
now = (new Date()).getTime() * 0.001
|
||||||
|
@ -452,6 +453,39 @@ class Salet
|
||||||
return Boolean place.visited
|
return Boolean place.visited
|
||||||
return 0
|
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
|
for index, value of spec
|
||||||
this[index] = value
|
this[index] = value
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue