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

48 lines
1.6 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) ->
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
parsedsc = (text, name) ->
window.objname = name
2016-01-16 18:43:20 +02:00
text = text.replace /\{\{(.+)\}\}/g, (str, p1) ->
name = window.objname
window.objname = undefined
2016-01-16 18:43:20 +02:00
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
2016-01-15 03:06:03 +02:00
constructor: (spec) ->
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
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>"
# replace braces {{}} with link to _act_
return parsedsc(text, @name)
2016-01-16 18:43:20 +02:00
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
2016-01-15 17:29:15 +02:00
location: ""
put: (location) =>
2016-01-15 03:06:03 +02:00
@level = 0 # this is scenery
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
return new SaletObj(spec)
2016-01-15 03:06:03 +02:00
module.exports = obj