2016-01-15 03:06:03 +02:00
|
|
|
markdown = require('./markdown.coffee')
|
2016-01-15 03:31:04 +02:00
|
|
|
undum = require('./undum.js')
|
2016-01-15 03:06:03 +02:00
|
|
|
objlink = (content, ref) ->
|
2016-01-16 18:43:20 +02:00
|
|
|
return "<a href='./_act_#{ref}' class='once'>#{content}</a>"
|
2016-01-15 03:06:03 +02:00
|
|
|
|
2016-01-15 17:29:15 +02:00
|
|
|
Array::remove = (e) -> @[t..t] = [] if (t = @indexOf(e)) > -1
|
|
|
|
|
2016-01-16 18:24:23 +02:00
|
|
|
parsedsc = (text, name) ->
|
|
|
|
window.objname = name
|
2016-01-16 18:43:20 +02:00
|
|
|
text = text.replace /\{\{(.+)\}\}/g, (str, p1) ->
|
2016-01-16 18:24:23 +02:00
|
|
|
name = window.objname
|
|
|
|
window.objname = undefined
|
2016-01-16 18:43:20 +02:00
|
|
|
return objlink(p1, name)
|
2016-01-16 18:24:23 +02:00
|
|
|
return text
|
|
|
|
|
|
|
|
# An object class.
|
|
|
|
# An object cannot be in several locations at once, you must clone the variable.
|
|
|
|
class SaletObj
|
2016-01-15 03:06:03 +02:00
|
|
|
constructor: (spec) ->
|
2016-01-17 07:29:52 +02:00
|
|
|
unless spec.name?
|
|
|
|
console.error("Trying to create an object with no name")
|
|
|
|
return null
|
2016-01-15 03:06:03 +02:00
|
|
|
for key, value of spec
|
2016-01-16 18:43:20 +02:00
|
|
|
this[key] = value
|
2016-01-15 03:06:03 +02:00
|
|
|
level: 0
|
2016-01-16 18:24:23 +02:00
|
|
|
look: (character, system, f) =>
|
2016-01-15 03:06:03 +02:00
|
|
|
if @dsc
|
|
|
|
text = markdown(@dsc.fcall(this, character, system, f))
|
|
|
|
text = "<span class='look lvl#{@level}'>" + text + "</span>"
|
2016-01-16 18:24:23 +02:00
|
|
|
# replace braces {{}} with link to _act_
|
|
|
|
return parsedsc(text, @name)
|
2016-01-16 18:43:20 +02:00
|
|
|
takeable: false
|
2016-01-16 18:24:23 +02:00
|
|
|
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
|
2016-01-15 17:29:15 +02:00
|
|
|
location: ""
|
2016-01-16 18:24:23 +02:00
|
|
|
put: (location) =>
|
2016-01-15 03:06:03 +02:00
|
|
|
@level = 0 # this is scenery
|
2016-01-16 18:24:23 +02:00
|
|
|
if undum.game.situations[location]?
|
|
|
|
undum.game.situations[location].take(this)
|
|
|
|
@location = location
|
|
|
|
delete: () =>
|
2016-01-15 17:29:15 +02:00
|
|
|
undum.game.situations[@location].objects.remove(this)
|
2016-01-15 03:06:03 +02:00
|
|
|
|
|
|
|
obj = (name, spec) ->
|
|
|
|
spec ?= {}
|
|
|
|
spec.name = name
|
2016-01-16 18:24:23 +02:00
|
|
|
return new SaletObj(spec)
|
2016-01-15 03:06:03 +02:00
|
|
|
module.exports = obj
|