mirror of
https://gitlab.com/Oreolek/salet.git
synced 2024-07-04 07:45:03 +03:00
Examination and syntax rewrites
This commit is contained in:
parent
408d3bc1a5
commit
07b994cc7f
|
@ -89,22 +89,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div> <!-- End of div.page -->
|
</div> <!-- End of div.page -->
|
||||||
|
|
||||||
<div id="ui_library">
|
|
||||||
<div id="quality" class="quality">
|
|
||||||
<span class="name" data-attr="name"></span>
|
|
||||||
<span class="value" data-attr="value"></span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="quality_group" class="quality_group">
|
|
||||||
<h2 data-attr="title"></h2>
|
|
||||||
<div class="qualities_in_group">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<hr id="turn_separator">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="content_library"></div>
|
|
||||||
<!-- CDN JS Libraries -->
|
<!-- CDN JS Libraries -->
|
||||||
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js"></script>
|
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js"></script>
|
||||||
<script type="text/javascript" src="//code.jquery.com/jquery-2.2.0.min.js"></script>
|
<script type="text/javascript" src="//code.jquery.com/jquery-2.2.0.min.js"></script>
|
||||||
|
|
|
@ -22,11 +22,12 @@ class SaletObj
|
||||||
return null
|
return null
|
||||||
for key, value of spec
|
for key, value of spec
|
||||||
this[key] = value
|
this[key] = value
|
||||||
level: 0
|
level: 0 # if > 0 it's hidden
|
||||||
|
order: 0 # you can use this to sort the descriptions
|
||||||
look: (system, f) =>
|
look: (system, f) =>
|
||||||
if @dsc
|
if @dsc and @dsc != ""
|
||||||
text = markdown(@dsc.fcall(this, system, f).toString())
|
text = markdown(@dsc.fcall(this, system, f).toString())
|
||||||
text = "<span class='look lvl#{@level}'>" + text + "</span>"
|
text = system.view.wrapLevel(text, @level)
|
||||||
# replace braces {{}} with link to _act_
|
# replace braces {{}} with link to _act_
|
||||||
return parsedsc(text, @name)
|
return parsedsc(text, @name)
|
||||||
takeable: false
|
takeable: false
|
||||||
|
|
|
@ -126,12 +126,25 @@ class SaletRoom
|
||||||
retval += '<div class="pic">'+system.view.pictureTag(@pic.fcall(this, system, f))+'</div>'
|
retval += '<div class="pic">'+system.view.pictureTag(@pic.fcall(this, system, f))+'</div>'
|
||||||
|
|
||||||
# Print the room description
|
# Print the room description
|
||||||
if @dsc
|
if @dsc and @dsc != ""
|
||||||
dsc = @dsc.fcall(this, system, f).toString()
|
dsc = @dsc.fcall(this, system, f).toString()
|
||||||
retval += markdown(dsc)
|
retval += markdown(dsc)
|
||||||
|
|
||||||
for name, thing of @objects
|
objDescriptions = []
|
||||||
retval += thing.look()
|
for thing in @objects
|
||||||
|
console.log thing
|
||||||
|
if thing.name and typeof(thing.look) == "function" and thing.level == 0 and thing.look(system, f)
|
||||||
|
objDescriptions.push ({
|
||||||
|
order: thing.order,
|
||||||
|
content: thing.look(system, f)
|
||||||
|
})
|
||||||
|
|
||||||
|
objDescriptions.sort((a, b) ->
|
||||||
|
return a.order - b.order
|
||||||
|
)
|
||||||
|
|
||||||
|
for description in objDescriptions
|
||||||
|
retval += description.content
|
||||||
|
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
|
@ -153,8 +166,8 @@ class SaletRoom
|
||||||
###
|
###
|
||||||
act: (system, action) =>
|
act: (system, action) =>
|
||||||
if (link = action.match(/^_(act|cycle)_(.+)$/)) #object action
|
if (link = action.match(/^_(act|cycle)_(.+)$/)) #object action
|
||||||
for name, thing of @objects
|
for thing in @objects
|
||||||
if name == link[2]
|
if thing.name == link[2]
|
||||||
if link[1] == "act"
|
if link[1] == "act"
|
||||||
# If it's takeable, the player can take this object.
|
# If it's takeable, the player can take this object.
|
||||||
# If not, we check the "act" function.
|
# If not, we check the "act" function.
|
||||||
|
@ -165,11 +178,15 @@ class SaletRoom
|
||||||
@entering.fcall(this, system, @name)
|
@entering.fcall(this, system, @name)
|
||||||
return system.view.write(thing.take.fcall(thing, system).toString())
|
return system.view.write(thing.take.fcall(thing, system).toString())
|
||||||
if thing.act
|
if thing.act
|
||||||
return system.view.write(thing.act.fcall(thing, system).toString())
|
system.view.changeLevel(thing.level)
|
||||||
elseif link[1] == "cycle"
|
return system.view.write(
|
||||||
# TODO object cyclewriter
|
system.view.wrapLevel(
|
||||||
|
thing.act.fcall(thing, system).toString(),
|
||||||
|
thing.level
|
||||||
|
)
|
||||||
|
)
|
||||||
# the loop is done but no return came - match not found
|
# the loop is done but no return came - match not found
|
||||||
console.error("Could not find #{link[1]} in current room.")
|
console.error("Could not find #{link[2]} in current room.")
|
||||||
|
|
||||||
# we're done with objects, now check the regular actions
|
# we're done with objects, now check the regular actions
|
||||||
actionClass = action.match(/^_(\w+)_(.+)$/)
|
actionClass = action.match(/^_(\w+)_(.+)$/)
|
||||||
|
@ -222,7 +239,7 @@ class SaletRoom
|
||||||
return this
|
return this
|
||||||
|
|
||||||
writers:
|
writers:
|
||||||
cyclewriter: (salet) ->
|
cyclewriter: (salet) =>
|
||||||
responses = @cycle
|
responses = @cycle
|
||||||
if typeof responses == "function"
|
if typeof responses == "function"
|
||||||
responses = responses()
|
responses = responses()
|
||||||
|
|
|
@ -138,7 +138,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
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ class Salet
|
||||||
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
|
||||||
|
@ -259,13 +259,16 @@ 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) =>
|
||||||
|
return @processLink(roomId)
|
||||||
|
|
||||||
###
|
###
|
||||||
This gets called to actually do the work of processing a code.
|
This gets called to actually do the work of processing a code.
|
||||||
When one doLink is called (or a link is clicked), this may set call
|
When one doLink is called (or a link is clicked), this may set call
|
||||||
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)
|
||||||
assert(match, "link_not_valid".l({link:code}))
|
assert(match, "link_not_valid".l({link:code}))
|
||||||
|
|
||||||
|
@ -292,14 +295,14 @@ class Salet
|
||||||
@afterAction(this, room, action)
|
@afterAction(this, 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})
|
||||||
@processLink(code)
|
@processLink(code)
|
||||||
|
|
||||||
# Transitions between situations.
|
# Transitions between situations.
|
||||||
doTransitionTo: (newRoomId) ->
|
doTransitionTo: (newRoomId) =>
|
||||||
oldRoomId = @current
|
oldRoomId = @current
|
||||||
oldRoom = @getCurrentRoom()
|
oldRoom = @getCurrentRoom()
|
||||||
newRoom = @rooms[newRoomId]
|
newRoom = @rooms[newRoomId]
|
||||||
|
@ -348,7 +351,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
|
||||||
|
@ -366,7 +369,7 @@ class Salet
|
||||||
@view.enableLoading()
|
@view.enableLoading()
|
||||||
|
|
||||||
# Loads the game from the given data
|
# Loads the game from the given data
|
||||||
loadGame: (saveFile) ->
|
loadGame: (saveFile) =>
|
||||||
@progress = saveFile.progress
|
@progress = saveFile.progress
|
||||||
@character = saveFile.character
|
@character = saveFile.character
|
||||||
|
|
||||||
|
@ -395,7 +398,9 @@ class Salet
|
||||||
|
|
||||||
view: new SaletView
|
view: new SaletView
|
||||||
|
|
||||||
beginGame: () ->
|
beginGame: () =>
|
||||||
|
@view.fixClicks()
|
||||||
|
|
||||||
# Handle storage.
|
# Handle storage.
|
||||||
saveFile = false
|
saveFile = false
|
||||||
if (@view.hasLocalStorage())
|
if (@view.hasLocalStorage())
|
||||||
|
@ -425,21 +430,13 @@ class Salet
|
||||||
# Do the first state.
|
# Do the first state.
|
||||||
@doTransitionTo(@start)
|
@doTransitionTo(@start)
|
||||||
|
|
||||||
# Any point that an option list appears, its options are its first links.
|
getRoom: (name) =>
|
||||||
$("body").on('click', "ul.options li, #menu li", (event) ->
|
|
||||||
# Make option clicks pass through to their first link.
|
|
||||||
link = $("a", this)
|
|
||||||
if (link.length > 0)
|
|
||||||
$(link.get(0)).click()
|
|
||||||
)
|
|
||||||
|
|
||||||
getRoom: (name) ->
|
|
||||||
return @rooms[name]
|
return @rooms[name]
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
@ -23,7 +23,7 @@ addClass = (element, className) ->
|
||||||
element.className += ' ' + className
|
element.className += ' ' + className
|
||||||
|
|
||||||
class SaletView
|
class SaletView
|
||||||
init: (salet) ->
|
init: (salet) =>
|
||||||
$("#content, #ways").on("click", "a", (event) ->
|
$("#content, #ways").on("click", "a", (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
a = $(this)
|
a = $(this)
|
||||||
|
@ -95,7 +95,7 @@ class SaletView
|
||||||
return content.toString()
|
return content.toString()
|
||||||
|
|
||||||
# Write content to current room
|
# Write content to current room
|
||||||
write: (content, elementSelector = "#current-room") ->
|
write: (content, elementSelector = "#current-room") =>
|
||||||
if content == ""
|
if content == ""
|
||||||
return
|
return
|
||||||
content = @prepareContent(content)
|
content = @prepareContent(content)
|
||||||
|
@ -109,7 +109,7 @@ class SaletView
|
||||||
|
|
||||||
# Replaces the text in the given block with the given text.
|
# Replaces the text in the given block with the given text.
|
||||||
# !! Does not call markdown on the provided text. !!
|
# !! Does not call markdown on the provided text. !!
|
||||||
replace: (content, elementSelector) ->
|
replace: (content, elementSelector) =>
|
||||||
if content == ""
|
if content == ""
|
||||||
return
|
return
|
||||||
content = @prepareContent(content)
|
content = @prepareContent(content)
|
||||||
|
@ -143,7 +143,7 @@ class SaletView
|
||||||
manually, ot else use the `getSituationIdChoices` method to
|
manually, ot else use the `getSituationIdChoices` method to
|
||||||
return an ordered list of valid viewable situation ids.
|
return an ordered list of valid viewable situation ids.
|
||||||
###
|
###
|
||||||
writeChoices: (salet, listOfIds) ->
|
writeChoices: (salet, listOfIds) =>
|
||||||
if (not listOfIds? or listOfIds.length == 0)
|
if (not listOfIds? or listOfIds.length == 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -192,6 +192,23 @@ class SaletView
|
||||||
else
|
else
|
||||||
contentToHide.remove()
|
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) =>
|
||||||
|
maxLevel = 6
|
||||||
|
if level < maxLevel
|
||||||
|
i = level + 1
|
||||||
|
hideArray = []
|
||||||
|
while i <= maxLevel
|
||||||
|
hideArray.push("#content .lvl"+i)
|
||||||
|
i++
|
||||||
|
directive = hideArray.join(", ")
|
||||||
|
$(directive).fadeOut("slow")
|
||||||
|
|
||||||
|
wrapLevel: (text, level) =>
|
||||||
|
return "<span class='lvl#{level}'>"+text+'</span>'
|
||||||
|
|
||||||
# At last, we scroll the view so that .new objects are in view.
|
# At last, we scroll the view so that .new objects are in view.
|
||||||
endOutputTransaction: () =>
|
endOutputTransaction: () =>
|
||||||
if !@interactive
|
if !@interactive
|
||||||
|
@ -232,6 +249,15 @@ class SaletView
|
||||||
hasLocalStorage: () ->
|
hasLocalStorage: () ->
|
||||||
return window.localStorage?
|
return window.localStorage?
|
||||||
|
|
||||||
|
# Any point that an option list appears, its options are its first links.
|
||||||
|
fixClicks: () ->
|
||||||
|
$("body").on('click', "ul.options li", (event) ->
|
||||||
|
# Make option clicks pass through to their first link.
|
||||||
|
link = $("a", this)
|
||||||
|
if (link.length > 0)
|
||||||
|
$(link.get(0)).click()
|
||||||
|
)
|
||||||
|
|
||||||
updateWays: (salet, ways, name) ->
|
updateWays: (salet, ways, name) ->
|
||||||
content = ""
|
content = ""
|
||||||
distances = []
|
distances = []
|
||||||
|
|
Loading…
Reference in a new issue