1
0
Fork 0
mirror of https://gitlab.com/Oreolek/black_phone.git synced 2024-05-05 18:48:37 +03:00
black_phone/lib/obj.coffee

51 lines
1.7 KiB
CoffeeScript

markdown = require('./markdown.coffee')
undum = require('./undum.js')
objlink = (content, ref) ->
return "<a href='./_act_#{ref}' class='once'>#{content}</a>"
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 = "<span class='look lvl#{@level}'>" + text + "</span>"
# 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