Module:Script-IS
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Script-IS/doc
local p = {}
--custom script for the IS wiki, feel free to make a copy of it or take any part of the code for other wikis
--split multiple properties passed as a single param to a template call and return the converted property text
--local functions used by p.gameInput()
local function getColor(btn)
--recognized buttons
switch = {
["L"] = "#0073AA",
["M"] = "#886A00",
["H"] = "#CA3700",
["S"] = "#B800D9",
["G"] = "#5500B1",
["X"] = "#686868",
["LM"] = "#5500B1",
["MH"] = "#A95E00",
["LH"] = "#000000",
["LMH"] = "#000000",
["CH"] = "#000000",
["OTG"] = "#000000",
["SSR"] = "#000000",
}
--return a full match, or if there is no full match then a match on the last character
btn = btn:gsub('+','')
local ret = switch[btn] or switch[string.sub(btn, -1)] or "#000000"
return ret
end
local function colorFormat(button, text)
if text == '' then return '' end
local clr = getColor(button)
local start = "<span style=\"color:"
local mid = ";\">"
local endstr = "</span>"
local ctext = start .. clr .. mid .. text .. endstr
return ctext
end
--actual method functions
function p.multiprop(frame)
local str = frame.args[1]
local sep = ","
local t={}
--split properties
for str in string.gmatch(str, "([^"..sep.."]+)") do
table.insert(t, str)
end
--get the string done
for index, prop in ipairs(t) do
if prop:sub(1,1) == "%s" then
prop = prop:sub(2,-1)
end
expanded = frame:expandTemplate{ title="Property-IS", args={prop,"IGNOREPROPERTYERROR"}}
t[index] = expanded
end
ret = table.concat(t,", ")
return ret
end
--color code and format game inputs.
--supports entire combos as arguments.
function p.gameInput(frame)
local str = frame.args[1]
local inputs = {}
--split the sequence into separate moves
for link, command, separator, leftbracket, button, rightbracket, s1, suffix, s2 in string.gmatch(str, "([^%w]*)([Jj]?%.?[%d]*)([^%w%[%{ ]*)([%[%{]*)([%a%+]*)([%}%]]*)(%(?)(%w*)(%)?)") do
-- link: Everything in between moves. All whitespace and move linking syntax ends up here.
-- command: Directional numbers with an optional J for air moves.
-- separator: Any symbols between the command and button.
-- leftbracket: [ or { around the button
-- button: The button. Can be a single letter or a full word.
-- rightbracket: ] or } around the button
-- suffix: Extra alphanumeric characters directly after the move. s1 and s2 match surrounding parenthesis.
table.insert(inputs, link)
if separator ~= '' then
-- If the command and button input are separate, do not color the command input.
table.insert(inputs, command .. separator)
table.insert(inputs, colorFormat(button, leftbracket .. button .. rightbracket))
else
table.insert(inputs, colorFormat(button, command .. leftbracket .. button .. rightbracket))
end
if suffix ~= '' then
-- If there is a suffix, color it the same as the button.
table.insert(inputs, colorFormat(button, s1 .. suffix .. s2))
else
table.insert(inputs, s1 .. suffix .. s2)
end
end
local ret = "<span style=\"font-weight:bold\">" .. table.concat(inputs, "") .. "</span>"
return ret
end
return p