mirror of
https://gitlab.com/Oreolek/salet.git
synced 2024-07-07 01:04:25 +03:00
Fix for takeable objects
This commit is contained in:
parent
0ed4f98098
commit
5488736b48
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
markdown = require('./markdown.coffee')
|
||||
undum = require('./undum.js')
|
||||
objlink = (content, ref) ->
|
||||
return "<a href='./_act_#{ref}'>#{content}</a>"
|
||||
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 /([\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 = "<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
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue