Editing Module:WeaponData
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 3: | Line 3: | ||
local weaponData = mw.loadData('Module:WeaponData/data') | local weaponData = mw.loadData('Module:WeaponData/data') | ||
− | local function | + | local function getMiscStatsTable(weaponDefName) |
− | if | + | local wd = weaponData[weaponDefName] |
− | + | if not wd then return nil end | |
− | + | if not wd.miscstats then return nil end | |
− | + | ||
− | + | local tbl = {} | |
+ | for index, tag in ipairs(wd.miscstats) do | ||
+ | tbl[tag] = true | ||
end | end | ||
− | + | return tbl | |
− | return | ||
end | end | ||
function weapon.getData(frame) | function weapon.getData(frame) | ||
if not frame then return '' end | if not frame then return '' end | ||
− | + | local weaponDefName = frame.args[1] | |
− | + | if not (weaponData[weaponDefName]) then return 'weapondef ' .. weaponDefName .. ' not found' end | |
− | + | local property = frame.args[2] | |
− | + | local result = weaponData[weaponDefName][property] | |
− | + | if not result then result = '' end | |
− | + | return frame:preprocess(result) or '' | |
− | |||
end | end | ||
− | + | function weapon.printInfobox(frame) | |
− | local | + | local weaponDefName = frame.args[1] |
− | + | if not (weaponData[weaponDefName]) then return 'weapondef ' .. weaponDefName .. ' not found' end | |
− | + | return [[{{User:Histidine/Autoinfobox zkweapon | |
− | + | |defname=]]..weaponDefName..[[}}]] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | function weapon. | + | function weapon.hasTag(frame) |
− | + | if not frame then return '' end | |
− | + | local weaponDefName = frame.args[1] | |
− | + | if not (weaponData[weaponDefName]) then return 'weapondef ' .. weaponDefName .. ' not found' end | |
− | + | local tag = frame.args[2] | |
− | |||
− | |||
− | + | local miscStats = getMiscStatsTable(weaponDefName) | |
− | + | if not miscStats then return false end | |
− | + | return miscStats[tag] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | if | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | end | ||
− | |||
− | |||
− | return | ||
end | end | ||
return weapon | return weapon |