0
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet-module.git synced 2024-07-01 06:15:04 +03:00

Lots of small fixes, mostly in loading

This commit is contained in:
Alexander Yakovlev 2016-09-12 14:42:59 +07:00
parent 784ca8609f
commit 5403c65167
3 changed files with 41 additions and 44 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "salet", "name": "salet",
"version": "1.4.6", "version": "1.4.7",
"description": "A general client-side framework for cybertext interactive fiction games.", "description": "A general client-side framework for cybertext interactive fiction games.",
"keywords": ["ifiction", "interactive fiction", "games", "coffee-script", "text", "menu"], "keywords": ["ifiction", "interactive fiction", "games", "coffee-script", "text", "menu"],
"homepage": "http://salet.oreolek.ru", "homepage": "http://salet.oreolek.ru",

View file

@ -78,7 +78,8 @@ class SaletRoom
if salet.rooms[f].exit? if salet.rooms[f].exit?
salet.rooms[f].exit @name salet.rooms[f].exit @name
history.pushState(@name, @title) if window.history.pushState?
window.history.pushState(@name, @title)
if @enter if @enter
@enter f @enter f

View file

@ -10,7 +10,7 @@ Boolean.prototype.fcall = () ->
String.prototype.fcall = () -> String.prototype.fcall = () ->
return this 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 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 Before this function returns its result, it sorts the
situations in increasing order of their displayOrder values. situations in increasing order of their displayOrder values.
### ###
@getSituationIdChoices = (listOfOrOneIdsOrTags, maxChoices) => @getSituationIdChoices = (listOfOrOneIdsOrTags, maxChoices) ->
datum = null datum = null
i = 0 i = 0
@ -149,7 +149,7 @@ class Salet
room = @rooms[roomId] room = @rooms[roomId]
assert(room, "unknown_situation".l({id: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({ viewableRoomData.push({
priority: room.priority priority: room.priority
id: roomId id: roomId
@ -210,24 +210,24 @@ class Salet
# The stack of links, resulting from the last action, still be to resolved. # The stack of links, resulting from the last action, still be to resolved.
@linkStack = null @linkStack = null
@getCurrentRoom = () => @getCurrentRoom = () ->
if (@current) if (@current)
return @rooms[@current] return @rooms[@current]
return null return null
# Gets the unique id used to identify saved games. # Gets the unique id used to identify saved games.
@getSaveId = (slot = "") => @getSaveId = (slot = "") ->
return 'salet_'+@game_id+'_'+@game_version#+'_'+slot return 'salet_'+@game_id+'_'+@game_version#+'_'+slot
# This gets called when a link needs to be followed, regardless # This gets called when a link needs to be followed, regardless
# of whether it was user action that initiated it. # 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. # Check if we should do this now, or if processing is already underway.
if @linkStack != null if @linkStack != null
@linkStack.push(code) @linkStack.push(code)
return return
@view.mark_all_links_old @view.mark_all_links_old()
# We're processing, so make the stack available. # We're processing, so make the stack available.
@linkStack = [] @linkStack = []
@ -247,7 +247,7 @@ class Salet
# We're able to save, if we weren't already. # We're able to save, if we weren't already.
@view.enableSaving() @view.enableSaving()
@goTo = (roomId) => @goTo = (roomId) ->
return @processClick(roomId) return @processClick(roomId)
### ###
@ -256,22 +256,20 @@ class Salet
code that further calls doLink, and so on. This method processes code that further calls doLink, and so on. This method processes
each one, and processLink manages this. each one, and processLink manages this.
### ###
@processOneLink = (code) => @processOneLink = (code) ->
match = code.match(@linkRe) match = code.match(@linkRe)
if not match if not match
console.error "link_not_valid".l() console.error "link_not_valid".l()
console.error code console.error code
return
situation = match[1] situation = match[1]
action = match[3] action = match[3]
# Change the situation # Change the situation
if situation != '.' and situation != @current_room if situation != '.' and situation != @current
@doTransitionTo(situation) @doTransitionTo(situation)
else else
# We should have an action if we have no situation change.
assert(action, "link_no_action".l())
# Carry out the action # Carry out the action
if (action) if (action)
room = @getCurrentRoom() room = @getCurrentRoom()
@ -289,7 +287,7 @@ class Salet
@afterAction(room, action) @afterAction(room, action)
# This gets called when the user clicks a link to carry out an 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 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})
@ -299,7 +297,7 @@ class Salet
# Go back N rooms. It's not an UNDO. # Go back N rooms. It's not an UNDO.
# Also, steps = 1 is the current room # Also, steps = 1 is the current room
@goBack = (steps = 2) => @goBack = (steps = 2) ->
window.history.back() window.history.back()
if @progress.path.length == 1 if @progress.path.length == 1
location = @start location = @start
@ -310,7 +308,7 @@ class Salet
@processClick(location) @processClick(location)
# Transition between rooms. # Transition between rooms.
@doTransitionTo = (newRoomId) => @doTransitionTo = (newRoomId) ->
oldRoomId = @current oldRoomId = @current
oldRoom = @getCurrentRoom() oldRoom = @getCurrentRoom()
newRoom = @rooms[newRoomId] newRoom = @rooms[newRoomId]
@ -342,14 +340,14 @@ class Salet
game state across save/erase cycles, meaning that character.sandbox game state across save/erase cycles, meaning that character.sandbox
no longer has to be the end-all be-all repository of game state. no longer has to be the end-all be-all repository of game state.
### ###
@eraseSave = (force = false) => @eraseSave = (force = false) ->
saveId = @getSaveId() # save slot saveId = @getSaveId() # save slot
if (localStorage.getItem(saveId) and (force or confirm("erase_message".l()))) if (localStorage.getItem(saveId) and (force or confirm("erase_message".l())))
localStorage.removeItem(saveId) localStorage.removeItem(saveId)
window.location.reload() window.location.reload()
# Find and return a list of ids for all situations with the given tag. # Find and return a list of ids for all situations with the given tag.
@getRoomsTagged = (tag) => @getRoomsTagged = (tag) ->
result = [] result = []
for id, room of @rooms for id, room of @rooms
for i in room.tags for i in room.tags
@ -359,7 +357,7 @@ class Salet
return result return result
# Saves the character and the walking history to local storage. # Saves the character and the walking history to local storage.
@saveGame = () => @saveGame = () ->
# Store when we're saving the game, to avoid exploits where a # Store when we're saving the game, to avoid exploits where a
# player loads their file to gain extra time. # player loads their file to gain extra time.
now = (new Date()).getTime() * 0.001 now = (new Date()).getTime() * 0.001
@ -376,7 +374,10 @@ class Salet
@view.enableLoading() @view.enableLoading()
# Loads the game from the given data # Loads the game from the given data
@loadGame = (saveFile) => @loadGame = (saveFile) ->
if !@interactive #don't enter recursion!
return
@progress = saveFile.progress @progress = saveFile.progress
@character = new Character @character = new Character
@ -387,15 +388,10 @@ class Salet
# Run through all the player's history. # Run through all the player's history.
@interactive = false @interactive = false
laststep = undefined
for step in @progress.sequence 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. # The action must be done at the recorded time.
@time = step.when @time = step.when
@processLink(step.link) @processLink(step.link)
laststep = step.link
@interactive = true @interactive = true
# Reverse engineer the start time. # Reverse engineer the start time.
@ -404,7 +400,7 @@ class Salet
@view = new SaletView @view = new SaletView
@getSave = (slot = "") => @getSave = (slot = "") ->
id = @getSaveId(slot) id = @getSaveId(slot)
saveFile = false saveFile = false
if (@view.hasLocalStorage()) if (@view.hasLocalStorage())
@ -412,7 +408,7 @@ class Salet
saveFile = JSON.parse(saveFile) saveFile = JSON.parse(saveFile)
return saveFile return saveFile
@beginGame = () => @beginGame = () ->
@view.fixClicks() @view.fixClicks()
# Handle storage. # Handle storage.
@ -440,15 +436,15 @@ class Salet
# Do the first state. # Do the first state.
@doTransitionTo(@start) @doTransitionTo(@start)
@getRoom = (name) => @getRoom = (name) ->
if @rooms[name]? if @rooms[name]?
return @rooms[name] return @rooms[name]
return undefined return undefined
# Just an alias for getCurrentRoom # Just an alias for getCurrentRoom
@here = () => @getCurrentRoom() @here = () -> @getCurrentRoom()
@isVisited = (name) => @isVisited = (name) ->
place = @getRoom(name) place = @getRoom(name)
if place if place
return Boolean place.visited return Boolean place.visited