mirror of
https://gitlab.com/Oreolek/salet.git
synced 2024-07-07 01:04:25 +03:00
57 lines
1.8 KiB
CoffeeScript
57 lines
1.8 KiB
CoffeeScript
markdown = require('./markdown.coffee')
|
|
#require('./salet.coffee')
|
|
unitlink = (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.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
|