Module:MoveDataParser ROA: Difference between revisions

From Mizuumi Wiki
Jump to navigation Jump to search
(Created page with "local p = {} local cargo = mw.ext.cargo -- Color frame advantage text based on value (positive or negative) function p.colorizeFrameAdvantage(frame) -- Set the string to the first argument given local str = frame.args[1] -- Surrond all plus values with a span with style color green str = string.gsub(str, "(%+%d+)", "<span style=\"color:green;\">%1</span>") -- Surrond all negative values with a span with style color green str = string.gsub(str, "(%-%d+)", "<span...")
 
mNo edit summary
Line 84: Line 84:
-- Cargo query
-- Cargo query
if useHitbox == "yes" then
if useHitbox == "yes" then
result = cargo.query( cargoTable, fields, args )[1].hitboxes
result = cargo.query( cargoTable, fields, args )[1].img_hitbox
else
else
result = cargo.query( cargoTable, fields, args )[1].images
result = cargo.query( cargoTable, fields, args )[1].img
end
end

Revision as of 11:20, 1 May 2023

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

local p = {}
local cargo = mw.ext.cargo

-- Color frame advantage text based on value (positive or negative)
function p.colorizeFrameAdvantage(frame)
	-- Set the string to the first argument given
	local str = frame.args[1]
	
	-- Surrond all plus values with a span with style color green
	str = string.gsub(str, "(%+%d+)", "<span style=\"color:green;\">%1</span>")
	-- Surrond all negative values with a span with style color green
	str = string.gsub(str, "(%-%d+)", "<span style=\"color:red;\">%1</span>")
	
	-- Return the string
	return str
end

-- Create a wikitext hyperlink that links to the frame data page section of a move
-- Assumes the section header is the same as moveInput
function p.createFrameDataLink(frame)
	-- Target cargo table to query
	local cargoTable = frame.args['cargoTable']
	-- MoveId to query
	local move_id = frame.args['move_id']
	-- Field in to return in query
	local fields = "input"
	-- Args for query
	local args = { where = "move_id = '" .. move_id .. "'"}
	
	-- Beginning of wikitext to return
	local wikitext = "[[/Data#"
	
	-- Cargo query for moveInput
	local results = cargo.query( cargoTable, fields, args )
	local moveInput = results[1]['input']
	
	-- Replaces any left and right square brackets with their ascii code to make it wikitext compatible
	moveInput = string.gsub(moveInput, '%[', "&#91;")
	moveInput = string.gsub(moveInput, "%]", "&#93;")
	
	-- TODO: Maybe add alternate text instead of it just saying '/Data#moveInput'?
	-- Concatenates 'wikitext' with 'moveInput' and ending square brackets
	wikitext = wikitext .. moveInput .. "]]"
	
	-- Returns the wikitext
	return wikitext 
end

-- Cargo queries a single image by 3 unnamed arguments
--- 1 - name of target cargo table
--- 2 - moveId from that cargo table
--- 3 - image index of the move
function p.getMoveImage(frame)
	-- Target cargo table to query
	local cargoTable = frame.args[1]
	-- Target move to query
	local move_id = frame.args[2]
	-- Target image index (is default 1 from template MoveDataCargoImage)
	local imageIndex = frame.args[3]
	-- Boolean to use image or hitbox image
	local useHitbox = mw.text.trim(frame.args[4])
	-- Maximum height of the image or hitbox image, used to limit edge cases
	local imageHeight = mw.text.trim(frame.args[5])
	-- Wikitext to return after function is completed
	local wikitext = ""
	
	-- 'fields' part of the cargo query
	-- We need to grab only the first instance of each image "sorted" by moveId
	local fields = ""
	if useHitbox == "yes" then
		fields = "img_hitbox"
	else
		fields = "img"
	end
	
	-- 'args' part of the Lua cargo query
	local args = {
		-- 'whereQuery' from above which goes by moveIds
		where = "move_id = '" .. mw.text.trim(move_id) .. "'"
	}
	
	local result
	
	-- Cargo query
	if useHitbox == "yes" then
		result = cargo.query( cargoTable, fields, args )[1].img_hitbox
	else
		result = cargo.query( cargoTable, fields, args )[1].img
	end
	
	-- Turn query into list split by ','
	local listOfImages = mw.text.split(result,',')
	
	-- Get target image based on imageIndex
	local targetImage = listOfImages[tonumber(imageIndex)]
	
	-- Return the image as wikitext
	if imageHeight == "no" then
		wikitext = "[[File:" .. targetImage .. "|175px]]"
	else
		wikitext = "[[File:" .. targetImage .. "|x" .. imageHeight .. "]]"
	end
	
	return wikitext
end

return p