Module:ItemTables: Difference between revisions
Jump to navigation
Jump to search
add styling and more patterns |
add something t test |
||
Line 57: | Line 57: | ||
for link, patterns in pairs(link_patterns) do | for link, patterns in pairs(link_patterns) do | ||
for i, v in ipairs(patterns) do | for i, v in ipairs(patterns) do | ||
local a = | local a = string.find(desc, v) | ||
if a then desc = link break | if a then desc = link break | ||
end | end | ||
end | end | ||
end | |||
return desc | |||
end | |||
local internal_to_friendly = {} | |||
internal_to_friendly["ammo"] = { "BonusClipSizePercent" } | |||
internal_to_friendly["weapon damage"] = { "BaseAttackDamagePercent" } | |||
internal_to_friendly["health"] = { "BonusHealth" } | |||
internal_to_friendly["health regen"] = { "BonusHealthRegen" } | |||
function amicableNames(desc) | |||
desc = string.lower(desc or "") | |||
for link, patterns in pairs(internal_to_friendly) do | |||
desc = patterns --TEST THIS | |||
end | end | ||
return desc | return desc |
Revision as of 08:12, 29 September 2024
Documentation for this module may be created at Module:ItemTables/doc
local p = {};
local data = mw.loadJsonData("Data:ItemData.json")
local get_cost = require("Module:ItemData")._get_cost
local get_type = require("Module:ItemData")._get_type
-- returns the table of a specific item
function get_json_item(name)
for i,v in pairs(data) do
if (v["Name"] == name) then
return v
end
end
return nil
end
-- Adds commas delimiter to the thousands place
function Format(amount)
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k == 0) then
break
end
end
return formatted
end
--- Copies original table with its children as deep as possible. Does not handle metatables. (Copy is needed because Lua passes by reference, not value)
-- @function Deepcopy
-- @param {n-D table}
-- @return {n-D table}
function Deepcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[Deepcopy(orig_key)] = Deepcopy(orig_value)
end
else
copy = orig
end
return copy
end
local link_patterns = {}
link_patterns["BonusClipSizePercent"] = { "[Aa]mmo" }
link_patterns["BaseAttackDamagePercent"] = { "[Ww]eapon [Dd]amage" }
link_patterns["CloseRangeBonusWeaponPower"] = { "[Cc]lose [Ww]eapon [Dd]amage" }
link_patterns["BulletLifestealPercent"] = { "[Bb]ullet [Ll]ifesteal" }
link_patterns["BonusHealth"] = { "[Hh]ealth" }
link_patterns["BonusHealthRegen"] = { "[Hh]ealth [Rr]egen" }
link_patterns["BonusFireRate"] = { "[Ff]ire [Rr]ate" }
function FriendlyNames(desc)
for link, patterns in pairs(link_patterns) do
for i, v in ipairs(patterns) do
local a = string.find(desc, v)
if a then desc = link break
end
end
end
return desc
end
local internal_to_friendly = {}
internal_to_friendly["ammo"] = { "BonusClipSizePercent" }
internal_to_friendly["weapon damage"] = { "BaseAttackDamagePercent" }
internal_to_friendly["health"] = { "BonusHealth" }
internal_to_friendly["health regen"] = { "BonusHealthRegen" }
function amicableNames(desc)
desc = string.lower(desc or "")
for link, patterns in pairs(internal_to_friendly) do
desc = patterns --TEST THIS
end
return desc
end
p.itemPropTable = function(frame)
local TableValues = {}
local requirements = {}
local listofItems = ""
local property = frame.args[1] or mw.title.getCurrentTitle().text
local friendlyPropertyName = property
property = FriendlyNames(property)
-- local item = get_json_item(item_name)
-- if(item == nil) then return "Item Not Found what" end
local createTable = mw.html.create('table')
:addClass('wikitable sortable')
:tag('caption'):wikitext("List of Items"):done()
local createTableRow = mw.html.create('tr')
createTableRow
:tag('th'):wikitext('Name'):done()
:tag('th'):wikitext('Cost'):done()
:tag('th'):wikitext('Category'):done()
:tag('th'):wikitext('Stat change'):done()
createTable:node(createTableRow)
-- query all items
for internalName, itemName in pairs(data) do --itemName is the key. go through whole table. in this case itemName can be upgrade_improved_stamina
local display = frame:expandTemplate{
title = 'ItemIcon',
args = {
itemName["Name"]
}
}
if(itemName[property] ~= nil and itemName["Name"] ~= nil) then
listofItems = listofItems .. itemName["Name"] .. "<br/>"
local tableData = mw.html.create('tr')
tableData
:tag('td'):wikitext(display):done()
:tag('td'):wikitext(get_cost(itemName["Name"])):done()
:tag('td'):wikitext(get_type(itemName["Name"])):done()
:tag('td'):wikitext("+<b>" .. itemName[property].. "</b> " .. friendlyPropertyName):done()
table.insert(requirements, tableData)
-- TableValues = table.insert(TableValues, itemName["Name"]) -- i may want to make a table first, so it includes weapon and cost to make it sortable.
end
end
for _, row in ipairs(requirements) do
createTableRow:node(row)
end
--createTable:node(createTableRow)
return tostring(createTable)
--return listofItems -- this is just a string list, same thing as createTable. delete this when line when finished
--return table.concat(TableValues, ", ")
end
return p