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:
parent
15e001af2a
commit
9628801fe1
|
@ -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
|
|
@ -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 ?= {}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue