mirror of
https://gitlab.com/Oreolek/salet.git
synced 2024-07-07 01:04:25 +03:00
Fixed once links.
Looks finished (except for saving)
This commit is contained in:
parent
5af7d3ad72
commit
b6696ff981
|
@ -20,10 +20,6 @@ assert = (msg, assertion) -> console.assert assertion, msg
|
||||||
class Character
|
class Character
|
||||||
inventory: []
|
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 is the control structure, it has minimal amount of data and
|
||||||
this data is volatile anyway (as in, it won't get saved).
|
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.
|
# The unique id of the starting room.
|
||||||
start: "start"
|
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
|
This function is called at the start of the game. It is
|
||||||
normally overridden to provide initial character creation
|
normally overridden to provide initial character creation
|
||||||
|
@ -264,7 +264,7 @@ class Salet
|
||||||
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}))
|
||||||
|
|
||||||
situation = match[1]
|
situation = match[1]
|
||||||
|
|
|
@ -26,7 +26,12 @@ class SaletView
|
||||||
init: (salet) ->
|
init: (salet) ->
|
||||||
$("#content, #ways").on("click", "a", (event) ->
|
$("#content, #ways").on("click", "a", (event) ->
|
||||||
event.preventDefault()
|
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) ->
|
$("#inventory").on("click", "a", (event) ->
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
@ -111,8 +116,11 @@ class SaletView
|
||||||
a link the 'once' class.
|
a link the 'once' class.
|
||||||
###
|
###
|
||||||
clearLinks: (code) ->
|
clearLinks: (code) ->
|
||||||
for a in $("a[href='" + code + "']")
|
for a in $("#content").find("a[href='" + code + "']")
|
||||||
a.replaceWith($("<span>").addClass("ex_link").html(a.html()))
|
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
|
Given a list of situation ids, this outputs a standard option
|
||||||
|
@ -249,7 +257,9 @@ class SaletView
|
||||||
min_key.push(node.key)
|
min_key.push(node.key)
|
||||||
if min < Infinity
|
if min < Infinity
|
||||||
for node in min_key
|
for node in min_key
|
||||||
addClass(document.getElementById("waylink-#{node}"), "destination")
|
waylink = document.getElementById("waylink-#{node}")
|
||||||
|
if waylink
|
||||||
|
addClass(waylink, "destination")
|
||||||
|
|
||||||
pictureTag = (picture) ->
|
pictureTag = (picture) ->
|
||||||
extension = picture.substr((~-picture.lastIndexOf(".") >>> 0) + 2)
|
extension = picture.substr((~-picture.lastIndexOf(".") >>> 0) + 2)
|
||||||
|
@ -262,27 +272,4 @@ class SaletView
|
||||||
"""
|
"""
|
||||||
return "<img class='img-responsive' src='#{picture}' alt='Room illustration'>"
|
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
|
module.exports = SaletView
|
||||||
|
|
Loading…
Reference in a new issue