0
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet-module.git synced 2024-07-05 08:14:23 +03:00
salet-module/lib/cycle.coffee
Alexander Yakovlev 0ed470dae6 Cycling rewrite, Raconteur's purge
- Rewrote cycling shortcuts into the library. It's more object-oriented
  now (and slightly less obvious, but we can get around that).
- Removed Raconteur situations entirely. Their functionality is 100%
  integrated now.
2016-01-19 10:03:01 +07:00

20 lines
718 B
CoffeeScript

# 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()
character.sandbox.cycle_index ?= [] # initialize with empty array
character.sandbox.cycle_index[name] ?= 0 # initialize with 0
response = responses[character.sandbox.cycle_index[name]]
character.sandbox.cycle_index[name]++
if character.sandbox.cycle_index[name] == responses.length
character.sandbox.cycle_index[name] = 0
return cyclelink(response)
module.exports = cycle