1
0
Fork 0
mirror of https://gitlab.com/Oreolek/salet.git synced 2024-07-02 06:45:06 +03:00

Examination and syntax rewrites

This commit is contained in:
Alexander Yakovlev 2016-02-08 19:12:12 +07:00
parent 408d3bc1a5
commit 07b994cc7f
5 changed files with 77 additions and 52 deletions

View file

@ -89,22 +89,6 @@
</div>
</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 -->
<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>

View file

@ -22,11 +22,12 @@ class SaletObj
return null
for key, value of spec
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) =>
if @dsc
if @dsc and @dsc != ""
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_
return parsedsc(text, @name)
takeable: false

View file

@ -126,12 +126,25 @@ class SaletRoom
retval += '<div class="pic">'+system.view.pictureTag(@pic.fcall(this, system, f))+'</div>'
# Print the room description
if @dsc
if @dsc and @dsc != ""
dsc = @dsc.fcall(this, system, f).toString()
retval += markdown(dsc)
for name, thing of @objects
retval += thing.look()
objDescriptions = []
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
@ -153,8 +166,8 @@ class SaletRoom
###
act: (system, action) =>
if (link = action.match(/^_(act|cycle)_(.+)$/)) #object action
for name, thing of @objects
if name == link[2]
for thing in @objects
if thing.name == link[2]
if link[1] == "act"
# If it's takeable, the player can take this object.
# If not, we check the "act" function.
@ -165,11 +178,15 @@ class SaletRoom
@entering.fcall(this, system, @name)
return system.view.write(thing.take.fcall(thing, system).toString())
if thing.act
return system.view.write(thing.act.fcall(thing, system).toString())
elseif link[1] == "cycle"
# TODO object cyclewriter
system.view.changeLevel(thing.level)
return system.view.write(
system.view.wrapLevel(
thing.act.fcall(thing, system).toString(),
thing.level
)
)
# 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
actionClass = action.match(/^_(\w+)_(.+)$/)
@ -222,7 +239,7 @@ class SaletRoom
return this
writers:
cyclewriter: (salet) ->
cyclewriter: (salet) =>
responses = @cycle
if typeof responses == "function"
responses = responses()

View file

@ -138,7 +138,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
@ -228,7 +228,7 @@ class Salet
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
@ -259,13 +259,16 @@ class Salet
# We're able to save, if we weren't already.
@view.enableSaving()
goTo: (roomId) =>
return @processLink(roomId)
###
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
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)
assert(match, "link_not_valid".l({link:code}))
@ -292,14 +295,14 @@ class Salet
@afterAction(this, 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})
@processLink(code)
# Transitions between situations.
doTransitionTo: (newRoomId) ->
doTransitionTo: (newRoomId) =>
oldRoomId = @current
oldRoom = @getCurrentRoom()
newRoom = @rooms[newRoomId]
@ -348,7 +351,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
@ -366,7 +369,7 @@ class Salet
@view.enableLoading()
# Loads the game from the given data
loadGame: (saveFile) ->
loadGame: (saveFile) =>
@progress = saveFile.progress
@character = saveFile.character
@ -395,7 +398,9 @@ class Salet
view: new SaletView
beginGame: () ->
beginGame: () =>
@view.fixClicks()
# Handle storage.
saveFile = false
if (@view.hasLocalStorage())
@ -425,21 +430,13 @@ class Salet
# Do the first state.
@doTransitionTo(@start)
# Any point that an option list appears, its options are its first links.
$("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) ->
getRoom: (name) =>
return @rooms[name]
# Just an alias for getCurrentRoom
here: () -> @getCurrentRoom()
here: () => @getCurrentRoom()
isVisited: (name) ->
isVisited: (name) =>
place = @getRoom(name)
if place
return Boolean place.visited

View file

@ -23,7 +23,7 @@ addClass = (element, className) ->
element.className += ' ' + className
class SaletView
init: (salet) ->
init: (salet) =>
$("#content, #ways").on("click", "a", (event) ->
event.preventDefault()
a = $(this)
@ -95,7 +95,7 @@ class SaletView
return content.toString()
# Write content to current room
write: (content, elementSelector = "#current-room") ->
write: (content, elementSelector = "#current-room") =>
if content == ""
return
content = @prepareContent(content)
@ -109,7 +109,7 @@ class SaletView
# Replaces the text in the given block with the given text.
# !! Does not call markdown on the provided text. !!
replace: (content, elementSelector) ->
replace: (content, elementSelector) =>
if content == ""
return
content = @prepareContent(content)
@ -143,7 +143,7 @@ class SaletView
manually, ot else use the `getSituationIdChoices` method to
return an ordered list of valid viewable situation ids.
###
writeChoices: (salet, listOfIds) ->
writeChoices: (salet, listOfIds) =>
if (not listOfIds? or listOfIds.length == 0)
return
@ -192,6 +192,23 @@ class SaletView
else
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.
endOutputTransaction: () =>
if !@interactive
@ -232,6 +249,15 @@ class SaletView
hasLocalStorage: () ->
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) ->
content = ""
distances = []