From 9628801fe11d8bca71b67e0e2ca8c27f0729ab87 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Mon, 1 Feb 2016 20:39:16 +0700 Subject: [PATCH] Cycling fix --- lib/cycle.coffee | 19 ------------------- lib/room.coffee | 13 +++++++++++-- lib/salet.coffee | 2 ++ lib/view.coffee | 5 ++++- 4 files changed, 17 insertions(+), 22 deletions(-) delete mode 100644 lib/cycle.coffee diff --git a/lib/cycle.coffee b/lib/cycle.coffee deleted file mode 100644 index 72da16e..0000000 --- a/lib/cycle.coffee +++ /dev/null @@ -1,19 +0,0 @@ -# Cycling interface. -# Rooms: cycle through this.cycle_gallery -# Objects: cycle through this.cycle_gallery - -cyclelink = (content) -> - return "#{content}" - -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 diff --git a/lib/room.coffee b/lib/room.coffee index cb10aa8..587c00e 100644 --- a/lib/room.coffee +++ b/lib/room.coffee @@ -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 ?= {} diff --git a/lib/salet.coffee b/lib/salet.coffee index f581f00..2c96a7a 100644 --- a/lib/salet.coffee +++ b/lib/salet.coffee @@ -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 diff --git a/lib/view.coffee b/lib/view.coffee index 4aa440e..2fdbc7b 100644 --- a/lib/view.coffee +++ b/lib/view.coffee @@ -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 "Room illustration" + cycleLink: (content) -> + return "#{content}" + module.exports = SaletView