Module:SkillDx2: Difference between revisions

Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(13 intermediate revisions by the same user not shown)
Line 11: Line 11:
local game = 'dx2'
local game = 'dx2'
local input = args[1]:lower()
local input = args[1]:lower()
local activeSkill = args[2]:lower()
local getSkill = require('Module:Data/Skill/dx2')
local getSkill = require('Module:Data/Skill/dx2')
local iconPage = mw.title.makeTitle('Module', 'Data/Icon/dx2') -- Creates information about a given page
local iconPage = mw.title.makeTitle('Module', 'Data/Icon/dx2') -- Creates information about a given page


-- 1 SKILL NAME
if input == '—' then
if not getSkill.skill[input] then --Error message for invalid skill
if activeSkill ~= '' then
error("Skill \"" .. input .. "\" not defined for dx2")
local output = "''No skill.''"
end
return output
-- 1.2 SKILL LINK
else
if getSkill.skill[input] and getSkill.skill[input].link then -- Check if an alternate link for a page is set in skill data
local output = "colspan=4|''No skill.''"
name = '[[' .. getSkill.skill[input].link .. '|' .. getSkill.skill[input].name .. ']]'
return output
else
end
name = '[[' .. getSkill.skill[input].name .. ']]'
end
-- 3 NAME AND ATTRIBUTE
-- 3.1 NAME NOTE
if getSkill.skill[input] and getSkill.skill[input].name_note then
namenote = frame:expandTemplate{ title = 'exp', args = { getSkill.skill[input].name_note } }
else
else
namenote = ''
-- 1 SKILL NAME
end
if not getSkill.skill[input] then --Error message for invalid skill
-- 4.1 SET ATTRIBUTE OUTPUT
error("Skill \"" .. input .. "\" not defined for dx2")
if getSkill.skill[input].attribute then
end
attribute = getSkill.skill[input].attribute:lower()
-- 1.2 SKILL LINK
else
if getSkill.skill[input] and getSkill.skill[input].link then -- Check if an alternate link for a page is set in skill data
attribute = ''
name = getSkill.skill[input].link .. '|' .. getSkill.skill[input].name
end
else
-- 4.2 IF ICON PAGE EXISTS
name = getSkill.skill[input].name
if iconPage.exists == true then
end
getIcon = require('Module:Data/Icon/' .. game)
-- 3 NAME AND ATTRIBUTE
if getIcon.icon[attribute] then -- Check if attribute is set in skill data
-- 3.1 NAME NOTE
nameattribute = '\n|style="text-align:left;"|' .. getIcon.icon[attribute] .. ' ' .. name .. rpname .. namenote -- Set icon
if getSkill.skill[input] and getSkill.skill[input].name_note then
elseif getSkill.skill[input] and getSkill.skill[input].attribute_link then
namenote = frame:expandTemplate{ title = 'exp', args = { getSkill.skill[input].name_note } }
nameattribute = '\n|style="text-align:center;"|' .. name .. namenote .. '\n|style="text-align:center;"|' .. '[[' .. getSkill.skill[input].attribute_link .. '|' .. attributeout .. ']]'
else
namenote = ''
end
-- 4.1 SET ATTRIBUTE OUTPUT
if getSkill.skill[input].attribute then
attribute = getSkill.skill[input].attribute:lower()
else
attribute = ''
end
attributeout = capitalFirst(attribute)
-- 4.2 IF ICON PAGE EXISTS
if iconPage.exists == true then
getIcon = require('Module:Data/Icon/dx2')
if input ~= '—' and activeSkill ~= '' and getIcon.icon[activeSkill] then
nameattribute = getIcon.icon[activeSkill] .. ' ' .. name .. namenote -- Set icon
elseif getIcon.icon[attribute] then -- Check if attribute is set in skill data
nameattribute = getIcon.icon[attribute] .. ' ' .. name .. namenote -- Set icon
else
nameattribute = name .. namenote .. '\n|style="text-align:center;"|' .. '[[' .. attributeout .. ']]'
end
end
-- 5 COST
if getSkill.skill[input].cost == nil then
cost = ''
elseif getSkill.skill[input].cost == '' or getSkill.skill[input].cost == '—' then
cost = '\n|style="text-align:center;"|' .. '—'
else
cost = '\n|style="text-align:center;"|' .. getSkill.skill[input].cost
end
-- 6 POWER
if getSkill.skill[input].pow == nil then
power = ''
elseif getSkill.skill[input].pow == '' or getSkill.skill[input].pow == '—' then
power = '\n|style="text-align:center;"|' .. '—'
else
power = '\n|style="text-align:center;"|' .. getSkill.skill[input].pow
end
-- 7 TARGET
if getSkill.skill[input].target_list == nil then
target = ''
elseif getSkill.skill[input].target_list == '' or getSkill.skill[input].target_list == '—' then
target = '\n|style="text-align:center;"|' .. '—'
else
target = '\n|style="text-align:center;"|' .. getSkill.skill[input].target_list
end
-- 10 FINAL OUTPUT
if activeSkill == '' then
local output = nameattribute .. cost .. power .. target .. '\n|-'
return output
else
else
nameattribute = '\n|style="text-align:center;"|' .. name .. namenote .. '\n|style="text-align:center;"|' .. '[[' .. attributeout .. ']]'
local output = nameattribute .. '\n|-'
return output
end
end
end
end
-- 5 COST
if getSkill.skill[input].cost == nil then
cost = ''
elseif getSkill.skill[input].cost == '' or getSkill.skill[input].cost == '—' then
cost = '\n|style="text-align:center;"|' .. '—'
else
cost = '\n|style="text-align:center;"|' .. getSkill.skill[input].cost
end
-- 6 POWER
if getSkill.skill[input].pow == nil then
power = ''
elseif getSkill.skill[input].pow == '' or getSkill.skill[input].pow == '—' then
power = '\n|style="text-align:center;"|' .. '—'
else
power = '\n|style="text-align:center;"|' .. getSkill.skill[input].pow
end
-- 7 TARGET
if getSkill.skill[input].target == nil then
target = ''
elseif getSkill.skill[input].target == '' or getSkill.skill[input].target == '—' then
target = '\n|style="text-align:center;"|' .. '—'
else
target = '\n|style="text-align:center;"|' .. getSkill.skill[input].target
end
-- 10 FINAL OUTPUT
local output = nameattribute .. cost .. power .. target .. '\n|-'
return output
end
end


