Editing Module:UnitData
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 2: | Line 2: | ||
local unit = {} | local unit = {} | ||
local unitData = mw.loadData('Module:UnitData/data') | local unitData = mw.loadData('Module:UnitData/data') | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
function unit.getData(frame) | function unit.getData(frame) | ||
if not frame then return '' end | if not frame then return '' end | ||
− | + | local unitDefName = frame.args[1] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local ud = unitData[unitDefName] | local ud = unitData[unitDefName] | ||
− | + | if not (ud) then return 'unitdef ' .. unitDefName .. ' not found' end | |
− | + | local property = frame.args[2] | |
− | + | local result = ud[property] | |
− | + | if not result then result = '' end | |
− | + | return frame:preprocess(result) or '' | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
function unit.printWeaponInfoboxes(frame) | function unit.printWeaponInfoboxes(frame) | ||
if not frame then return '' end | if not frame then return '' end | ||
− | + | local unitDefName = frame.args[1] | |
local ud = unitData[unitDefName] | local ud = unitData[unitDefName] | ||
− | + | if not (ud) then return 'unitdef ' .. unitDefName .. ' not found' end | |
− | + | ||
− | + | local result = '' | |
local weaponModule = require('Module:WeaponData') | local weaponModule = require('Module:WeaponData') | ||
for index,weaponID in ipairs(ud.weaponIDs or {}) do | for index,weaponID in ipairs(ud.weaponIDs or {}) do | ||
− | local | + | local frame = {args = {weaponID}} |
− | result = result .. weaponModule.printInfobox | + | result = result .. weaponModule.printInfobox(frame) |
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | + | ||
− | + | if not result then result = '' end | |
− | + | return frame:preprocess(result) or '' | |
− | end | ||
− | |||
− | |||
− | |||
end | end | ||
return unit | return unit |