Module:ItemTables: Difference between revisions

Jump to navigation Jump to search
change names, add better comments,
add fire rate and stamina, include inclusions of different stat names, cleanup. WORKS NOW BUT ALSO BREAKS, invocations need to be reversed from internal to friendly, to friendly to internal
Line 3: Line 3:
local get_cost = require("Module:ItemData")._get_cost
local get_cost = require("Module:ItemData")._get_cost
local get_type = require("Module:ItemData")._get_type
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
-- Adds commas delimiter to the thousands place
Line 45: Line 35:




local link_patterns = {}
-- local link_patterns = {}
link_patterns["BonusClipSizePercent"] = { "[Aa]mmo" }
-- link_patterns["BonusClipSizePercent"] = { "[Aa]mmo" }
link_patterns["CloseRangeBonusWeaponPower"] = { "[Cc]lose [Ww]eapon [Dd]amage" }
-- link_patterns["CloseRangeBonusWeaponPower"] = { "[Cc]lose [Ww]eapon [Dd]amage" }
link_patterns["BaseAttackDamagePercent"] = { "[Ww]eapon [Dd]amage" }
-- link_patterns["BaseAttackDamagePercent"] = { "[Ww]eapon [Dd]amage" }
link_patterns["BulletLifestealPercent"] = { "[Bb]ullet [Ll]ifesteal" }
-- link_patterns["BulletLifestealPercent"] = { "[Bb]ullet [Ll]ifesteal" }
link_patterns["BonusHealthRegen"] = { "[Hh]ealth [Rr]egen" }
-- link_patterns["BonusHealthRegen"] = { "[Hh]ealth [Rr]egen" }
link_patterns["BonusHealth"] = { "[Hh]ealth" }
-- link_patterns["BonusHealth"] = { "[Hh]ealth" }
link_patterns["BonusFireRate"] = { "[Ff]ire [Rr]ate" }
-- link_patterns["BonusFireRate"] = { "[Ff]ire [Rr]ate" }
 
--
function FriendlyNames(desc)
-- function FriendlyNames(desc)
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 = string.find(desc, v)
--     local a = string.find(desc, v)
if a then desc = link break
-- if a then desc = link break
     end
--     end
     end
--     end
end
-- end
return desc
-- return desc
end
-- end


local internal_to_friendly = {}
local internal_to_friendly = {}
Line 70: Line 60:
internal_to_friendly["health"] = { "BonusHealth" }
internal_to_friendly["health"] = { "BonusHealth" }
internal_to_friendly["health regen"] = { "BonusHealthRegen" }
internal_to_friendly["health regen"] = { "BonusHealthRegen" }
internal_to_friendly["fire rate"] = { "BonusFireRate" }
internal_to_friendly["stamina"] = { "Stamina" }


function amicableNames(desc)
function amicableNames(desc)
local keysTable = {}
desc = string.lower(desc or "")
desc = string.lower(desc or "")
for link, patterns in pairs(internal_to_friendly) do
for link, patterns in pairs(internal_to_friendly) do
for _, v in pairs(patterns) do
 
desc = v --TEST THIS
if (desc == link) then keysTable = patterns end
end
 
end
end
return desc
return keysTable
end
end


Line 84: Line 77:
local TableValues = {}
local TableValues = {}
local requirements = {}
local requirements = {}
local listofKeysTable = {}
local listofItems = ""
local listofItems = ""
local property = frame.args[1] or mw.title.getCurrentTitle().text
local property = frame.args[1] or mw.title.getCurrentTitle().text
local copyVar = property
local copyVar = property
property = FriendlyNames(property) -- need to switch this around from value to key, to key to values
listofKeysTable = amicableNames(property) -- need to switch this around from value to key, to key to values
-- local item = get_json_item(item_name)
-- if(item == nil) then return "Item Not Found what" end
local createTable = mw.html.create('table')
local createTable = mw.html.create('table')
Line 113: Line 105:
}
}
}
}
for _, t in pairs(listofKeysTable) do
-- filter out items that: don't have the property, don't have names (have 'null' names), and aren't disabled --//and itemName["Disabled"] == nil  
-- filter out items that: don't have the property, don't have names (have 'null' names), and aren't disabled --//and itemName["Disabled"] == nil  
if(itemName[property] ~= nil and itemName["Name"] ~= nil) then --  and itemName["Disabled"] == false --// the data field is not setup to filter this yet
if(itemName[t] ~= nil and itemName["Name"] ~= nil) then --  and itemName["Disabled"] == false --// the data field is not setup to filter this yet
listofItems = listofItems .. itemName["Name"] .. "<br/>"
listofItems = listofItems .. itemName["Name"] .. "<br/>"
Line 123: Line 115:
:tag('td'):wikitext(get_cost(itemName["Name"])):done()
:tag('td'):wikitext(get_cost(itemName["Name"])):done()
:tag('td'):wikitext(get_type(itemName["Name"])):done()
:tag('td'):wikitext(get_type(itemName["Name"])):done()
:tag('td'):wikitext("+<b>" .. itemName[property].. "</b> " .. copyVar):done()
:tag('td'):wikitext("+<b>" .. itemName[t].. "</b> " .. copyVar):done()
table.insert(requirements, tableData)
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.
-- 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
end
end
end