return p
return p

Latest revision as of 04:32, 11 November 2024

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

local getArgument = require('Module:Arguments').getArgument

local p = {}

function capitalFirst(str) -- Allows capitalization of the first letter of each word in a string; adapted from (https://stackoverflow.com/questions/20284515/capitalize-first-letter-of-every-word-in-lua)
    return (str:gsub("(%l)(%w*)", function(a,b) return string.upper(a)..b end))
end

function p.Main(frame) 
	local args = frame.args
	local game = 'dx2'
	local input = args[1]:lower()
	local activeSkill = args[2]:lower()
	local getSkill = require('Module:Data/Skill/dx2')
	local iconPage = mw.title.makeTitle('Module', 'Data/Icon/dx2') -- Creates information about a given page

	if input == '—' then
		if activeSkill ~= '' then
			local output = "''No skill.''"
			return output
		else
			local output = "colspan=4|''No skill.''"
			return output
		end
	else
	-- 1 SKILL NAME
		if not getSkill.skill[input] then --Error message for invalid skill
			error("Skill \"" .. input .. "\" not defined for dx2")
		end
	-- 1.2 SKILL LINK
		if getSkill.skill[input] and getSkill.skill[input].link then -- Check if an alternate link for a page is set in skill data
			name = getSkill.skill[input].link .. '|' .. getSkill.skill[input].name 
		else	
			name = getSkill.skill[input].name
		end
	-- 3 NAME AND ATTRIBUTE
	-- 3.1 NAME NOTE
		if getSkill.skill[input] and getSkill.skill[input].name_note then
			namenote = frame:expandTemplate{ title = 'exp', args = { getSkill.skill[input].name_note } }
		else
			namenote = ''
		end
	-- 4.1 SET ATTRIBUTE OUTPUT
		if getSkill.skill[input].attribute then
			attribute = getSkill.skill[input].attribute:lower()
		else
			attribute = ''
		end
		attributeout = capitalFirst(attribute)
	-- 4.2 IF ICON PAGE EXISTS
		if iconPage.exists == true then
			getIcon = require('Module:Data/Icon/dx2')
			if input ~= '—' and activeSkill ~= '' and getIcon.icon[activeSkill] then
				nameattribute = getIcon.icon[activeSkill] .. ' ' .. name .. namenote -- Set icon
			elseif getIcon.icon[attribute] then -- Check if attribute is set in skill data
				nameattribute = getIcon.icon[attribute] .. ' ' .. name .. namenote -- Set icon
			else
				nameattribute = name .. namenote .. '\n|style="text-align:center;"|' .. '[[' .. attributeout .. ']]'
			end
		end
	-- 5 COST
		if getSkill.skill[input].cost == nil then
			cost = ''
		elseif getSkill.skill[input].cost == '' or getSkill.skill[input].cost == '—' then
			cost = '\n|style="text-align:center;"|' .. '—'
		else
			cost = '\n|style="text-align:center;"|' .. getSkill.skill[input].cost
		end
	-- 6 POWER
		if getSkill.skill[input].pow == nil then
			power = ''
		elseif getSkill.skill[input].pow == '' or getSkill.skill[input].pow == '—' then
			power = '\n|style="text-align:center;"|' .. '—'
		else
			power = '\n|style="text-align:center;"|' .. getSkill.skill[input].pow	
		end
	-- 7 TARGET
		if getSkill.skill[input].target_list == nil then
			target = ''
		elseif getSkill.skill[input].target_list == '' or getSkill.skill[input].target_list == '—' then
			target = '\n|style="text-align:center;"|' .. '—'
		else
			target = '\n|style="text-align:center;"|' .. getSkill.skill[input].target_list
		end
	-- 10 FINAL OUTPUT
		if activeSkill == '' then
			local output = nameattribute .. cost .. power .. target .. '\n|-'
			return output
		else
			local output = nameattribute .. '\n|-'
			return output
		end
	end
end

return p