libquicklink

by Kuraudo
Add quicklinks such as google:hello and id:23 to your game.
ID:79010
 
Keywords: libraries, links
This library makes it easy to create links in text strings using shortcuts, similar to the way BYOND forums use the "id:" tag to make it easy to locate a specific post. Instead of having to write out the entire url of the post, you can just write "id:123456" and it will take you there. Using the quicklink library allows you to create your own shortcuts to, for example, look up an item in the dictionary or perhaps direct someone to the download link for a certain game resource.

Setting up quick links for your game is done in two steps, and its pretty easy once you see an example of it. Step one is to create the parser and quicklink datums, and step two is to run your text strings through the parser's parse() proc.


Step 1: Define your quick link types.

As an example, we're going to create a quick link that will allow people to link to the Google dictionary just like Google does using the shortcut name "define:".

quicklink
define
name = "define:"
url = "http://www.google.com/search?q=define:"

In order for it to be used in your program, you'll need to create your own instance of the parser like this:

var/quicklink_parser/quicklinks = new()


Step 2: Parse the message.

If you want to use this in a chat function so that whenever someone says something that includes "define:word", it will convert that into a link to Google's dictionary, all you need to do is run the message through the parser's parse() proc, like this:

mob/verb/Chat(message as text)
if(!message)
return
message = quicklinks.parse(message)
world << "[src]: [message]"

Using the parse(message) function will convert the matching tags into links, so define:game turns into define:game. If you want to use more than one word in your quick link arguments, you can put quotes around them, such as define:"au revoir".


Other Stuff:

Another tool that you can use when defining a quick link is the numeric variable. This variable means that only numeric arguments will be accepted for the quick link, just as BYOND's "id:" tag only accepts numeric values. id:123456 will convert to a link, but id:wookie will not. If you want your quick link to only accept numeric values, set it up like this:

quicklink
forum
name = "forum:"
url = "http://www.byond.com/developer/forum/?forum="
numeric = TRUE

If at any point while the game is running you want to find out what quick links are available, you can loop through the parser's quicklinks variable, which will contain all of the /quicklink datums that you've defined. You can find out what those datums are like this:

mob/verb/QuicklinksHelp()
src << "List of valid quick links:"
for(var/quicklink/link in quicklinks.quicklinks)
src << "\t - [link]"

And that's about all there is to it.
Looks good. I'll check it out.

One unrelated question though...

I submitted an article here for what seems like a month ago. How does this get through seemingly so fast, and yet it seems like nobody has found my submission. Maybe it dissapeared o.o, or maybe I just thought I sent it.
Its still there. Probably everybody has been to preoccupied with the other things happening to give it a serious look.
Yeah, there's one other article ahead of yours and then we'll give it a look. We haven't quite settled on submission standards, but we'll figure it out. I don't want to post everything at once since there is some advertising advantage of having an article on the front-page for at least a few hours.
I'm flattered to have released a library and found that, in less than 24 hours, a Dream Makers article was published on it. Thanks, Foomer!

If you wanted to make a follow-up part 2, or maybe even extend this version, you could maybe describe overriding procedures in the user-defined /quicklink datums, which is the element perhaps that adds greatest flexibility. Example: make() could be redefined for a hypothetical quicklink which goes to entirely different base URLs based on the query string.

This type of usage may fall under advanced use, but as a whole it makes the library more powerful.
I think you'd need to document it in your library before I'll attempt to fiddle with it. I'm not in the habit of tearing other people's libraries apart to figure out how everything works and what can be modified.