markdown = require('./markdown.coffee') #require('./salet.coffee') unitlink = (content, ref) -> return "#{content}" Array::remove = (e) -> @[t..t] = [] if (t = @indexOf(e)) > -1 parsedsc = (text, name) -> window.unitname = name text = text.replace /\{\{(.+)\}\}/g, (str, p1) -> name = window.unitname window.unitname = undefined return unitlink(p1, name) return text # A unit class. # A unit cannot be in several locations at once, you must clone the variable. class SaletUnit constructor: (spec) -> unless spec.name? console.error("Trying to create a unit with no name") return null @order = 0 # you can use this to sort the descriptions @visible = true @look = (system, f) => if @dsc and @dsc != "" and @visible text = markdown(@dsc.fcall(this, system, f).toString()) # replace braces {{}} with link to _act_ return parsedsc(text, @name) @takeable = false @take = (system) => "You take the #{@name}." # taking to inventory @act = (system) => "You don't find anything extraordinary about the #{@name}." # unit action @dsc = (system) => "You see a {{#{@name}}} here." # unit description @inv = (system) => "It's a #{@name}." # inventory description @location = "" @put = (salet, location) => @level = 0 # this is scenery if salet.rooms[location]? @location = location salet.rooms[location].take(this) else console.log("Could not find location #{location} for a unit #{@name}") @delete = (salet, location = false) => if location == false location = @location salet.rooms[location].drop(this) for key, value of spec this[key] = value unit = (name, spec) -> spec ?= {} spec.name = name return new SaletUnit(spec) module.exports = unit