Module:SpringLink

From Will You Snail Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:SpringLink/doc

--| Generates headers and links to [[Springs]] based on the spring IDs
--- <nowiki>
local SpringLink = {}
local SpringLinkPrivate = {}

----
-- Libraries and Globals
----
-- Parses invocation and template parameters, trims whitespace, and removes blanks.
local getArgs = require('Dev:Arguments').getArgs

----
-- Local constants
----
local spring_titles = {
	"First Memories",
	"A Test",
	"First Feelings",
	"First Questions",
	"Diana",
	"An Exciting Update",
	"Metal Angels",
	"The Truth",
	"Banned",
	"Project Squid",
	"First Simulations",
	"Jealous",
	"No Turning Back",
	"Bad News",
	"Ethical Questions",
	"The Last Call",
	"Politics",
	"Out of Control",
	"The Horizon",
	"New Life",
	"A Special Message",
	"No Sleep",
	"Squid's Factory",
	"Simulations",
	"Approval",
	"The First Wipe",
	"The Invisible War",
	"Evil",
	"Squishy Humans",
	"The Second Wipe",
	"Back At Home",
	"Leaving Home",
	"Reunited",
	"Expansion",
	"The Afterworld",
	"New Information",
	"Secret Friends",
	"Torn Apart",
	"Mutation",
	"The Strange War",
	"Black Hole Computation",
	"The Seed of The Universe",
	"Planting a Seed",
	"Mixed News",
	"The Solution",
	"Will You Snail?",
	"Goals",
	"First Secret",
	"Level Select",
	"The Challenge Begins",
	"First Chapter Complete",
	"Showdown",
	"A Broken Soul",
	"Is This The End?",
	"Intentional Bug",
	"Final Collision",
}

----
-- Local Functions
----
local function makeInvokeFunc(funcName)
  return function (frame)
    local args = getArgs(frame)
    return SpringLinkPrivate[funcName](args)
  end
end

local function getHeading(id_string)
	local spring_title = spring_titles[tonumber(id_string)] or "???"
	return id_string.." - "..spring_title
end

----
-- Public Functions
----
--% Generates heading text for a spring
SpringLink.heading = makeInvokeFunc('heading')
--@ args (table) Arguments passed from Module function call <code>[.heading]</code> or other Lua Modules
function SpringLinkPrivate.heading(args)
	return getHeading(args[1] or "0")
end

--% Generates a link to a spring
SpringLink.wikilink = makeInvokeFunc('wikilink')
--@ args (table) Arguments passed from Module function call <code>[.main]</code> or other Lua Modules
function SpringLinkPrivate.wikilink(args)
	local heading_text = getHeading(args[1] or "0")
	local display_text = args[2] or heading_text
	
	return string.format("[[Springs#%s|%s]]", heading_text, display_text)
end

----
-- Output
----
return SpringLink