From 2197fbad65f683331d8ef355718a9974fe4c49c0 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Mon, 14 Mar 2016 21:55:28 +0700 Subject: [PATCH] Got rid of levels --- lib/obj.coffee | 5 ++--- lib/room.coffee | 9 ++++----- lib/view.coffee | 20 +------------------- 3 files changed, 7 insertions(+), 27 deletions(-) diff --git a/lib/obj.coffee b/lib/obj.coffee index 99f946b..3aeb73e 100644 --- a/lib/obj.coffee +++ b/lib/obj.coffee @@ -21,12 +21,11 @@ class SaletObj console.error("Trying to create an object with no name") return null - @level = 0 # if > 0 it's hidden @order = 0 # you can use this to sort the descriptions + @visible = true @look = (system, f) => - if @dsc and @dsc != "" + if @dsc and @dsc != "" and @visible text = markdown(@dsc.fcall(this, system, f).toString()) - text = system.view.wrapLevel(text, @level) # replace braces {{}} with link to _act_ return parsedsc(text, @name) @takeable = false diff --git a/lib/room.coffee b/lib/room.coffee index 1fc85d3..9fa05a9 100644 --- a/lib/room.coffee +++ b/lib/room.coffee @@ -124,7 +124,7 @@ class SaletRoom objDescriptions = [] for thing in @objects - if thing.name and typeof(thing.look) == "function" and thing.level == 0 and thing.look(system, f) + if thing.name and typeof(thing.look) == "function" and thing.look(system, f) objDescriptions.push ({ order: thing.order, content: thing.look(system, f) @@ -168,10 +168,9 @@ class SaletRoom system.view.clearContent() @entering.fcall(this, system, @name) return system.view.write(thing.take.fcall(thing, system).toString()) - if thing.act - return system.view.changeLevel(thing.level, () -> - return thing.act.fcall(thing, system).toString() - ) + if thing.act? + return system.view.write thing.act.fcall(thing, system) + # the loop is done but no return came - match not found console.error("Could not find #{link[2]} in current room.") diff --git a/lib/view.coffee b/lib/view.coffee index d29c7a7..bb59b0c 100644 --- a/lib/view.coffee +++ b/lib/view.coffee @@ -98,7 +98,7 @@ class SaletView # Write content to current room write: (content, elementSelector = "#current-room") => - if content == "" + if not content? or content == "" return content = @prepareContent(content) block = document.querySelector(elementSelector) @@ -202,24 +202,6 @@ class SaletView else contentToHide.remove() - # Remove every section marked as a different level. - # For a link level 0, we hide every link of level 1 and above. - # It's for the player to focus. - changeLevel: (level, callback) => - maxLevel = 6 - if level < maxLevel - i = level + 1 - hideArray = [] - while i <= maxLevel - hideArray.push("#content .lvl"+i) - i++ - directive = hideArray.join(", ") - $(directive).hide() - @write system.view.wrapLevel(callback(), level) - - wrapLevel: (text, level) => - return "
"+markdown(text)+'
' - # At last, we scroll the view so that .new objects are in view. endOutputTransaction: () => if !@interactive