1
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet.git synced 2024-07-04 07:45:03 +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') require('./salet.coffee')
obj = require('./obj.coffee') obj = require('./obj.coffee')
markdown = require('./markdown.coffee') markdown = require('./markdown.coffee')
cycle = require('./cycle.coffee')
assert = (msg, assertion) -> console.assert assertion, msg assert = (msg, assertion) -> console.assert assertion, msg
@ -224,7 +223,17 @@ class SaletRoom
writers: writers:
cyclewriter: (salet) -> 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) -> room = (name, salet, spec) ->
spec ?= {} spec ?= {}

View file

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

View file

@ -260,7 +260,7 @@ class SaletView
if waylink if waylink
addClass(waylink, "destination") addClass(waylink, "destination")
pictureTag = (picture) -> pictureTag: (picture) ->
extension = picture.substr((~-picture.lastIndexOf(".") >>> 0) + 2) extension = picture.substr((~-picture.lastIndexOf(".") >>> 0) + 2)
if (extension == "webm") if (extension == "webm")
return """ return """
@ -271,4 +271,7 @@ class SaletView
""" """
return "<img class='img-responsive' src='#{picture}' alt='Room illustration'>" 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 module.exports = SaletView