Module:Move7: Difference between revisions

From Wavu Wiki, the 🌊 wavy Tekken wiki
No edit summary
(replace error() with assert())
Line 16: Line 16:
while (parentId ~= nil and parentId ~= '') do
while (parentId ~= nil and parentId ~= '') do
local parent = cargo.query(tables, 'input,target,damage,parent', { where = "id='" .. parentId .. "'" })[1]
local parent = cargo.query(tables, 'input,target,damage,parent', { where = "id='" .. parentId .. "'" })[1]
if parent == nil then
assert(parent, 'Error: parent = "' .. parentId .. '" not found')
error('Error: parent = "' .. parentId .. '" not found')
end


parentId = parent['parent']
parentId = parent['parent']
Line 49: Line 47:
p.query = function(frame)
p.query = function(frame)
local args = frame:getParent().args
local args = frame:getParent().args
local id = args[1]
local id = assert(args[1], '1st unnamed param must be move id')
if id == nil then
error('1st unnamed param must be move id')
end
id = mw.text.trim(id) -- whitespace is stripped only from named params
id = mw.text.trim(id) -- whitespace is stripped only from named params
local result = cargo.query(tables, p.fields, { where = "id = '" .. id .. "'" })[1]
local result = cargo.query(tables, p.fields, { where = "id = '" .. id .. "'" })[1]
if result == nil then
assert(result, "move with id = '" .. id .. "' not found")
error("move with id = '" .. id .. "' not found")
end
for k, v in pairs(result) do
for k, v in pairs(result) do

Revision as of 16:04, 24 August 2023

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

local p = {};
local cargo = mw.ext.cargo
local tables = 'MoveDataCargoTest'

p.fields = 'id,name,input,target,damage,reach,tracksLeft,tracksRight,startup,recv,tot,crush,block,hit,ch,notes'


p.display = function(frame)
	local function appendFrom(dst, src)
		for k, v in pairs(src) do
			dst[k] = v
		end
	end
	local function getLeads(parentId)
		local leads = {}
		while (parentId ~= nil and parentId ~= '') do
			local parent = cargo.query(tables, 'input,target,damage,parent', { where = "id='" .. parentId .. "'" })[1]
			assert(parent, 'Error: parent = "' .. parentId .. '" not found')

			parentId = parent['parent']
			parent['parent'] = nil
			
			for k, v in pairs(parent) do
				local leadName = k .. 'Lead'
				if leads[leadName] == nil then
					leads[leadName] = ''
				end
				
				leads[leadName] = v .. leads[leadName]
			end
		end
		
		return leads
	end
	
	local leads = getLeads(frame:getParent().args['parent'])
	if next(leads) == nil then
		return frame:expandTemplate{ title = 'MoveData', args = frame:getParent().args }
	end
	
	local args = {}
	appendFrom(args, frame:getParent().args)
	appendFrom(args, leads)
	return frame:expandTemplate{ title = 'MoveData', args = args }
end

p.query = function(frame)
	local args = frame:getParent().args
	local id = assert(args[1], '1st unnamed param must be move id')
	id = mw.text.trim(id) -- whitespace is stripped only from named params
	
	local result = cargo.query(tables, p.fields, { where = "id = '" .. id .. "'" })[1]
	assert(result, "move with id = '" .. id .. "' not found")
	
	for k, v in pairs(result) do
		local override = args[k]
		if override ~= nil then
			result[k] = override
		end
	end
	
	return frame:expandTemplate{ title = 'MoveDataCargoTest/Display', args = result }
end

return p