Module:Script-IS: Difference between revisions
Jump to navigation
Jump to search
(Adjust colors for visibility in non-dark mode) |
(Differentiate S and G) |
||
Line 15: | Line 15: | ||
["M"] = "#7A7A00", | ["M"] = "#7A7A00", | ||
["H"] = "#D93C00", | ["H"] = "#D93C00", | ||
["S"] = "# | ["S"] = "#B300D2", | ||
["G"] = "# | ["G"] = "#5500B1", | ||
["X"] = "#767676" | ["X"] = "#767676" | ||
} | } |
Revision as of 11:07, 27 May 2023
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"] = "#007BB7",
["M"] = "#7A7A00",
["H"] = "#D93C00",
["S"] = "#B300D2",
["G"] = "#5500B1",
["X"] = "#767676"
}
local color = switch[btn]
if (color==nil) then
color = "#000000"
end
return color
end
local function colorFormat(button, text)
local clr = getColor(button)
local start = "<span style=\"font-weight:bold;color:"
local mid = ";\">"
local endstr = "</span>"
local ctext = start .. clr .. mid .. text .. endstr
return ctext
end
local function chargedFormat(str)
local button
--handle [X] and {X} inputs
if string.sub(str, -1, -1) == "]" or string.sub(str, -1, -1) == "}" then
button = string.sub(str, -2, -2)
else
button = string.sub(str, -1, -1)
end
local ctext = colorFormat(button, str)
return ctext
end
local function followupFormat(str)
local flws = {}
--split options
for str in string.gmatch(str, "([^~]+)") do
table.insert(flws, str)
end
for index, flw in ipairs(flws) do
local cflw = chargedFormat(flw)
flws[index] = cflw
end
local ctext = table.concat(flws, "~")
return ctext
end
local function optionFormat(str)
local options = {}
--split options
for str in string.gmatch(str, "([^/]+)") do
table.insert(options, str)
end
for index, option in ipairs(options) do
local copt = followupFormat(option)
options[index] = copt
end
local ctext = table.concat(options, "/")
return ctext
end
local function bracketFormat(str)
local pre = ""
local post = ""
if string.sub(str, 1, 1) == "(" then
str = string.sub(str, 2, -1)
pre = "("
end
if string.sub(str, -1, -1) == ")" then
str = string.sub(str, 1, -2)
post = ")"
end
local ctext = pre .. optionFormat(str) .. post
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 sep = " "
local inputs = {}
--split combo terms
for str in string.gmatch(str, "([^"..sep.."]+)") do
table.insert(inputs, str)
end
for index, input in ipairs(inputs) do
local cterm = bracketFormat(input)
inputs[index] = cterm
end
local ret = table.concat(inputs, " ")
return ret
end
return p