Module:Item: Difference between revisions
From Growtopia
Jump to navigationJump to search
>NekoPillow No edit summary |
>NekoPillow No edit summary |
||
| Line 14: | Line 14: | ||
local function getSprite(file, pos, class) | local function getSprite(file, pos, tsize, rowlen, class) | ||
tsize = tsize or 32 | |||
rowlen = rowlen or 64 | |||
class = class or {} | |||
table.insert(class,"growsprite") | table.insert(class,"growsprite") | ||
return "<span class='"..table.concat(class," ").."'>"..mw.getCurrentFrame():preprocess("{{filepath:"..file.."}}"):gsub("?cb=.*$","/window-crop/width/"..tsize.."/x-offset/"..(pos%rowlen)*tsize.."/y-offset/"..math.floor(pos/rowlen)*tsize.."/window-width/"..tsize.."/window-height/"..tsize.."%0").."</span>" | return "<span class='"..table.concat(class," ").."'>"..mw.getCurrentFrame():preprocess("{{filepath:"..file.."}}"):gsub("?cb=.*$","/window-crop/width/"..tsize.."/x-offset/"..(pos%rowlen)*tsize.."/y-offset/"..math.floor(pos/rowlen)*tsize.."/window-width/"..tsize.."/window-height/"..tsize.."%0").."</span>" | ||
end | |||
local function getItemSprite(data) | |||
local class = {} | |||
local pos = data[1] | |||
if(data[2] == 19) then return getSeedSprite(data) end | |||
return getSprite("ItemSprites.png",pos,32,false,class) | |||
end | |||
local function getSeedSprite(data) | |||
local pos = data[1] | |||
return getSprite("SeedSprites.png",pos,16) | |||
end | |||
local function getItemSpriteByName(name) | |||
return getItemSprite(getItemData(md5.md5(name))) | |||
end | end | ||
function item.SpriteByName(frame) | function item.SpriteByName(frame) | ||
return getItemSpriteByName(frame.args[1]) | |||
end | end | ||
local function in_array(h,a) | |||
for k,v in ipairs(a) do if v == h then return true end end return false | |||
end | |||
local function addCategory(t,n) | local function addCategory(t,n) | ||
table.insert(t,"[".."[Category:"..n.."]]") | table.insert(t,"[".."[Category:"..n.."]]") | ||
| Line 41: | Line 57: | ||
local s = {} | local s = {} | ||
if(d[2] == -1) then | if(d[2] == -1 or d[2] == 19) then | ||
table.insert(s,"<div><b style='color: #F00'>Invalid Item</b></div>") | table.insert(s,"<div><b style='color: #F00'>Invalid Item</b></div>") | ||
if(mw.title.getCurrentTitle().nsText=="") then | if(mw.title.getCurrentTitle().nsText=="") then | ||
| Line 53: | Line 69: | ||
table.insert(s,"__NOTOC__<div class='iteminfobox'>") | table.insert(s,"__NOTOC__<div class='iteminfobox'>") | ||
table.insert(s,"<div class='header'><h3>") | table.insert(s,"<div class='header'><h3>") | ||
table.insert(s,getItemSprite(d)) | |||
table.insert(s,getItemSprite( | |||
table.insert(s," <b class='s_name'>"..name) | table.insert(s," <b class='s_name'>"..name) | ||
if(d[3]<999) then | |||
table.insert(s," <small class='s_rarity'>(Rarity: "..d[ | table.insert(s," <small class='s_rarity'>(Rarity: "..d[3]..")</small>") | ||
end | end | ||
table.insert(s,"</b></h3><span></span></div>") | table.insert(s,"</b></h3><span></span></div>") | ||
-------------------- | |||
table.insert(s,"<div class='sect_text'>") | table.insert(s,"<div class='sect_text'>") | ||
if((frame.args[1] or ""):len()>0) then | if((frame.args[1] or ""):len()>0) then | ||
| Line 74: | Line 85: | ||
end | end | ||
table.insert(s,"</div>") | table.insert(s,"</div>") | ||
-------------------- | |||
table.insert(s,"<b class='sect_title'>Properties</b>") | table.insert(s,"<b class='sect_title'>Properties</b>") | ||
table.insert(s,"<div class='sect_text'>") | table.insert(s,"<div class='sect_text'>") | ||
local l = {} | local l = {} | ||
if((d[ | if((d[4]/1)%2>=1) then | ||
table.insert(l,"This item can be placed in two directions, depending on the direction you're facing.") end | table.insert(l,"This item can be placed in two directions, depending on the direction you're facing.") end | ||
if((d[ | if((d[4]/2)%2>=1) then | ||
table.insert(l,"This item has special properties you can adjust with the Wrench.") end | table.insert(l,"This item has special properties you can adjust with the Wrench.") end | ||
if((d[ | if((d[4]/4)%2>=1) then | ||
table.insert(l,"This item never drops any seeds.") end | table.insert(l,"This item never drops any seeds.") end | ||
if((d[ | if((d[4]/32)%2>=1) then | ||
if(d[2]==20) then table.insert(l,"This item can kill zombies during a Pandemic!") | if(d[2]==20) then table.insert(l,"This item can kill zombies during a Pandemic!") | ||
else table.insert(l,"This item can't be used on yourself.") end | else table.insert(l,"This item can't be used on yourself.") end | ||
end | end | ||
if((d[ | if((d[4]/128)%2>=1) then | ||
table.insert(l,"This item can only be used in World-Locked worlds.") end | table.insert(l,"This item can only be used in World-Locked worlds.") end | ||
if((d[ | if((d[4]/512)%2>=1) then | ||
table.insert(l,"This item can't be destroyed - smashing it will return it to your backpack if you have room!") | table.insert(l,"This item can't be destroyed - smashing it will return it to your backpack if you have room!") | ||
end | end | ||
if((d[ | if((d[4]/2048)%2>=1) then | ||
table.insert(l,"A tree of this type can bear surprising fruit!") end | table.insert(l,"A tree of this type can bear surprising fruit!") end | ||
if((d[ | if((d[4]/4096)%2>=1) then | ||
table.insert(l,"This item is PUBLIC: Even if it's locked, anyone can smash it.") end | table.insert(l,"This item is PUBLIC: Even if it's locked, anyone can smash it.") end | ||
if((d[ | if((d[4]/16384)%2>=1) then | ||
if(id==3762) then table.insert(l,"This item can only be created during SummerFest!") | if(id==3762) then table.insert(l,"This item can only be created during SummerFest!") | ||
else table.insert(l,"This item can only be created during WinterFest!") end | else table.insert(l,"This item can only be created during WinterFest!") end | ||
end | end | ||
if((d[ | if((d[4]/32768)%2>=1) then | ||
table.insert(l,"This item cannot be dropped or traded.") end | table.insert(l,"This item cannot be dropped or traded.") end | ||
if(d[2]==3) then | if(d[2]==3) then | ||
| Line 112: | Line 123: | ||
if(d[2]==107) then | if(d[2]==107) then | ||
table.insert(l,"This item can be upgraded.") end | table.insert(l,"This item can be upgraded.") end | ||
if(#l==0) then table.insert(s,"None") | if(#l==0) then table.insert(s,"None") | ||
else table.insert(s,table.concat(l,"<br>")) end | else table.insert(s,table.concat(l,"<br>")) end | ||
table.insert(s,"</div>") | table.insert(s,"</div>") | ||
-------------------- | |||
table.insert(s,"<b class='sect_title'>Data</b>") | table.insert(s,"<b class='sect_title'>Data</b>") | ||
table.insert(s,"<table class='sect_text'>") | table.insert(s,"<table class='sect_text'>") | ||
table.insert(s,"<tr><th>Type</th><td>") | table.insert(s,"<tr><th>Type</th><td>") | ||
local ca = getItemType("category",d[2]) | local ca = getItemType("category",d[2]) | ||
if(d[2]==20) then ca = getItemType("clothingType",d[ | if(d[2]==20) then ca = getItemType("clothingType",d[8]) end | ||
if(not ca[1]) then table.insert(s,getItemSpriteByName("Blank").." <i class='warning'>Unknown ("..d[2]..")</i>") | if(not ca[1]) then table.insert(s,getItemSpriteByName("Blank").." <i class='warning'>Unknown ("..d[2]..")</i>") | ||
else | else | ||
| Line 128: | Line 140: | ||
if(#ca[2] > 0) then table.insert(s,"<br><small class='desc'>"..ca[2].."</small>") end | if(#ca[2] > 0) then table.insert(s,"<br><small class='desc'>"..ca[2].."</small>") end | ||
end | end | ||
table.insert(s,"</td></tr><tr><th>Chi</th><td>") | table.insert(s,"</td></tr><tr><th>Chi</th><td>") | ||
local chi_uc = mw.getContentLanguage():ucfirst((frame.args[2] or ""):lower()) | local chi_uc = mw.getContentLanguage():ucfirst((frame.args[2] or ""):lower()) | ||
if(chi_uc == "None" or in_array(d[2],{20,107})) then | if(chi_uc == "None" or in_array(d[2],{20,107})) then | ||
table.insert(s,"None") | table.insert(s,"None") | ||
elseif(chi_uc | elseif(in_array(chi_uc,{"Fire","Water","Earth","Wind"})) then | ||
table.insert(s,getItemSpriteByName("Element - "..chi_uc).." "..chi_uc) | table.insert(s,getItemSpriteByName("Element - "..chi_uc).." "..chi_uc) | ||
addCategory(c,"Chi - "..chi_uc) | addCategory(c,"Chi - "..chi_uc) | ||
| Line 140: | Line 152: | ||
addCategory(c,"Missing Chi") | addCategory(c,"Missing Chi") | ||
end | end | ||
table.insert(s,"</td></tr><tr><th>Texture Type</th><td>") | table.insert(s,"</td></tr><tr><th>Texture Type</th><td>") | ||
local tt = getItemType("textureType",d[ | local tt = getItemType("textureType",d[5]) | ||
table.insert(s,getSprite("TextureTypeSprite.png" | table.insert(s,getSprite("TextureTypeSprite.png", d[5], 32, 8).." "..(tt[1] or "<i class='warning'>Unknown</i>")) | ||
table.insert(s,"</td></tr><tr><th>Collision Type</th><td>") | table.insert(s,"</td></tr><tr><th>Collision Type</th><td>") | ||
local ct = getItemType("collisionType",d[ | local ct = getItemType("collisionType",d[7]) | ||
table.insert(s,getSprite("CollisionTypeSprite.png" | table.insert(s,getSprite("CollisionTypeSprite.png", d[7], 32, 8).." "..(ct[1] or "<i class='warning'>Unknown</i>")) | ||
table.insert(s,"</td></tr><tr><th>Hardness</th><td>"..getItemSpriteByName("Fist").." ") | table.insert(s,"</td></tr><tr><th>Hardness</th><td>"..getItemSpriteByName("Fist").." ") | ||
table.insert(s,math.ceil(d[ | table.insert(s,math.ceil(d[9]/6).." Hits<br>"..getItemSpriteByName("Pickaxe").." ") | ||
table.insert(s,math.ceil(d[ | table.insert(s,math.ceil(d[9]/8).." Hits<br><small>Restores after <b>"..d[10].."s</b>") | ||
table.insert(s," of inactivity.</small></td></tr>") | table.insert(s," of inactivity.</small></td></tr>") | ||
table.insert(s,"<tr><th>Seed Color</th><td class='seedColor'>"..getSeedSprite( | table.insert(s,"<tr><th>Seed Color</th><td class='seedColor'>"..getSeedSprite(d).." <div>") | ||
table.insert(s,"<span style='background:"..d[ | table.insert(s,"<span style='background:"..d[11].."'></span> "..d[11].."<br>") | ||
table.insert(s,"<span style='background:"..d[ | table.insert(s,"<span style='background:"..d[12].."'></span> "..d[12].."</div></td></tr>") | ||
table.insert(s,"<tr><th>Grow Time</th><td>"..getTreeSprite(pos).." ") | table.insert(s,"<tr><th>Grow Time</th><td>"..getTreeSprite(pos).." ") | ||
if(d[ | if(d[13]>=604800) then table.insert(s,math.floor(d[13]/604800).."w ") end | ||
if(d[ | if(d[13]>=86400) then table.insert(s,math.floor(d[13]%604800/86400).."d ") end | ||
if(d[ | if(d[13]>=3600) then table.insert(s,math.floor(d[13]%86400/3600).."h ") end | ||
if(d[ | if(d[13]>=60) then table.insert(s,math.floor(d[13]%3600/60).."m ") end | ||
table.insert(s,(d[ | table.insert(s,(d[13]%60).."s</td></tr>") | ||
table.insert(s,"<tr><th>Default Gems Drop</th><td>"..getItemSpriteByName("Gems").." ") | table.insert(s,"<tr><th>Default Gems Drop</th><td>"..getItemSpriteByName("Gems").." ") | ||
if(d[ | if(d[3]==999) then table.insert(s,"N/A".."</td></tr>") | ||
else | else | ||
if(d[ | if(d[3]>30) then table.insert(s,"0 - "..math.floor(d[3]/4+1).."</td></tr>") | ||
elseif(d[ | elseif(d[3]>=8) then table.insert(s,"0 - "..math.floor(math.floor(d[3]/4)*0.75+1).."</td></tr>") | ||
else table.insert(s,"0 - 1".."</td></tr>") end | else table.insert(s,"0 - 1".."</td></tr>") end | ||
end | end | ||
table.insert(s,"</table>") | table.insert(s,"</table>") | ||
table.insert(s,"</div>") | table.insert(s,"</div>") | ||
| Line 178: | Line 192: | ||
if(d[2]==20) then | if(d[2]==20) then | ||
addCategory(c,"Clothes") | addCategory(c,"Clothes") | ||
addCategory(c,getItemType("clothingType",d[ | addCategory(c,getItemType("clothingType",d[8])[1].." (Clothes)") | ||
end | end | ||
Revision as of 15:01, 14 August 2019
Documentation for this module may be created at Module:Item/doc
local item = {}
local md5 = require('Module:Md5')
local function getItemData(hash)
local a = mw.loadData('Module:Item/Data')
return a[hash] or {0, -1}
end
local function getItemType(name,id)
local a = mw.loadData('Module:Item/Type')
return (a[name] or {})[id] or {}
end
local function getSprite(file, pos, tsize, rowlen, class)
tsize = tsize or 32
rowlen = rowlen or 64
class = class or {}
table.insert(class,"growsprite")
return "<span class='"..table.concat(class," ").."'>"..mw.getCurrentFrame():preprocess("{{filepath:"..file.."}}"):gsub("?cb=.*$","/window-crop/width/"..tsize.."/x-offset/"..(pos%rowlen)*tsize.."/y-offset/"..math.floor(pos/rowlen)*tsize.."/window-width/"..tsize.."/window-height/"..tsize.."%0").."</span>"
end
local function getItemSprite(data)
local class = {}
local pos = data[1]
if(data[2] == 19) then return getSeedSprite(data) end
return getSprite("ItemSprites.png",pos,32,false,class)
end
local function getSeedSprite(data)
local pos = data[1]
return getSprite("SeedSprites.png",pos,16)
end
local function getItemSpriteByName(name)
return getItemSprite(getItemData(md5.md5(name)))
end
function item.SpriteByName(frame)
return getItemSpriteByName(frame.args[1])
end
local function in_array(h,a)
for k,v in ipairs(a) do if v == h then return true end end return false
end
local function addCategory(t,n)
table.insert(t,"[".."[Category:"..n.."]]")
end
function item.Infobox(frame)
local name = frame.args["name"] or mw.title.getCurrentTitle().text
local d = getItemData(md5.md5(name))
local s = {}
if(d[2] == -1 or d[2] == 19) then
table.insert(s,"<div><b style='color: #F00'>Invalid Item</b></div>")
if(mw.title.getCurrentTitle().nsText=="") then
addCategory(s,"Invalid Item")
end
return table.concat(s)
end
local c = {}
addCategory(c,"Item")
table.insert(s,"__NOTOC__<div class='iteminfobox'>")
table.insert(s,"<div class='header'><h3>")
table.insert(s,getItemSprite(d))
table.insert(s," <b class='s_name'>"..name)
if(d[3]<999) then
table.insert(s," <small class='s_rarity'>(Rarity: "..d[3]..")</small>")
end
table.insert(s,"</b></h3><span></span></div>")
--------------------
table.insert(s,"<div class='sect_text'>")
if((frame.args[1] or ""):len()>0) then
if(d[2]==64) then table.insert(s,"This is a 1 lb. "..name..". ") end
table.insert(s,frame.args[1])
else
table.insert(s,"<i class='warning'>Description missing.</i>")
addCategory(c,"Missing Description")
end
table.insert(s,"</div>")
--------------------
table.insert(s,"<b class='sect_title'>Properties</b>")
table.insert(s,"<div class='sect_text'>")
local l = {}
if((d[4]/1)%2>=1) then
table.insert(l,"This item can be placed in two directions, depending on the direction you're facing.") end
if((d[4]/2)%2>=1) then
table.insert(l,"This item has special properties you can adjust with the Wrench.") end
if((d[4]/4)%2>=1) then
table.insert(l,"This item never drops any seeds.") end
if((d[4]/32)%2>=1) then
if(d[2]==20) then table.insert(l,"This item can kill zombies during a Pandemic!")
else table.insert(l,"This item can't be used on yourself.") end
end
if((d[4]/128)%2>=1) then
table.insert(l,"This item can only be used in World-Locked worlds.") end
if((d[4]/512)%2>=1) then
table.insert(l,"This item can't be destroyed - smashing it will return it to your backpack if you have room!")
end
if((d[4]/2048)%2>=1) then
table.insert(l,"A tree of this type can bear surprising fruit!") end
if((d[4]/4096)%2>=1) then
table.insert(l,"This item is PUBLIC: Even if it's locked, anyone can smash it.") end
if((d[4]/16384)%2>=1) then
if(id==3762) then table.insert(l,"This item can only be created during SummerFest!")
else table.insert(l,"This item can only be created during WinterFest!") end
end
if((d[4]/32768)%2>=1) then
table.insert(l,"This item cannot be dropped or traded.") end
if(d[2]==3) then
table.insert(l,"A lock makes it so only you (and designated friends) can edit an area.") end
if(d[2]==37 or d[2]==114) then
table.insert(l,"This item has no use... by itself.") end
if(d[2]==64) then
table.insert(l,"This is a fish. It can only be placed in a Fish Tank. You can't divide fish into pieces.") end
if(d[2]==107) then
table.insert(l,"This item can be upgraded.") end
if(#l==0) then table.insert(s,"None")
else table.insert(s,table.concat(l,"<br>")) end
table.insert(s,"</div>")
--------------------
table.insert(s,"<b class='sect_title'>Data</b>")
table.insert(s,"<table class='sect_text'>")
table.insert(s,"<tr><th>Type</th><td>")
local ca = getItemType("category",d[2])
if(d[2]==20) then ca = getItemType("clothingType",d[8]) end
if(not ca[1]) then table.insert(s,getItemSpriteByName("Blank").." <i class='warning'>Unknown ("..d[2]..")</i>")
else
table.insert(s,getItemSpriteByName(ca[3]).." "..ca[1])
if(ca[4] ~= false) then table.insert(s,"<small> - "..ca[4].."</small>") end
if(#ca[2] > 0) then table.insert(s,"<br><small class='desc'>"..ca[2].."</small>") end
end
table.insert(s,"</td></tr><tr><th>Chi</th><td>")
local chi_uc = mw.getContentLanguage():ucfirst((frame.args[2] or ""):lower())
if(chi_uc == "None" or in_array(d[2],{20,107})) then
table.insert(s,"None")
elseif(in_array(chi_uc,{"Fire","Water","Earth","Wind"})) then
table.insert(s,getItemSpriteByName("Element - "..chi_uc).." "..chi_uc)
addCategory(c,"Chi - "..chi_uc)
else
table.insert(s,"<i class='warning'>Unknown</i>")
addCategory(c,"Missing Chi")
end
table.insert(s,"</td></tr><tr><th>Texture Type</th><td>")
local tt = getItemType("textureType",d[5])
table.insert(s,getSprite("TextureTypeSprite.png", d[5], 32, 8).." "..(tt[1] or "<i class='warning'>Unknown</i>"))
table.insert(s,"</td></tr><tr><th>Collision Type</th><td>")
local ct = getItemType("collisionType",d[7])
table.insert(s,getSprite("CollisionTypeSprite.png", d[7], 32, 8).." "..(ct[1] or "<i class='warning'>Unknown</i>"))
table.insert(s,"</td></tr><tr><th>Hardness</th><td>"..getItemSpriteByName("Fist").." ")
table.insert(s,math.ceil(d[9]/6).." Hits<br>"..getItemSpriteByName("Pickaxe").." ")
table.insert(s,math.ceil(d[9]/8).." Hits<br><small>Restores after <b>"..d[10].."s</b>")
table.insert(s," of inactivity.</small></td></tr>")
table.insert(s,"<tr><th>Seed Color</th><td class='seedColor'>"..getSeedSprite(d).." <div>")
table.insert(s,"<span style='background:"..d[11].."'></span> "..d[11].."<br>")
table.insert(s,"<span style='background:"..d[12].."'></span> "..d[12].."</div></td></tr>")
table.insert(s,"<tr><th>Grow Time</th><td>"..getTreeSprite(pos).." ")
if(d[13]>=604800) then table.insert(s,math.floor(d[13]/604800).."w ") end
if(d[13]>=86400) then table.insert(s,math.floor(d[13]%604800/86400).."d ") end
if(d[13]>=3600) then table.insert(s,math.floor(d[13]%86400/3600).."h ") end
if(d[13]>=60) then table.insert(s,math.floor(d[13]%3600/60).."m ") end
table.insert(s,(d[13]%60).."s</td></tr>")
table.insert(s,"<tr><th>Default Gems Drop</th><td>"..getItemSpriteByName("Gems").." ")
if(d[3]==999) then table.insert(s,"N/A".."</td></tr>")
else
if(d[3]>30) then table.insert(s,"0 - "..math.floor(d[3]/4+1).."</td></tr>")
elseif(d[3]>=8) then table.insert(s,"0 - "..math.floor(math.floor(d[3]/4)*0.75+1).."</td></tr>")
else table.insert(s,"0 - 1".."</td></tr>") end
end
table.insert(s,"</table>")
table.insert(s,"</div>")
----- [Handle Category] -----
if(d[2]==20) then
addCategory(c,"Clothes")
addCategory(c,getItemType("clothingType",d[8])[1].." (Clothes)")
end
if(mw.title.getCurrentTitle().nsText=="") then
table.insert(s,table.concat(c))
end
return table.concat(s)
end
return item