1
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet.git synced 2024-07-02 06:45:06 +03:00

Localization supports functions, init fixes

This commit is contained in:
Alexander Yakovlev 2016-02-13 10:20:56 +07:00
parent 84d6538e61
commit ba9b59b53a
3 changed files with 25 additions and 20 deletions

View file

@ -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;

View file

@ -166,5 +166,7 @@ oneOf = (ary...) ->
Array.prototype.oneOf = () ->
oneOf.apply(null, this)
String.prototype.oneOf = () ->
return this
module.exports = oneOf;

View file

@ -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 ?= {}