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

Fixed once links.

Looks finished (except for saving)
This commit is contained in:
Alexander Yakovlev 2016-02-01 16:54:15 +07:00
parent 5af7d3ad72
commit b6696ff981
2 changed files with 19 additions and 32 deletions

View file

@ -20,10 +20,6 @@ assert = (msg, assertion) -> console.assert assertion, msg
class Character
inventory: []
# Regular expression to catch every link action.
# Salet's default is a general URL-safe expression.
linkRe = /^([0-9A-Za-z_-]+|\.)(\/([0-9A-Za-z_-]+))?$/
###
This is the control structure, it has minimal amount of data and
this data is volatile anyway (as in, it won't get saved).
@ -42,6 +38,10 @@ class Salet
# The unique id of the starting room.
start: "start"
# Regular expression to catch every link action.
# Salet's default is a general URL-safe expression.
linkRe: /^([0-9A-Za-z_-]+|\.)(\/([0-9A-Za-z_-]+))?$/
###
This function is called at the start of the game. It is
normally overridden to provide initial character creation
@ -264,7 +264,7 @@ class Salet
each one, and processLink manages this.
###
processOneLink: (code) ->
match = code.match(linkRe)
match = code.match(@linkRe)
assert(match, "link_not_valid".l({link:code}))
situation = match[1]

View file

@ -26,7 +26,12 @@ class SaletView
init: (salet) ->
$("#content, #ways").on("click", "a", (event) ->
event.preventDefault()
salet.processClick($(this).attr("href"))
a = $(this)
href = a.attr('href')
if (href.match(salet.linkRe))
if (a.hasClass("once") || href.match(/[?&]once[=&]?/))
salet.view.clearLinks(href)
salet.processClick(href)
)
$("#inventory").on("click", "a", (event) ->
event.preventDefault()
@ -111,8 +116,11 @@ class SaletView
a link the 'once' class.
###
clearLinks: (code) ->
for a in $("a[href='" + code + "']")
a.replaceWith($("<span>").addClass("ex_link").html(a.html()))
for a in $("#content").find("a[href='" + code + "']")
html = a.innerHTML
a = $(a)
a.replaceWith($("<span>").addClass("ex_link").html(html))
return true
###
Given a list of situation ids, this outputs a standard option
@ -249,7 +257,9 @@ class SaletView
min_key.push(node.key)
if min < Infinity
for node in min_key
addClass(document.getElementById("waylink-#{node}"), "destination")
waylink = document.getElementById("waylink-#{node}")
if waylink
addClass(waylink, "destination")
pictureTag = (picture) ->
extension = picture.substr((~-picture.lastIndexOf(".") >>> 0) + 2)
@ -262,27 +272,4 @@ class SaletView
"""
return "<img class='img-responsive' src='#{picture}' alt='Room illustration'>"
# Returns HTML from the given content with the non-raw links wired up.
augmentLinks: (content) ->
output = $(content)
# Wire up the links for regular <a> tags.
for index, element in output.find("a")
a = $(element)
href = a.attr('href')
if (!a.hasClass("raw")|| href.match(/[?&]raw[=&]?/))
if (href.match(linkRe))
a.click((event) ->
event.preventDefault()
# If we're a once-click, remove all matching links.
if (a.hasClass("once") || href.match(/[?&]once[=&]?/))
@view.clearLinks(href)
processClick(href)
return false
)
else
a.addClass("raw")
return output
module.exports = SaletView