User:Westgrass/sandbox

local data = mw.loadData( 'Module:iteminfo/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

local statname={ "acc" = "accessory", "autoreuse" = "autoReuse", "autoswing" = "autoReuse", "auto" = "autoReuse", "axe power" = "axe", "axepower" = "axe", "bait power" = "bait", "baitpower" = "bait", "body slot" = "bodySlot", "bodyslot" = "bodySlot", "buff duration" = "buffTime", "buff id" = "buffType", "buffduration" = "buffTime", "buffid" = "buffType", "bufftime" = "buffTime", "bufftype" = "buffType", "carttrack" = "cartTrack", "createtile" = "createTile", "createwall" = "createWall", "critical" = "crit", "dd2summon" = "DD2Summon", "dmg" = "damage", "fishing power" = "fishingPole", "fishingpole" = "fishingPole", "fishingpower" = "fishingPole", "fishing" = "fishingPole", "hair dye" = "hairDye", "hairdye" = "hairDye", "hammer power" = "hammer", "hammerpower" = "hammer", "head slot" = "headSlot", "headslot" = "headSlot", "heallife" = "healLife", "healmana" = "healMana", "holdstyle" = "holdStyle", "id" = "type", "internal name" = "internalName", "internalname" = "internalName", "item id" = "type", "itemid" = "type", "kb" = "knockBack", "knockback" = "knockBack", "leg slot" = "legSlot", "legslot" = "legSlot", "liferegen" = "lifeRegen", "makenpc" = "makeNPC", "maxstack" = "maxStack", "mount id" = "mountType", "mountid" = "mountType", "mounttype" = "mountType", "mount" = "mountType", "nomelee" = "noMelee", "notammo" = "notAmmo", "nousegraphic" = "noUseGraphic", "nowet" = "noWet", "pick power" = "pick", "pickpower" = "pick", "pickaxe power" = "pick", "pickaxepower" = "pick", "pickaxe" = "pick", "placestyle" = "placeStyle", "projectile id" = "shoot", "questitem" = "questItem", "range bonus" = "tileBoost", "rangebonus" = "tileBoost", "rarity" = "rare", "reusedelay" = "reuseDelay", "shootspeed" = "shootSpeed", "sound" = "UseSound", "sounduse" = "UseSound", "stack" = "maxStack", "stringcolor" = "stringColor", "tile id" = "createTile", "tile sub id" = "placeStyle", "tile subid" = "placeStyle", "tilesubid" = "placeStyle", "tile wand" = "tileWand", "tileboost" = "tileBoost", "tileid" = "createTile", "tilewand" = "tileWand", "tile" = "createTile", "tool speed" = "useTime", "toolspeed" = "useTime", "tooltip" = "ToolTip", "uniquestack" = "uniqueStack", "use delay" = "reuseDelay", "use sound" = "UseSound", "use style" = "useStyle", "use time" = "useAnimation", "useammo" = "useAmmo", "useanimation" = "useAnimation", "usedelay" = "reuseDelay", "usesound" = "UseSound", "usestyle" = "useStyle", "usetime" = "useAnimation", "useturn" = "useTurn", "use" = "useAnimation", "velocity" = "shootSpeed", "wall id" = "createWall", "wallid" = "createWall", "wall" = "createWall", "sell" = "value", --non-native stats: "buy" = "buyValue", "price" = "buyValue", "buffname" = "buffName", "buff name" = "buffName", "buff" = "buffName", }

---

local p = { -- for other module, get all stats, return as a table. getItemInfo = function(itemid) if itemid >= 3930 or itemid <= 0 then itemid = 0 end local d = data[itemid] local result = {['type'] = itemid} for k,v in pairs(data[0]) do			if d[k] ~= nil and d[k] ~= v then result[k] = d[k] else result[k] = v			end end return result end,

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

local itemid = tonumber(getArg('id')) or tonumber(getArg(1)) or 0 local prefix = getArg('prefix') or getArg(2) or '_iteminfo_'

if itemid >= 3930 or itemid <= 0 then itemid = 0 end local result = data[itemid] local args = { prefix .. 'type', itemid } for k,v in pairs(data[0]) do args[#args + 1] = prefix .. k			if result[k] ~= nil and result[k] ~= v then args[#args + 1] = result[k] else args[#args + 1] = v			end end

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

-- for other module, get single stat, return this stat directly getItemStat = function(itemid, stat) if itemid >= 3930 or itemid <= 0 then itemid = 0 end if stat == 'type' then return itemid end return data[itemid][stat] or data[0][stat] end,

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

local itemid = tonumber(getArg('id')) or tonumber(getArg(1)) or 0 local stat = getArg('stat') or getArg(2) stat = statname[stat] or stat

if not stat then return end

if itemid >= 3930 or itemid <= 0 then itemid = 0 end

local result if stat == 'type' then result = itemid else result = data[itemid][stat] or data[0][stat] or nil -- "or nil" will convert "false" to "nil" end

if getArg('raw') then return result end

end,

getStatInfo }

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

return p