1
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet.git synced 2024-07-02 06:45:06 +03:00

Clear content fix, new before- and afterChoices events

This commit is contained in:
Alexander Yakovlev 2016-03-05 11:11:41 +07:00
parent dbfc7e086e
commit cbd0f37ad8
2 changed files with 19 additions and 13 deletions

View file

@ -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 = "<section id='current-room' data-room='#{@name}' class='room-#{@name}#{classes}'>"
system.view.append "<section id='current-room' data-room='#{@name}' class='room-#{@name}#{classes}'></section>"
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 += "</section>"
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()

View file

@ -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) =>