diff --git a/lib/localize.coffee b/lib/localize.coffee index 0621b99..16dc2a0 100644 --- a/lib/localize.coffee +++ b/lib/localize.coffee @@ -49,13 +49,14 @@ String.prototype.l = (args) -> # Find the localized form. localized = localize(lang, this) - - # Merge in any replacement content. - if args - for name in args - localized = localized.replace( - new RegExp("\\{"+name+"\\}"), args[name] - ) + if typeof(localized) == "function" + localized = localized(args) + else # Merge in any replacement content. + if args + for name in args + localized = localized.replace( + new RegExp("\\{"+name+"\\}"), args[name] + ) return localized module.exports = languages; diff --git a/lib/oneOf.coffee b/lib/oneOf.coffee index 051e129..76563f6 100644 --- a/lib/oneOf.coffee +++ b/lib/oneOf.coffee @@ -166,5 +166,7 @@ oneOf = (ary...) -> Array.prototype.oneOf = () -> oneOf.apply(null, this) +String.prototype.oneOf = () -> + return this module.exports = oneOf; diff --git a/lib/salet.coffee b/lib/salet.coffee index c57a889..1742816 100644 --- a/lib/salet.coffee +++ b/lib/salet.coffee @@ -2,7 +2,7 @@ markdown = require('./markdown.coffee') SaletView = require('./view.coffee') Random = require('./random.js') character = require('./character.coffee') -languages = require('./localize.coffee') +require('./localize.coffee') ### fcall() (by analogy with fmap) is added to the prototypes of both String and @@ -27,12 +27,12 @@ There is only one instance of this class. class Salet constructor: (spec) -> @character = character() - + # REDEFINE THIS IN YOUR GAME @game_id = null @game_version = "1.0" @autosave = true - + @rnd = null @time = 0 @@ -230,7 +230,7 @@ class Salet return @view.mark_all_links_old - + # We're processing, so make the stack available. @linkStack = [] @@ -296,15 +296,16 @@ class Salet oldRoomId = @current oldRoom = @getCurrentRoom() newRoom = @rooms[newRoomId] + console.log @rooms, newRoomId assert(newRoom, "unknown_situation".l({id:newRoomId})) - + # We might not have an old situation if this is the start of the game. if (oldRoom and @exit) @exit(oldRoomId, newRoomId) @current = newRoomId - + # Remove links and transient sections. @view.removeTransient(@interactive) @@ -361,7 +362,9 @@ class Salet # Loads the game from the given data @loadGame = (saveFile) => @progress = saveFile.progress - @character = saveFile.character + @character = new Character + for index, value of saveFile.character + @character[index] = value @rnd = new Random(@progress.seed) @@ -370,9 +373,8 @@ class Salet if saveFile.progress? and saveFile.progress.sequence.length > 1 @view.clearContent() - # Now play through the actions so far: - if (@init) - @init() + # Start the game + @init() # Run through all the player's history. interactive = false @@ -413,8 +415,7 @@ class Salet # Start the game @startTime = new Date().getTime() * 0.001 - if (@init) - @init(character) + @init() # Do the first state. @doTransitionTo(@start) @@ -432,7 +433,8 @@ class Salet for index, value of spec this[index] = value - return this + + return this salet = (spec) -> spec ?= {}