diff --git a/game/begin.coffee b/game/begin.coffee
index ec90f2b..253ef77 100644
--- a/game/begin.coffee
+++ b/game/begin.coffee
@@ -45,6 +45,11 @@ writemd = (system, text) ->
get_room = (name) ->
return undum.game.situations[name]
+# Function to return the current room.
+# Works because our `enter()` function sets the `data-situation` attribute.
+here = () ->
+ return undum.game.situations[document.getElementById("current-situation").getAttribute("data-situation")]
+
# The first room of the game.
# For accessibility reasons the text is provided in HTML, not here.
room "start",
diff --git a/game/init.coffee b/game/init.coffee
index 1bd3030..658e2ad 100644
--- a/game/init.coffee
+++ b/game/init.coffee
@@ -2,6 +2,5 @@
# All code in this file comes last, so the game is almost ready by this point.
undum.game.init = (character, system) ->
- bugg.put("lair")
window.onload = undum.begin
diff --git a/game/story.coffee b/game/story.coffee
index fcbdf0c..04a8678 100644
--- a/game/story.coffee
+++ b/game/story.coffee
@@ -67,8 +67,8 @@ room "lair",
bugg = obj "bugg-shoggog",
dsc: "You see a particularly beautiful slimy {{bugg.}}"
- act: () ->
- this.delete()
+ act: () =>
+ here().drop(@name)
return "You eat the bugg mass. Delicious and raw."
room "shop-inside",
@@ -80,4 +80,4 @@ room "shop-inside",
lamp = obj "lamp",
dsc: "You see a {{lamp.}}"
- take: "You carefully take the lamp."
+ takeable: true
diff --git a/lib/obj.coffee b/lib/obj.coffee
index f3247a6..02bc143 100644
--- a/lib/obj.coffee
+++ b/lib/obj.coffee
@@ -1,16 +1,16 @@
markdown = require('./markdown.coffee')
undum = require('./undum.js')
objlink = (content, ref) ->
- return "#{content}"
+ return "#{content}"
Array::remove = (e) -> @[t..t] = [] if (t = @indexOf(e)) > -1
parsedsc = (text, name) ->
window.objname = name
- text = text.replace /([\s^])\{\{(.+)\}\}([\s$])/g, (str, p1, p2, p3) ->
+ text = text.replace /\{\{(.+)\}\}/g, (str, p1) ->
name = window.objname
window.objname = undefined
- return p1+objlink(p2, name)+p3
+ return objlink(p1, name)
return text
# An object class.
@@ -18,7 +18,7 @@ parsedsc = (text, name) ->
class SaletObj
constructor: (spec) ->
for key, value of spec
- this[key] ?= value
+ this[key] = value
level: 0
look: (character, system, f) =>
if @dsc
@@ -26,6 +26,7 @@ class SaletObj
text = "" + text + ""
# 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
diff --git a/lib/room.coffee b/lib/room.coffee
index c601499..233941c 100644
--- a/lib/room.coffee
+++ b/lib/room.coffee
@@ -26,11 +26,6 @@ addClass = (element, className) ->
else
element.className += ' ' + className
-# Function to return the current room.
-# Works because our `enter()` function sets the `data-situation` attribute.
-here = () ->
- return undum.game.situations[document.getElementById("current-situation").getAttribute("data-situation")]
-
cls = (system) ->
system.clearContent()
system.clearContent("#intro")
@@ -154,7 +149,6 @@ class SaletRoom extends RaconteurSituation
if @content
retval += markdown(@content.fcall(this, character, system, f))
- console.log @objects
for name, thing of @objects
retval += thing.look()
@@ -164,11 +158,15 @@ class SaletRoom extends RaconteurSituation
Puts an object in this room.
###
take: (thing) =>
+ console.log this
@objects[thing.name] = thing
# BUG: for some really weird reason if the call is made in init function or
# during the initialization, this ALSO puts the thing in the start room.
undum.game.situations["start"].objects = {}
+ drop: (name) =>
+ delete @objects[name]
+
###
Object action. A function or a string which comes when you click on the object link.
You could interpret this as an EXAMINE verb or USE one, it's your call.
@@ -177,12 +175,11 @@ class SaletRoom extends RaconteurSituation
if (link = action.match(/^_act_(.+)$/)) #object action
for name, thing of @objects
if name == link[1]
- # We check the "take" function. If it exists, the player can take this object.
+ # If it's takeable, the player can take this object.
# If not, we check the "act" function.
- if thing.take
+ if thing.takeable
character.sandbox.inventory.push thing
- delete @objects[name]
- console.log @objects
+ @drop name
cls(system)
@entering.fcall(this, character, system, @name)
return print(thing.take.fcall(thing, character, system))