(Added popup functionality) |
mNo edit summary |
||
Line 378: | Line 378: | ||
]]) |
]]) |
||
− | + | div:wikitext(p.stats(frame)) |
|
div = div:done() |
div = div:done() |
||
Line 435: | Line 435: | ||
div = div:wikitext("<br />") |
div = div:wikitext("<br />") |
||
− | return tostring( |
+ | return tostring(div) |
end |
end |
||
Revision as of 19:12, 13 July 2020
This module can display item information in a fashion similar to the way it is done in the game. Specifically, it aims to replace the old wikitext templates Template:Item and Template:Stats. The main difference is that this module does not require the user to provide all item information when invoking the module on a page. Instead, the module pulls item information from a database.
This way, the module only requires a single parameter to add an item to a page - the item name. A big advantage of this is that a single item can be added to several different pages all over the wiki with minimal effort.
However, it remains necessary to add item information to the database if it is not yet present. This may be unintuitive to users that have no prior experience with programming, as the database is more of a hack using Lua tables rather than a proper database in the truest sense of the word. Still, the documentation on the database page aims to make adding new items easy even for newcomers.
Usage
{{#invoke:Item|stats|[item name]}}
has the functionality of the old Stats template. It displays a flat view of the item stats.
{{#invoke:Item|item|[item name]}}
has the functionality of the old Item template. It displays an image of the item along with the item name and how to obtain the item. The info from {{#invoke:Item|stats|[item name]}}
is added as a pop-up, same as in the inventory in the game.
Samples
{{#invoke:Item|stats|DEMO_Sturdy Stick}}
Lua error at line 8: attempt to index field '?' (a nil value).
{{#invoke:Item|item|DEMO_Sturdy Stick}}
Lua error at line 357: attempt to index field '?' (a nil value).
local p = {}
local data = mw.loadData("Module:Database")
function p.stats(frame)
item = frame.args[1]
local div = mw.html.create( 'div' )
if data[item]["Book"] then
div:addClass("stats")
div:addClass("p-killer")
div:cssText([[
display: inline-block;
width: fit-content;
height: auto;
visibility: visible;
color: #262119;
user-select: none;
padding: 2px !important;
background-color: #dbbb83;
border: 2px solid #262119;
border-radius: 2px;
font-size: 14px;
font-family: Fira Sans Condensed;
font-weight: 700;
margin: 0px !important;
]])
div = div:tag("p")
div:cssText([[
text-align: left;
font-size: 16px;
font-weight: 800;
margin: 0px;
padding: 0px;
line-height: 16px;
]])
rotb = data[item]["Rarity of the book"]
if rotb=="u" then div:wikitext('<span style="color: #1A800D">')
elseif rotb=="r" then div:wikitext('<span style="color: #1252B3">')
elseif rotb=="e" then div:wikitext('<span style="color: #B814CC">')
elseif rotb=="l" then div:wikitext('<span style="color: #CC1414">') end
div:wikitext("Book: ")
if data[item]["Type of the book"] then div:wikitext("Gather") end
div:wikitext(data[item]["Name"])
div:wikitext("<br />")
if rotb~="c" then div:wikitext("</span>") end
rotb = nil
div = div:done()
div = div:tag("p")
div:cssText([[
text-align: right;
opacity: 0.5;
margin: 0px;
padding: 0px;
]])
div:wikitext('<span style="float:left;">')
if data[item]["Binding of the book"]==1 then div:wikitext("Binds on use")
elseif data[item]["Binding of the book"]==2 then div:wikitext("Binds on pickup") end
div:wikitext("<br />")
div:wikitext("</span> SkillBook")
div = div:done()
div:tag("p")
div:cssText([[
text-align: left;
margin: 0px;
padding: 0px;
]])
if data[item]["Type of the book"]=="gather" then div:wikitext("Teaches you to gather:<br />")
else div:wikitext("Learn to craft:<br />") end
div = div:done()
div = div:tag("div")
end
div:addClass("stats")
div:addClass("p-killer")
div:cssText([[
display: inline-block;
width: fit-content;
height: auto;
visibility: visible;
color: #262119;
user-select: none;
padding: 2px;
background-color: #dbbb83;
border: 2px solid #262119;
border-radius: 3px;
font-size: 14px;
font-family: Fira Sans Condensed;
font-weight: 700;
margin:0px;
]])
div = div:tag("p")
div:cssText([[
text-align: right;
font-size: 16px;
font-weight: 800;
margin: 0px;
padding: 0px;
line-height: 16px;
margin-bottom: 3px;
]])
div:wikitext('<span style="margin-left:1ex;">')
points = data[item]["Points"]
if points=="death" then
points = '<span class="stein-tooltip-item-damage-point stein-tooltip-item-damage-point-death"></span>'
elseif points=="earth" then
points = '<span class="stein-tooltip-item-damage-point stein-tooltip-item-damage-point-earth"></span>'
elseif points=="fire" then
points = '<span class="stein-tooltip-item-damage-point stein-tooltip-item-damage-point-fire"></span>'
elseif points=="holy" then
points = '<span class="stein-tooltip-item-damage-point stein-tooltip-item-damage-point-holy"></span>'
elseif points=="physical" then
points = '<span class="stein-tooltip-item-damage-point stein-tooltip-item-damage-point-physical"></span>'
elseif points=="soul" then
points = '<span class="stein-tooltip-item-damage-point stein-tooltip-item-damage-point-soul"></span>'
elseif points=="water" then
points = '<span class="stein-tooltip-item-damage-point stein-tooltip-item-damage-point-water"></span>'
elseif points=="truedamage" then
points = '<span class="stein-tooltip-item-damage-point stein-tooltip-item-damage-point-truedamage"></span>' end
n = tonumber(data[item]["Amount of points"])
while n and n > 0 do
div:wikitext(points)
n = n - 1
end
points = nil
n = nil
div:wikitext("</span>")
div = div:tag("span")
div:css("float", "left")
rarity = data[item]["Rarity"]
if rarity=="u" then div:css("color", "#1A800D")
elseif rarity=="r" then div:css("color", "#1252B3")
elseif rarity=="e" then div:css("color", "#B814CC")
elseif rarity=="l" then div:css("color", "#CC1414") end
div:wikitext(data[item]["Name"])
div:wikitext("<br />")
div = div:done()
div = div:done()
div = div:tag("p")
div:cssText([[
text-align: right;
opacity: 0.5;
margin: 0px;
padding: 0px
]])
div:wikitext('<span style="float:left; margin-right:1ex;">')
if data[item]["Binding"]==1 then div:wikitext("Binds on use")
elseif data[item]["Binding"]==2 then div:wikitext("Binds on pickup") end
div:wikitext("<br />")
div:wikitext("</span>")
div:wikitext(data[item]["Category"])
div = div:done()
div = div:tag("p")
div:cssText([[
text-align: left;
margin: 0px;
padding: 0px;
]])
div:wikitext(data[item]["Function"])
div = div:done()
div = div:tag("p")
div:cssText([[
text-align: left;
margin: 0px;
padding: 0px;
]])
div:wikitext('<span style="float:right; margin-left: 5px;">')
if data[item]["Energy usage"] then
div:wikitext(data[item]["Energy usage"])
div:wikitext(" Energy")
div:wikitext("<br />")
end
if data[item]["Mana usage"] then
div:wikitext(data[item]["Mana usage"])
div:wikitext(" Mana")
div:wikitext("<br />")
end
div:wikitext("</span>")
if data[item]["Casttime"] then
div:wikitext("Casttime: ")
div:wikitext(data[item]["Casttime"])
div:wikitext(" sec")
div:wikitext("<br />")
end
div = div:done()
div = div:tag("p")
div:cssText([[
text-align: left;
margin: 0px;
padding: 0px;
]])
div:wikitext('<span style="float:right; margin-left: 5px;">')
if data[item]["Range"] then
div:wikitext("Range ")
div:wikitext(data[item]["Range"])
div:wikitext("<br />")
end
div:wikitext("</span>")
if data[item]["Cooldown"] then
div:wikitext("Cooldown: ")
div:wikitext(data[item]["Cooldown"])
div:wikitext(" sec")
div:wikitext("<br />")
end
div = div:done()
div = div:tag("p")
div:cssText([[
text-align: left;
margin: 0px;
padding: 0px;
]])
if data[item]["Armor"] then div:wikitext("+"..data[item]["Armor"].." Armor<br />") end
if data[item]["Cooldown Reduction Rating"] then div:wikitext("+"..data[item]["Cooldown Reduction Rating"].." Cooldown Reduction Rating<br />") end
if data[item]["Critical Bonus Rating"] then div:wikitext("+"..data[item]["Critical Bonus Rating"].." Critical Bonus Rating<br />") end
if data[item]["Critical Chance Rating"] then div:wikitext("+"..data[item]["Critical Chance Rating"].." Critical Chance Rating<br />") end
if data[item]["Death Damage"] then div:wikitext("+"..data[item]["Death Damage"].." Death Damage<br />") end
if data[item]["Energy Regeneration"] then div:wikitext("+"..data[item]["Energy Regeneration"].." Energy Regeneration<br />") end
if data[item]["Fire Damage"] then div:wikitext("+"..data[item]["Fire Damage"].." Fire Damage<br />") end
if data[item]["Heal"] then div:wikitext("+"..data[item]["Heal"].." Heal<br />") end
if data[item]["Life"] then div:wikitext("+"..data[item]["Life"].." Life<br />") end
if data[item]["Life Regeneration"] then div:wikitext("+"..data[item]["Life Regeneration"].." Life Regeneration<br />") end
if data[item]["Magic Damage"] then div:wikitext("+"..data[item]["Magic Damage"].." Magic Damage<br />") end
if data[item]["Mana"] then div:wikitext("+"..data[item]["Mana"].." Mana<br />") end
if data[item]["Mana Regeneration"] then div:wikitext("+"..data[item]["Mana Regeneration"].." Mana Regeneration<br />") end
if data[item]["Physical Damage"] then div:wikitext("+"..data[item]["Physical Damage"].." Physical Damage<br />") end
if data[item]["Threat"] then div:wikitext("+"..data[item]["Threat"].."% Threat<br />") end
if data[item]["Water Damage"] then div:wikitext("+"..data[item]["Water Damage"].." Water Damage<br />") end
div = div:done()
div = div:tag("p")
div:cssText([[
text-align:left;
opacity:0.5;
font-style:italic;
margin:0px;
padding:0px;
]])
if data[item]["Flavor text"] then
div:wikitext('"'..data[item]["Flavor text"]..'"')
div:wikitext("<br />")
end
div = div:done()
div = div:tag("p")
div:cssText([[
text-align: left;
margin: 0px;
padding: 0px;
]])
if data[item]["Effect"] then
div:wikitext(data[item]["Effect"])
div:wikitext("<br />")
end
div = div:done()
div = div:tag("p")
div:cssText([[
text-align: left;
margin: 0px;
padding: 0px;
]])
div = div:tag("span")
div:addClass("stein-no-text-border")
div:cssText([[
float: right;
color: #ab6d00;
margin-left: 5px;
]])
if data[item]["Selling value"] then
div:wikitext(data[item]["Selling value"])
div:wikitext(" [[File:Currency_gold.png]]")
div:wikitext("<br />")
end
div = div:done()
div:wikitext('<span style="opacity:0.5;">')
if data[item]["Level"] then
div:wikitext("Level: ")
div:wikitext(data[item]["Level"])
div:wikitext("<br />")
end
div:wikitext("</span>")
div = div:done()
div = div:done()
if data[item]["Book"] then
div= div:tag("p")
div:cssText([[
text-align: left;
margin: 0px;
padding: 0px;
]])
div:wikitext('<span style="float: right; margin-left: 5px;">')
if data[item]["Profession"] then
div:wikitext(data[item]["Profession"])
div:wikitext("<br />")
end
div:wikitext("</span>")
if data[item]["Learn time"] then
div:wikitext("Learn time: ")
div:wikitext(data[item]["Learn time"])
div:wikitext("<br />")
end
div = div:done()
div = div:tag("p")
div:cssText([[
text-align: left;
margin: 0px;
padding: 0px;
]])
div = div:tag("span")
div:addClass("stein-no-text-border")
div:cssText([[
float: right;
color: #ab6d00;
margin-left: 5px;
]])
if data[item]["Selling value of the book"] then
div:wikitext(data[item]["Selling value of the book"])
div:wikitext(" [[File:Currency_gold.png]]")
div:wikitext("<br />")
end
div = div:done()
div:wikitext('<span style="opacity: 0.5;">')
if data[item]["Book Level"] then
div:wikitext("Level: ")
div:wikitext(data[item]["Book Level"])
div:wikitext("<br />")
end
div:wikitext("</span>")
div = div:done()
end
div = div:allDone()
return tostring(div)
end
function p.item(frame)
item = frame.args[1]
local div = mw.html.create("div")
div:addClass("item")
div:addClass("p-killer")
div = div:tag("div")
div:cssText([[
float: left;
display: inline-block;
width: 48px;
height: 48px;
visibility: visible;
color: #262119;
user-select: none;
padding: 0px;
border: 2px solid #eddca0;
border-radius:3px;
position:relative;
box-shadow: 0px 0px 0 2px #262119;
margin:2px;
margin-right: 5px;
margin-bottom: 10px;
]])
rarity = data[item]["Rarity"]
if rarity=="c" then div:css("background-color", "#dbbb83")
elseif rarity=="u" then div:css("background-color", "#739743")
elseif rarity=="r" then div:css("background-color", "#6f8097")
elseif rarity=="e" then div:css("background-color", "#c261a3")
elseif rarity=="l" then div:css("background-color", "#cc6147") end
rarity = data[item]["Rarity of the book"]
if rarity=="c" then div:css("background-color", "#dbbb83")
elseif rarity=="u" then div:css("background-color", "#739743")
elseif rarity=="r" then div:css("background-color", "#6f8097")
elseif rarity=="e" then div:css("background-color", "#c261a3")
elseif rarity=="l" then div:css("background-color", "#cc6147") end
rarity = nil
div:wikitext("[[File:"..data[item]["File"].."]]")
div = div:done()
div = div:tag("div")
div:addClass("tooltip")
div:cssText([[
top: -4px;
left: 55px;
width: max-content;
]])
div:wikitext(p.stats(frame))
div = div:done()
div = div:tag("div")
div:addClass("stein-no-text-border")
div:cssText([[
white-space:pre;
font-size:20px;
]])
if data[item]["Rarity of the book"] then
rarity = data[item]["Rarity of the book"]
if rarity=="c" then
div:wikitext('<span class="common">')
elseif rarity=="u" then
div:wikitext('<span class="uncommon">')
elseif rarity=="r" then
div:wikitext('<span class="rare">')
elseif rarity=="e" then
div:wikitext('<span class="epic">')
elseif rarity=="l" then
div:wikitext('<span class="legendary">')
end
else
rarity = data[item]["Rarity"]
if rarity=="c" then
div:wikitext('<span class="common">')
elseif rarity=="u" then
div:wikitext('<span class="uncommon">')
elseif rarity=="r" then
div:wikitext('<span class="rare">')
elseif rarity=="e" then
div:wikitext('<span class="epic">')
elseif rarity=="l" then
div:wikitext('<span class="legendary">')
end
end
if data[item]["Book"] then
div:wikitext("Book: ")
if data[item]["Type of the book"]=="gather" then
div:wikitext("Gather ")
end
end
div:wikitext(data[item]["Name"])
div:wikitext("</span>")
div:wikitext("<br />")
div = div:tag("span")
div:cssText([[
opacity:0.5;
font-size:18px;
]])
if data[item]["Obtained"] then
div:wikitext("Obtained from ")
div:wikitext(data[item]["Obtained"])
end
div = div:allDone()
div = div:wikitext("<br />")
return tostring(div)
end
return p