0
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet-module.git synced 2024-06-26 03:50:49 +03:00

Cycling fix

This commit is contained in:
Alexander Yakovlev 2016-02-01 20:39:16 +07:00
parent 15e001af2a
commit 9628801fe1
4 changed files with 17 additions and 22 deletions

View file

@ -1,19 +0,0 @@
# 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.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
return cyclelink(response)
module.exports = cycle

View file

@ -3,7 +3,6 @@
require('./salet.coffee')
obj = require('./obj.coffee')
markdown = require('./markdown.coffee')
cycle = require('./cycle.coffee')
assert = (msg, assertion) -> console.assert assertion, msg
@ -224,7 +223,17 @@ class SaletRoom
writers:
cyclewriter: (salet) ->
cycle(this.cycle, this.name, salet.character)
responses = @cycle
if typeof responses == "function"
responses = responses()
cycleIndex = window.localStorage.getItem("cycleIndex")
cycleIndex ?= 0
response = responses[cycleIndex]
cycleIndex++
if cycleIndex == responses.length
cycleIndex = 0
window.localStorage.setItem("cycleIndex", cycleIndex)
return salet.view.cycleLink(response)
room = (name, salet, spec) ->
spec ?= {}

View file

@ -43,6 +43,8 @@ class Salet
# Salet's default is a general URL-safe expression.
linkRe: /^([0-9A-Za-z_-]+|\.)(\/([0-9A-Za-z_-]+))?$/
character: new Character
###
This function is called at the start of the game. It is
normally overridden to provide initial character creation

View file

@ -260,7 +260,7 @@ class SaletView
if waylink
addClass(waylink, "destination")
pictureTag = (picture) ->
pictureTag: (picture) ->
extension = picture.substr((~-picture.lastIndexOf(".") >>> 0) + 2)
if (extension == "webm")
return """
@ -271,4 +271,7 @@ class SaletView
"""
return "<img class='img-responsive' src='#{picture}' alt='Room illustration'>"
cycleLink: (content) ->
return "<a href='./_replacer_cyclewriter' class='cycle' id='cyclewriter'>#{content}</a>"
module.exports = SaletView