1
0
Fork 0
mirror of https://gitlab.com/Oreolek/black_phone.git synced 2024-04-29 23:59:42 +03:00

Level-marked descriptions WIP

This commit is contained in:
Alexander Yakovlev 2016-03-14 13:35:17 +07:00
parent d67c327ff5
commit 965608c46e
5 changed files with 24 additions and 26 deletions

View file

@ -97,3 +97,20 @@ room "start", salet,
Ronald was working inside, quietly walking around the apartment.
He began the inspection from #{way_to('the living room.', 'living-room')}
"""
# 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) =>
maxLevel = 6
if level < maxLevel
i = level + 1
hideArray = []
while i <= maxLevel
hideArray.push("#content .lvl"+i)
i++
directive = hideArray.join(", ")
$(directive).hide()
wrapLevel: (text, level) =>
return "<div class='lvl#{level}'>"+markdown(text)+'</div>'

View file

@ -21,12 +21,10 @@ 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
@look = (system, f) =>
if @dsc and @dsc != ""
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

View file

@ -168,10 +168,11 @@ 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?
if thing.beforeAct?
thing.beforeAct.fcall(thing, system)
return system.view.write thing.act.call(thing, system).toString()
# the loop is done but no return came - match not found
console.error("Could not find #{link[2]} in current room.")

View file

@ -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 @wrapLevel(callback(), level)
wrapLevel: (text, level) =>
return "<div class='lvl#{level}'>"+markdown(text)+'</div>'
# At last, we scroll the view so that .new objects are in view.
endOutputTransaction: () =>
if !@interactive

@ -1 +1 @@
Subproject commit ada8f213433b357af0528d06ec03148ae9d106f3
Subproject commit 980d8ea2d828fe1796a423f80d84d526b0252a89