markdown = require('./markdown.coffee') undum = require('./undum.js') objlink = (content, ref) -> return "#{content}" Array::remove = (e) -> @[t..t] = [] if (t = @indexOf(e)) > -1 parsedsc = (text, name) -> window.objname = name text = text.replace /\{\{(.+)\}\}/g, (str, p1) -> name = window.objname window.objname = undefined return objlink(p1, name) return text # An object class. # An object cannot be in several locations at once, you must clone the variable. class SaletObj constructor: (spec) -> unless spec.name? console.error("Trying to create an object with no name") return null for key, value of spec this[key] = value level: 0 look: (character, system, f) => if @dsc text = markdown(@dsc.fcall(this, character, system, f)) text = "" + text + "" # replace braces {{}} with link to _act_ return parsedsc(text, @name) takeable: false take: (character, system) => "You take the #{@name}." # taking to inventory act: (character, system) => "You don't find anything extraordinary about the #{@name}." # object action dsc: (character, system) => "You see a {{#{@name}}} here." # object description inv: (character, system) => "It's a {{#{@name}.}}" # inventory description location: "" put: (location) => @level = 0 # this is scenery if undum.game.situations[location]? undum.game.situations[location].take(this) @location = location delete: () => undum.game.situations[@location].objects.remove(this) obj = (name, spec) -> spec ?= {} spec.name = name return new SaletObj(spec) module.exports = obj