mirror of
https://gitlab.com/Oreolek/salet-module.git
synced 2024-06-26 03:50:49 +03:00
Lots of small fixes, mostly in loading
This commit is contained in:
parent
784ca8609f
commit
5403c65167
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "salet",
|
||||
"version": "1.4.6",
|
||||
"version": "1.4.7",
|
||||
"description": "A general client-side framework for cybertext interactive fiction games.",
|
||||
"keywords": ["ifiction", "interactive fiction", "games", "coffee-script", "text", "menu"],
|
||||
"homepage": "http://salet.oreolek.ru",
|
||||
|
|
|
@ -78,7 +78,8 @@ class SaletRoom
|
|||
if salet.rooms[f].exit?
|
||||
salet.rooms[f].exit @name
|
||||
|
||||
history.pushState(@name, @title)
|
||||
if window.history.pushState?
|
||||
window.history.pushState(@name, @title)
|
||||
|
||||
if @enter
|
||||
@enter f
|
||||
|
|
|
@ -10,7 +10,7 @@ Boolean.prototype.fcall = () ->
|
|||
String.prototype.fcall = () ->
|
||||
return this
|
||||
|
||||
assert = (msg, assertion) -> console.assert assertion, msg
|
||||
assert = (assertion, msg) -> console.assert assertion, msg
|
||||
|
||||
###
|
||||
This is the control structure, it has minimal amount of data and
|
||||
|
@ -124,7 +124,7 @@ class Salet
|
|||
Before this function returns its result, it sorts the
|
||||
situations in increasing order of their displayOrder values.
|
||||
###
|
||||
@getSituationIdChoices = (listOfOrOneIdsOrTags, maxChoices) =>
|
||||
@getSituationIdChoices = (listOfOrOneIdsOrTags, maxChoices) ->
|
||||
datum = null
|
||||
i = 0
|
||||
|
||||
|
@ -149,7 +149,7 @@ class Salet
|
|||
room = @rooms[roomId]
|
||||
assert(room, "unknown_situation".l({id:roomId}))
|
||||
|
||||
if (room.canView.fcall(this, this, currentRoom, room))
|
||||
if (room.canView.fcall(this, currentRoom, room))
|
||||
viewableRoomData.push({
|
||||
priority: room.priority
|
||||
id: roomId
|
||||
|
@ -210,24 +210,24 @@ class Salet
|
|||
# The stack of links, resulting from the last action, still be to resolved.
|
||||
@linkStack = null
|
||||
|
||||
@getCurrentRoom = () =>
|
||||
@getCurrentRoom = () ->
|
||||
if (@current)
|
||||
return @rooms[@current]
|
||||
return null
|
||||
|
||||
# Gets the unique id used to identify saved games.
|
||||
@getSaveId = (slot = "") =>
|
||||
@getSaveId = (slot = "") ->
|
||||
return 'salet_'+@game_id+'_'+@game_version#+'_'+slot
|
||||
|
||||
# This gets called when a link needs to be followed, regardless
|
||||
# of whether it was user action that initiated it.
|
||||
@processLink = (code) =>
|
||||
@processLink = (code) ->
|
||||
# Check if we should do this now, or if processing is already underway.
|
||||
if @linkStack != null
|
||||
@linkStack.push(code)
|
||||
return
|
||||
|
||||
@view.mark_all_links_old
|
||||
@view.mark_all_links_old()
|
||||
|
||||
# We're processing, so make the stack available.
|
||||
@linkStack = []
|
||||
|
@ -247,7 +247,7 @@ class Salet
|
|||
# We're able to save, if we weren't already.
|
||||
@view.enableSaving()
|
||||
|
||||
@goTo = (roomId) =>
|
||||
@goTo = (roomId) ->
|
||||
return @processClick(roomId)
|
||||
|
||||
###
|
||||
|
@ -256,40 +256,38 @@ class Salet
|
|||
code that further calls doLink, and so on. This method processes
|
||||
each one, and processLink manages this.
|
||||
###
|
||||
@processOneLink = (code) =>
|
||||
@processOneLink = (code) ->
|
||||
match = code.match(@linkRe)
|
||||
if not match
|
||||
console.error "link_not_valid".l()
|
||||
console.error code
|
||||
return
|
||||
|
||||
situation = match[1]
|
||||
action = match[3]
|
||||
|
||||
# Change the situation
|
||||
if situation != '.' and situation != @current_room
|
||||
if situation != '.' and situation != @current
|
||||
@doTransitionTo(situation)
|
||||
else
|
||||
# We should have an action if we have no situation change.
|
||||
assert(action, "link_no_action".l())
|
||||
# Carry out the action
|
||||
if (action)
|
||||
room = @getCurrentRoom()
|
||||
if room
|
||||
consumed = false
|
||||
|
||||
# Carry out the action
|
||||
if (action)
|
||||
room = @getCurrentRoom()
|
||||
if room
|
||||
consumed = false
|
||||
if @beforeAction
|
||||
# Try the global act handler
|
||||
consumed = @beforeAction(room, action)
|
||||
|
||||
if @beforeAction
|
||||
# Try the global act handler
|
||||
consumed = @beforeAction(room, action)
|
||||
if consumed != true
|
||||
room.act(action)
|
||||
|
||||
if consumed != true
|
||||
room.act(action)
|
||||
|
||||
if @afterAction
|
||||
@afterAction(room, action)
|
||||
if @afterAction
|
||||
@afterAction(room, action)
|
||||
|
||||
# This gets called when the user clicks a link to carry out an action.
|
||||
@processClick = (code) =>
|
||||
@processClick = (code) ->
|
||||
now = (new Date()).getTime() * 0.001
|
||||
@time = now - @startTime
|
||||
@progress.sequence.push({link:code, when:@time})
|
||||
|
@ -299,7 +297,7 @@ class Salet
|
|||
|
||||
# Go back N rooms. It's not an UNDO.
|
||||
# Also, steps = 1 is the current room
|
||||
@goBack = (steps = 2) =>
|
||||
@goBack = (steps = 2) ->
|
||||
window.history.back()
|
||||
if @progress.path.length == 1
|
||||
location = @start
|
||||
|
@ -310,7 +308,7 @@ class Salet
|
|||
@processClick(location)
|
||||
|
||||
# Transition between rooms.
|
||||
@doTransitionTo = (newRoomId) =>
|
||||
@doTransitionTo = (newRoomId) ->
|
||||
oldRoomId = @current
|
||||
oldRoom = @getCurrentRoom()
|
||||
newRoom = @rooms[newRoomId]
|
||||
|
@ -342,14 +340,14 @@ class Salet
|
|||
game state across save/erase cycles, meaning that character.sandbox
|
||||
no longer has to be the end-all be-all repository of game state.
|
||||
###
|
||||
@eraseSave = (force = false) =>
|
||||
@eraseSave = (force = false) ->
|
||||
saveId = @getSaveId() # save slot
|
||||
if (localStorage.getItem(saveId) and (force or confirm("erase_message".l())))
|
||||
localStorage.removeItem(saveId)
|
||||
window.location.reload()
|
||||
|
||||
# Find and return a list of ids for all situations with the given tag.
|
||||
@getRoomsTagged = (tag) =>
|
||||
@getRoomsTagged = (tag) ->
|
||||
result = []
|
||||
for id, room of @rooms
|
||||
for i in room.tags
|
||||
|
@ -359,7 +357,7 @@ class Salet
|
|||
return result
|
||||
|
||||
# Saves the character and the walking history to local storage.
|
||||
@saveGame = () =>
|
||||
@saveGame = () ->
|
||||
# Store when we're saving the game, to avoid exploits where a
|
||||
# player loads their file to gain extra time.
|
||||
now = (new Date()).getTime() * 0.001
|
||||
|
@ -376,7 +374,10 @@ class Salet
|
|||
@view.enableLoading()
|
||||
|
||||
# Loads the game from the given data
|
||||
@loadGame = (saveFile) =>
|
||||
@loadGame = (saveFile) ->
|
||||
if !@interactive #don't enter recursion!
|
||||
return
|
||||
|
||||
@progress = saveFile.progress
|
||||
@character = new Character
|
||||
|
||||
|
@ -387,15 +388,10 @@ class Salet
|
|||
|
||||
# Run through all the player's history.
|
||||
@interactive = false
|
||||
laststep = undefined
|
||||
for step in @progress.sequence
|
||||
# skip through repeating steps (it's just inviting the bugs)
|
||||
if step.link == laststep
|
||||
continue
|
||||
# The action must be done at the recorded time.
|
||||
@time = step.when
|
||||
@processLink(step.link)
|
||||
laststep = step.link
|
||||
@interactive = true
|
||||
|
||||
# Reverse engineer the start time.
|
||||
|
@ -404,7 +400,7 @@ class Salet
|
|||
|
||||
@view = new SaletView
|
||||
|
||||
@getSave = (slot = "") =>
|
||||
@getSave = (slot = "") ->
|
||||
id = @getSaveId(slot)
|
||||
saveFile = false
|
||||
if (@view.hasLocalStorage())
|
||||
|
@ -412,7 +408,7 @@ class Salet
|
|||
saveFile = JSON.parse(saveFile)
|
||||
return saveFile
|
||||
|
||||
@beginGame = () =>
|
||||
@beginGame = () ->
|
||||
@view.fixClicks()
|
||||
|
||||
# Handle storage.
|
||||
|
@ -440,15 +436,15 @@ class Salet
|
|||
# Do the first state.
|
||||
@doTransitionTo(@start)
|
||||
|
||||
@getRoom = (name) =>
|
||||
@getRoom = (name) ->
|
||||
if @rooms[name]?
|
||||
return @rooms[name]
|
||||
return undefined
|
||||
|
||||
# Just an alias for getCurrentRoom
|
||||
@here = () => @getCurrentRoom()
|
||||
@here = () -> @getCurrentRoom()
|
||||
|
||||
@isVisited = (name) =>
|
||||
@isVisited = (name) ->
|
||||
place = @getRoom(name)
|
||||
if place
|
||||
return Boolean place.visited
|
||||
|
|
Loading…
Reference in a new issue