Module:Sandbox
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Sandbox/doc
local getArgument = require('Module:Arguments').getArgument local p = {} -- 1 CELL STRUCTURE function format(s, c) local output = '' if c then output = output .. '|class="stat-' .. c .. '"' end output = output .. '|' .. s .. '\n' return output end -- 2 ATTRIBUTE FUNCTIONS -- 2.1 NAME function name(s) if s.name then local name = s.name return format(name) else error('"name" does not exist for given skill') end end -- 2.2 COST function cost(s) if s.cost then local cost if s.cost ~= '' or s.cost ~= '—' then local costtype = '' if s.costtype then costtype = ' ' .. s.costtype end cost = s.cost .. costtype else cost = '—' end return format(cost, 'cost') else return '' end end -- 2.3 RANGE function range(s) if s.range then local range = s.range return format(range) else return '' end end -- 2.4 DESCRIPTION function description(s) if s.description then local description = s.description return format(description, 'align-left') else return '' end end -- 2.5 LEVEL function level(s, a) local level if a[3] and a[3] ~= '-' then level = a[3] else level = 'Innate' end return format(level, 'level') end -- 2.6 RANK function rank(s, a) if a[3] then local rank = a[3] return format(rank, 'rank') else error('Rank/Inheritance value must be set using parameter 3') end end -- 2.7 INHERITANCE function inherit(s, a) if a[3] then local inherit if a[3]:lower() == 'y' then inherit = '<span style="color:lime;">✔</span>' else inherit = '<span style="color:red;">✘</span>' end return format(inherit, 'inherit') else error('Rank/Inheritance value must be set using parameter 3') end end -- 2.8 FUSION function fusion(s) if s.fusion then local fusion = s.fusion return format(fusion, 'fusion') else return '' end end -- 2.9 PREREQUISITE function prerequisite(s) if args[4] then local prerequisite = args[4] return format(prerequisite) else return '' end end -- 3 IMPLEMENTATION -- 3.1 INDEX TABLE local indexTable = { ['smt1'] = 1, ['mip'] = 3, ['p3'] = 2 } -- 3.2 TYPE TABLE local typeTable = { { -- 1 name, cost, description, level }, { -- 2 name, cost, description, level, fusion }, { -- 3 name, cost, range, description, rank, inherit }, } -- 3.3 MAIN FUNCTION function p.Main(frame) local args = frame.args local output = '' if args[1] then if args[2] then local skill = require('Module:Data/Skill/' .. args[1]:lower()).skill if skill[args[2]:lower()] then skill = skill[args[2]:lower()] local passTable = typeTable[indexTable[args[1]:lower()]] local i = 0 while i < #passTable do output = output .. passTable[i+1](skill, args) i = i + 1 end return output else error('The skill "' .. args[2]:lower() .. '" does not exist at Module:Data/Skill/' .. args[1]:lower()) end else error("No skill argument was passed") end else error("No arguments were passed") end end return p