2016-01-19 05:03:01 +02:00
|
|
|
# Cycling interface.
|
|
|
|
# Rooms: cycle through this.cycle_gallery
|
|
|
|
# Objects: cycle through this.cycle_gallery
|
|
|
|
|
|
|
|
cyclelink = (content) ->
|
|
|
|
return "<a href='./_replacer_cyclewriter' class='cycle' id='cyclewriter'>#{content}</a>"
|
|
|
|
|
|
|
|
cycle = (responses, name, character) ->
|
|
|
|
if typeof responses == "function"
|
|
|
|
responses = responses()
|
2016-02-01 10:51:48 +02:00
|
|
|
character.cycle_index ?= [] # initialize with empty array
|
|
|
|
character.cycle_index[name] ?= 0 # initialize with 0
|
|
|
|
response = responses[character.cycle_index[name]]
|
|
|
|
character.cycle_index[name]++
|
|
|
|
if character.cycle_index[name] == responses.length
|
|
|
|
character.cycle_index[name] = 0
|
2016-01-19 05:03:01 +02:00
|
|
|
return cyclelink(response)
|
|
|
|
|
|
|
|
module.exports = cycle
|