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 writeTemplateLine(key, value) |
+ | if not key or not value then | ||
+ | return "" | ||
+ | end | ||
+ | local str = "" | ||
+ | str = str .. "| " .. key .. " = " .. value | ||
+ | return str | ||
+ | end | ||
+ | |||
+ | -- args: key in a key-value pair (nil if not a pair); value to display; number of extra rows used in the infobox thus far; infobox string thus far | ||
+ | -- return values: appended string, number of rows (now incremented by one), infobox string with new text appended | ||
+ | local function writeCustomDataLine(key, value, count, currentStr) | ||
+ | currentStr = currentStr or '' | ||
+ | count = count + 1 | ||
+ | local append = "" | ||
+ | |||
if key then | if key then | ||
− | + | append = writeTemplateLine("customlabel"..count, key) .. writeTemplateLine("customdata"..count, value) | |
− | |||
else | else | ||
− | + | append = writeTemplateLine("special"..count, value) | |
end | end | ||
− | + | currentStr = currentStr .. append | |
− | return | + | return append, count, currentStr |
end | end | ||
function weapon.getData(frame) | function weapon.getData(frame) | ||
if not frame then return '' end | if not frame then return '' end | ||
− | local weaponDefName = | + | local weaponDefName = frame.args[1] |
local wd = weaponData[weaponDefName] | local wd = weaponData[weaponDefName] | ||
if not (wd) then return 'weapondef ' .. weaponDefName .. ' not found' end | if not (wd) then return 'weapondef ' .. weaponDefName .. ' not found' end | ||
− | local property = | + | local property = frame.args[2] |
local result = wd[property] | local result = wd[property] | ||
if not result then result = '' end | if not result then result = '' end | ||
Line 25: | Line 39: | ||
end | end | ||
− | local function | + | function weapon.printInfobox(frame) |
− | local | + | local weaponDefName = frame.args[1] |
− | for index, entry in ipairs(wd.extraData | + | local expanded = frame.args[2] |
+ | if not (weaponData[weaponDefName]) then return 'weapondef ' .. weaponDefName .. ' not found' end | ||
+ | if expanded then return frame:expandTemplate({title = "User:Histidine/Autoinfobox zkweapon", args = {defname=weaponDefName}}) | ||
+ | else return [[{{User:Histidine/Autoinfobox zkweapon | ||
+ | |defname=]]..weaponDefName..[[}}]] end | ||
+ | end | ||
+ | |||
+ | function weapon.printInfoboxCustomRows(frame) | ||
+ | local weaponDefName = frame.args[1] | ||
+ | local wd = weaponData[weaponDefName] | ||
+ | if not wd then return 'weapondef ' .. weaponDefName .. ' not found' end | ||
+ | if not wd.extraData then return '' end | ||
+ | |||
+ | local str = '' | ||
+ | local count = 0 | ||
+ | for index, entry in ipairs(wd.extraData) do | ||
+ | local append = '' | ||
if type(entry) == 'table' then | if type(entry) == 'table' then | ||
if entry.type == 'shielddrain' then | if entry.type == 'shielddrain' then | ||
− | + | append, count, str = writeCustomDataLine("Shield drain (HP/shot)", entry.drain, count, str) | |
elseif entry.type == 'needs_link' then | elseif entry.type == 'needs_link' then | ||
− | + | append, count, str = writeCustomDataLine("Grid needed", entry.power, count, str) | |
elseif entry.type == 'spawn' then | elseif entry.type == 'spawn' then | ||
− | + | append, count, str = writeCustomDataLine("Spawns Unit", "[[" .. entry.name .. "]]", count, str) | |
− | + | append, count, str = writeCustomDataLine("Spawn Life (s)", entry.expire, count, str) | |
elseif entry.type == 'areadamage' then | elseif entry.type == 'areadamage' then | ||
local typeName = entry.grav and "Gravity Well" or "Ground Burn" | local typeName = entry.grav and "Gravity Well" or "Ground Burn" | ||
if not grav then | if not grav then | ||
− | + | append, count, str = writeCustomDataLine(typeName .. " DPS", entry.dps, count, str) | |
end | end | ||
− | + | append, count, str = writeCustomDataLine(typeName .. " radius (elmo)", entry.radius, count, str) | |
− | + | append, count, str = writeCustomDataLine(typeName .. " duration (s)", entry.duration, count, str) | |
elseif entry.type == 'stockpile' then | elseif entry.type == 'stockpile' then | ||
− | + | append, count, str = writeCustomDataLine("Stockpile time (s)", entry.time, count, str) | |
if (entry.cost) then | if (entry.cost) then | ||
− | + | append, count, str = writeCustomDataLine("Stockpile cost (M)", entry.cost, count, str) | |
end | end | ||
+ | else | ||
+ | append, count, str = writeCustomDataLine("Invalid table data", entry.type, count, str) | ||
end | end | ||
else | else | ||
if entry == 'hitscan' then | if entry == 'hitscan' then | ||
− | + | append, count, str = writeCustomDataLine(nil, "Instantly hits", count, str) | |
elseif entry == 'ignoreshield' then | elseif entry == 'ignoreshield' then | ||
− | + | append, count, str = writeCustomDataLine(nil, "Ignores shields", count, str) | |
elseif entry == 'smoothsground' then | elseif entry == 'smoothsground' then | ||
− | + | append, count, str = writeCustomDataLine(nil, "Smooths ground", count, str) | |
elseif entry == 'hightraj' then | elseif entry == 'hightraj' then | ||
− | + | append, count, str = writeCustomDataLine(nil, "High trajectory", count, str) | |
elseif entry == 'trajtoggle' then | elseif entry == 'trajtoggle' then | ||
− | + | append, count, str = writeCustomDataLine(nil, "Trajectory toggle", count, str) | |
elseif entry == 'watercapable' then | elseif entry == 'watercapable' then | ||
− | + | append, count, str = writeCustomDataLine(nil, "Water capable", count, str) | |
elseif entry == 'friendlyfire' then | elseif entry == 'friendlyfire' then | ||
− | + | append, count, str = writeCustomDataLine(nil, "Potential friendly fire", count, str) | |
elseif entry == 'nofriendlyfire' then | elseif entry == 'nofriendlyfire' then | ||
− | + | append, count, str = writeCustomDataLine(nil, "No friendly fire", count, str) | |
elseif entry == 'nogroundcollide' then | elseif entry == 'nogroundcollide' then | ||
− | + | append, count, str = writeCustomDataLine(nil, "Passes through ground", count, str) | |
elseif entry == 'piercing' then | elseif entry == 'piercing' then | ||
− | + | append, count, str = writeCustomDataLine(nil, "Damage increase vs large units", count, str) | |
elseif entry == 'damagefalloff' then | elseif entry == 'damagefalloff' then | ||
− | + | append, count, str = writeCustomDataLine(nil, "Damage falls off with range", count, str) | |
elseif entry == 'inaccuratevsmoving' then | elseif entry == 'inaccuratevsmoving' then | ||
− | + | append, count, str = writeCustomDataLine(nil, "Inaccuracy vs moving targets", count, str) | |
elseif entry == 'interceptedbyantinuke' then | elseif entry == 'interceptedbyantinuke' then | ||
− | + | append, count, str = writeCustomDataLine(nil, "Can be shot down by antinukes", count, str) | |
+ | else | ||
+ | append, count, str = writeCustomDataLine("Invalid tag data", entry, count, str) | ||
end | end | ||
end | end | ||
end | end | ||
− | + | return str or '' | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
return weapon | return weapon |