Módulo:Projectileinfo
Saltar para a navegação
Saltar para a pesquisa
result sample:
table#1 { ["aiStyle"] = 1, ["alpha"] = 0, ["arrow"] = true, ["bobber"] = false, ["coldDamage"] = false, ["counterweight"] = false, ["decidesManualFallThrough"] = false, ["extraUpdates"] = 0, ["friendly"] = true, ["glowMask"] = -1, ["height"] = 10, ["hide"] = false, ["hostile"] = false, ["idStaticNPCHitCooldown"] = -1, ["ignoreWater"] = false, ["internalName"] = "WoodenArrowFriendly", ["knockBack"] = 0, ["light"] = 0, ["localNPCHitCooldown"] = -2, ["magic"] = false, ["manualDirectionChange"] = false, ["melee"] = false, ["minion"] = false, ["minionSlots"] = 0, ["netImportant"] = false, ["noEnchantmentVisuals"] = false, ["noEnchantments"] = false, ["ownerHitCheck"] = false, ["penetrate"] = 1, ["ranged"] = true, ["scale"] = 1, ["sentry"] = false, ["tileCollide"] = true, ["timeLeft"] = 1200, ["trap"] = false, ["type"] = 1, ["usesIDStaticNPCImmunity"] = false, ["usesLocalNPCImmunity"] = false, ["width"] = 10, }
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 m = false
local projectileid = getArg('id') or getArg(1) or '0'
if string.sub(projectileid, 1, 1) == 'm' then
m = true
projectileid = string.sub(projectileid, 2)
end
projectileid = tonumber(projectileid)
if m then
projectileid = 'm'..projectileid
end
local stat = getArg('stat') or getArg(2)
if stat == 'count' then
return 1022
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