1
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet.git synced 2024-07-07 01:04:25 +03:00
salet/lib/obj.coffee

40 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2016-01-15 03:06:03 +02:00
markdown = require('./markdown.coffee')
undum = require('./undum.js')
2016-01-15 03:06:03 +02:00
objlink = (content, ref) ->
return "<a href='./_act_#{ref}'>#{content}</a>"
2016-01-15 17:29:15 +02:00
Array::remove = (e) -> @[t..t] = [] if (t = @indexOf(e)) > -1
2016-01-15 03:06:03 +02:00
class RaconteurObj
constructor: (spec) ->
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>"
window.name = @name
text = text.replace /([\s^])\{\{(\w+)\}\}([\s$])/g, (str, p1, p2, p3) ->
name = window.name
window.name = undefined
return p1+objlink(p2, name)+p3
return text
take: () -> "You take the #{@name}." # taking to inventory
act: () -> "You don't find anything extraordinary about the #{@name}." # object action
dsc: () -> "You see a {{#{@name}}} here." # object description
2016-01-16 08:26:25 +02:00
inv: () -> "It's a {{#{@name}.}}" # inventory description
2016-01-15 17:29:15 +02:00
location: ""
put: (location) ->
2016-01-15 03:06:03 +02:00
@level = 0 # this is scenery
2016-01-15 17:29:15 +02:00
undum.game.situations[location].objects[@name] = this
@location = location
delete: () ->
undum.game.situations[@location].objects.remove(this)
2016-01-15 03:06:03 +02:00
obj = (name, spec) ->
spec ?= {}
spec.name = name
return new RaconteurObj(spec)
module.exports = obj