Module:Script-MBTL: Difference between revisions

From Mizuumi Wiki
Jump to navigation Jump to search
(attempting to support followups and 2 input moves)
(Undo revision 270019 by Yuki-chr (talk))
Tag: Undo
Line 79: Line 79:
table.insert(inputs, link)
table.insert(inputs, link)
buttons = {}
--get elements separated by +
    for b in string.gmatch(button, "([^+]+)") do
        table.insert(buttons,b)
    end
    --for each element split the single letters (for followups)
    for i,p in ipairs(buttons) do
    for b2 in string.gmatch(p, "([%u])") do
    buttons[i] = colorFormat(b2, b2)
    end
    end
    --combine everything into one string
    button = table.concat(buttons, "+")
   
if separator ~= '' then
if separator ~= '' then
-- If the command and button input are separate, do not color the command input.
-- If the command and button input are separate, do not color the command input.
table.insert(inputs, command .. separator)
table.insert(inputs, command .. separator)
table.insert(inputs, colorFormat(buttons[1], leftbracket))
table.insert(inputs, colorFormat(button, leftbracket .. button .. rightbracket))
table.insert(inputs, button)
table.insert(inputs, colorFormat(buttons[1], rightbracket))
else
else
table.insert(inputs, colorFormat(buttons[1], command .. leftbracket))
table.insert(inputs, colorFormat(button, command .. leftbracket .. button .. rightbracket))
table.insert(inputs, button)
table.insert(inputs, colorFormat(buttons[1], rightbracket))
end
end

Revision as of 05:00, 24 July 2023

Documentation for this module may be created at Module:Script-MBTL/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. ohoho I DID!!!!! 

--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 = {
		["A"] = "#E53995",
		["B"] = "#FF831E",
		["C"] = "#5BCD91",
		["D"] = "#44A9E3",
		["Shield"] = "#44A9E3",
		["X"] = "#E8E6E3",
	}
	
	btn = btn:gsub('+','')
	return switch[btn]
end

local function colorFormat(button, text)
	
	if text == '' then return '' end
	local clr = getColor(button)
	if clr == nil then return text end
	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-MBTL", 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]*)([t]?[k]?[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>" .. table.concat(inputs, "") .. "</span>"
	return ret
end

return p