mirror of
https://gitlab.com/Oreolek/salet.git
synced 2024-07-04 07:45:03 +03:00
"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
|
for thing in salet.character.inventory
|
||||||
text += "* #{salet.character.listinv(thing.name)}\n"
|
text += "* #{salet.character.listinv(thing.name)}\n"
|
||||||
return text+"\n\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
|
seed: null
|
||||||
# Keeps track of the links clicked, and when.
|
# Keeps track of the links clicked, and when.
|
||||||
sequence: [],
|
sequence: [],
|
||||||
|
# Keeps track of the rooms visited, for when we want to "go back"
|
||||||
|
path: [],
|
||||||
# The time when the progress was saved.
|
# The time when the progress was saved.
|
||||||
saveTime: null
|
saveTime: null
|
||||||
}
|
}
|
||||||
|
@ -295,12 +297,14 @@ class Salet
|
||||||
now = (new Date()).getTime() * 0.001
|
now = (new Date()).getTime() * 0.001
|
||||||
@time = now - @startTime
|
@time = now - @startTime
|
||||||
@progress.sequence.push({link:code, when:@time})
|
@progress.sequence.push({link:code, when:@time})
|
||||||
|
if @getRoom(code)? # if it's a room
|
||||||
|
@progress.path.push(code)
|
||||||
@processLink(code)
|
@processLink(code)
|
||||||
|
|
||||||
# Presumably, the last action is the one that fired goBack, so we go to the
|
# Go back N rooms. It's not an UNDO.
|
||||||
# one before it.
|
# Also, steps = 1 is the current room
|
||||||
@goBack = (steps = 2) =>
|
@goBack = (steps = 2) =>
|
||||||
@processClick(@progress.sequence[@progress.sequence.length - steps].link)
|
@processClick(@progress.path[@progress.path.length - steps])
|
||||||
|
|
||||||
# Transition between rooms.
|
# Transition between rooms.
|
||||||
@doTransitionTo = (newRoomId) =>
|
@doTransitionTo = (newRoomId) =>
|
||||||
|
@ -426,7 +430,10 @@ class Salet
|
||||||
# Do the first state.
|
# Do the first state.
|
||||||
@doTransitionTo(@start)
|
@doTransitionTo(@start)
|
||||||
|
|
||||||
@getRoom = (name) => @rooms[name]
|
@getRoom = (name) =>
|
||||||
|
if @rooms[name]?
|
||||||
|
return @rooms[name]
|
||||||
|
return undefined
|
||||||
|
|
||||||
# Just an alias for getCurrentRoom
|
# Just an alias for getCurrentRoom
|
||||||
@here = () => @getCurrentRoom()
|
@here = () => @getCurrentRoom()
|
||||||
|
|
Loading…
Reference in a new issue