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:
parent
dbfc7e086e
commit
cbd0f37ad8
|
@ -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,33 +79,30 @@ 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()
|
||||
|
|
|
@ -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) =>
|
||||
|
|
Loading…
Reference in a new issue