Module:Projectileinfo

local data = mw.loadData( 'Module:projectileinfo/data' ) -- loading data table.

local trim = mw.text.trim

-- cache local currentFrame -- helper function local getArg = function(key) local value = currentFrame.args[key] if not value then return nil end value = trim(value) if value == '' then return nil else return value end end

-- credit: http://richard.warburton.it -- this version is with trim. local function explode(div,str) if (div=='') then return false end local pos,arr = 0,{} -- for each divider found for st,sp in function return string.find(str,div,pos,true) end do		arr[#arr + 1] = trim(string.sub(str,pos,st-1)) -- Attach chars left of current divider pos = sp + 1 -- Jump past current divider end arr[#arr + 1] = trim(string.sub(str,pos)) -- Attach chars right of last divider return arr end

-- stat alias local statname = {} -- stat process function local proc = {}

local p = { -- for other module, get all stats, return as a table. getProjectileInfo = function(projectileid) local d = data[projectileid] local reset = data[0] if not d then projectileid = 0 d = reset end local result = {['type'] = projectileid} for k,v in pairs(reset) do			result[k] = d[k] or v		end return result end,

-- for template, get all stats, setting in dplvars. getInfo = function(frame) currentFrame = frame -- cache

local projectileid = tonumber(getArg('id')) or tonumber(getArg(1)) or 0 local prefix = getArg('prefix') or getArg(2) or '_projectileinfo_'

local d = data[projectileid] local reset = data[0] if not d then projectileid = 0 d = reset end local args = { prefix .. 'type', projectileid } for k,v in pairs(reset) do args[#args + 1] = prefix .. k			args[#args + 1] = d[k] or v 		end

frame:callParserFunction{ name = '#dplvar:set', args = args } end,

-- for other module, get single stat, return this stat directly getProjectileStat = function(projectileid, stat) local d = data[projectileid] local reset = data[0] if not d then projectileid = 0 d = reset end if stat == 'type' then return projectileid end return d[stat] or reset[stat] end,

-- for template, get single stat, return directly getStat = function(frame) currentFrame = frame -- cache

local projectileid = tonumber(getArg('id')) or tonumber(getArg(1)) or 0 local stat = getArg('stat') or getArg(2) if stat == 'count' then return 971 end if stat == 'extraupdates' then stat = 'extraUpdates' end

local d = data[projectileid] local reset = data[0] local raw if not d then projectileid = 0 d = reset end if stat == 'type' then raw = projectileid else raw = d[stat] or reset[stat] end return raw end, }

--alias p.getinfo = p.getInfo p.GetInfo = p.getInfo p.getstat = p.getStat p.GetStat = p.getStat

return p