From cbd0f37ad80e26e13d1ad3c83c863db07fa317be Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Sat, 5 Mar 2016 11:11:41 +0700 Subject: [PATCH] Clear content fix, new before- and afterChoices events --- lib/room.coffee | 24 +++++++++++------------- lib/view.coffee | 8 ++++++++ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/room.coffee b/lib/room.coffee index e1be822..6c5aac2 100644 --- a/lib/room.coffee +++ b/lib/room.coffee @@ -68,6 +68,8 @@ class SaletRoom @entering = (system, f) => if @clear and f? system.view.clearContent() + else + system.view.removeTransient() if f != @name and f? @visited++ @@ -77,32 +79,29 @@ class SaletRoom if @enter @enter system, f - room_content = "" if not @extendSection classes = if @classes then ' ' + @classes.join(' ') else '' room = document.getElementById('current-room') if room? room.removeAttribute('id') - # Javascript DOM manipulation functions like jQuery's append() or document.createElement - # don't work like a typical printLn - they create *DOM nodes*. - # You can't leave an unclosed tag just like that. So we have to buffer the output. - room_content = "
" + system.view.append "
" if f != @name and @before? - room_content += markdown(@before.fcall(this, system, f)) + system.view.write markdown(@before.fcall(this, system, f)) - room_content += @look system, f + system.view.write @look system, f if f != @name and @after? - room_content += markdown(@after.fcall(this, system, f)) + system.view.write markdown(@after.fcall(this, system, f)) - if not @extendSection - room_content += "
" - - system.view.write(room_content) + if @beforeChoices? + @beforeChoices.fcall(this, system, f) if @choices system.view.writeChoices(system, system.getSituationIdChoices(@choices, @maxChoices)) + + if @afterChoices? + @afterChoices.fcall(this, system, f) if system.autosave system.saveGame() @@ -164,7 +163,6 @@ class SaletRoom # If it's takeable, the player can take this object. # If not, we check the "act" function. if thing.takeable - console.log system system.character.take(thing) @drop name system.view.clearContent() diff --git a/lib/view.coffee b/lib/view.coffee index 4d4d350..71437b4 100644 --- a/lib/view.coffee +++ b/lib/view.coffee @@ -109,6 +109,14 @@ class SaletView block = document.getElementById("content") block.innerHTML = content + # Append content to a block. Does not replace the old content. + append: (content, elementSelector = "#content") => + if content == "" + return + content = @prepareContent(content) + block = document.querySelector(elementSelector) + block.innerHTML = block.innerHTML + markdown(content) + # Replaces the text in the given block with the given text. # !! Does not call markdown on the provided text. !! replace: (content, elementSelector) =>