1
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet.git synced 2024-07-04 07:45:03 +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) => @entering = (system, f) =>
if @clear and f? if @clear and f?
system.view.clearContent() system.view.clearContent()
else
system.view.removeTransient()
if f != @name and f? if f != @name and f?
@visited++ @visited++
@ -77,32 +79,29 @@ class SaletRoom
if @enter if @enter
@enter system, f @enter system, f
room_content = ""
if not @extendSection if not @extendSection
classes = if @classes then ' ' + @classes.join(' ') else '' classes = if @classes then ' ' + @classes.join(' ') else ''
room = document.getElementById('current-room') room = document.getElementById('current-room')
if room? if room?
room.removeAttribute('id') room.removeAttribute('id')
# Javascript DOM manipulation functions like jQuery's append() or document.createElement system.view.append "<section id='current-room' data-room='#{@name}' class='room-#{@name}#{classes}'></section>"
# 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}'>"
if f != @name and @before? 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? 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 if @beforeChoices?
room_content += "</section>" @beforeChoices.fcall(this, system, f)
system.view.write(room_content)
if @choices if @choices
system.view.writeChoices(system, system.getSituationIdChoices(@choices, @maxChoices)) system.view.writeChoices(system, system.getSituationIdChoices(@choices, @maxChoices))
if @afterChoices?
@afterChoices.fcall(this, system, f)
if system.autosave if system.autosave
system.saveGame() system.saveGame()
@ -164,7 +163,6 @@ class SaletRoom
# If it's takeable, the player can take this object. # If it's takeable, the player can take this object.
# If not, we check the "act" function. # If not, we check the "act" function.
if thing.takeable if thing.takeable
console.log system
system.character.take(thing) system.character.take(thing)
@drop name @drop name
system.view.clearContent() system.view.clearContent()

View file

@ -109,6 +109,14 @@ class SaletView
block = document.getElementById("content") block = document.getElementById("content")
block.innerHTML = 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. # Replaces the text in the given block with the given text.
# !! Does not call markdown on the provided text. !! # !! Does not call markdown on the provided text. !!
replace: (content, elementSelector) => replace: (content, elementSelector) =>