"Go back" functionality
This commit is contained in:
parent
1059b0997c
commit
cea54d7dee
|
@ -51,5 +51,8 @@ room "inventory", salet,
|
|||
for thing in salet.character.inventory
|
||||
text += "* #{salet.character.listinv(thing.name)}\n"
|
||||
return text+"\n\n"+"""
|
||||
<div class="center"><a href="plaza"><button class="btn btn-lg btn-outline-primary">Go to plaza</button></a></div>
|
||||
<div class="center"><a href="./exit"><button class="btn btn-lg btn-outline-primary">Go back</button></a></div>
|
||||
"""
|
||||
actions:
|
||||
exit: (salet) ->
|
||||
return salet.goBack()
|
||||
|
|
|
@ -196,6 +196,8 @@ class Salet
|
|||
seed: null
|
||||
# Keeps track of the links clicked, and when.
|
||||
sequence: [],
|
||||
# Keeps track of the rooms visited, for when we want to "go back"
|
||||
path: [],
|
||||
# The time when the progress was saved.
|
||||
saveTime: null
|
||||
}
|
||||
|
@ -295,12 +297,14 @@ class Salet
|
|||
now = (new Date()).getTime() * 0.001
|
||||
@time = now - @startTime
|
||||
@progress.sequence.push({link:code, when:@time})
|
||||
if @getRoom(code)? # if it's a room
|
||||
@progress.path.push(code)
|
||||
@processLink(code)
|
||||
|
||||
# Presumably, the last action is the one that fired goBack, so we go to the
|
||||
# one before it.
|
||||
# Go back N rooms. It's not an UNDO.
|
||||
# Also, steps = 1 is the current room
|
||||
@goBack = (steps = 2) =>
|
||||
@processClick(@progress.sequence[@progress.sequence.length - steps].link)
|
||||
@processClick(@progress.path[@progress.path.length - steps])
|
||||
|
||||
# Transition between rooms.
|
||||
@doTransitionTo = (newRoomId) =>
|
||||
|
@ -426,7 +430,10 @@ class Salet
|
|||
# Do the first state.
|
||||
@doTransitionTo(@start)
|
||||
|
||||
@getRoom = (name) => @rooms[name]
|
||||
@getRoom = (name) =>
|
||||
if @rooms[name]?
|
||||
return @rooms[name]
|
||||
return undefined
|
||||
|
||||
# Just an alias for getCurrentRoom
|
||||
@here = () => @getCurrentRoom()
|
||||
|
|
Loading…
Reference in a new issue