Module:Item uses

local p = {} --p stands for package p.loadedData = mw.loadJsonData( "Module:Item infobox/itemData.json" ) local args = mw.getCurrentFrame.args

-- find the item data for our input arg for k, v in pairs(p.loadedData) do   if args[1] == v["inGameName"] then if args[2] == nil or args[2] == '' then p.data = p.loadedData[k] break end end end

function p.main( frame ) local useData = p.data['uses'] local wikitext = '{| class="wikitable" \n|+ Uses for ' .. p.data['inGameName'] .. '\n! Type !! Quantity\n' local missionData = useData['missions'] local jobData    = useData['jobs'] local quarterData = useData['quarters'] local forgeData  = useData['forge'] local printData  = useData['printing']

local hasOutput = false local useOnceCount = 0; -- missions local hasDoneMissionOutput = false for index, value in pairs(missionData) do		if not hasDoneMissionOutput then wikitext = wikitext .. '\n|-\n! colspan="2" | Missions' hasDoneMissionOutput = true end hasOutput = true local name = mw.text.split(value['inGameName'], " Part ", true) wikitext = wikitext .. '\n|-\n|' .. value['inGameName'] .. ' ||' .. value['amount'].. ' '		useOnceCount = useOnceCount + value['amount'] end -- jobs local hasDoneJobsOutput = false -- these jobs must have the (Job) text appended to the link as they are otherwise the same as another page local jobTextList = {"NEW-Hard-ICA-Gather-2", "NEW-Medium-KOR-Mine-1", "NEW-Medium-KOR-Mine-3", "NEW-Medium-KOR-Meteor-1", "NEW-Hard-KOR-Meteor-1", "NEW-Hard-KOR-Mine-3", "NEW-Hard-KOR-Hunt-1", "NEW-Easy-Osiris-Flora-1", "NEW-Medium-Osiris-Gather-5", "NEW-Medium-Osiris-Flora-2"} for index, value in pairs(jobData) do		if not hasDoneJobsOutput then wikitext = wikitext .. '\n|-\n! colspan="2" | Jobs' hasDoneJobsOutput = true end local name = value['inGameName'] -- set name in some edge cases if p.contains(jobTextList, index) then name = name .. ' (Job)' elseif index == 'NEW-Hard-KOR-Gather-4' then name = 'Energy Crisis (Korolev)' elseif index == 'NEW-Hard-ICA-Mine-2' then name = 'Energy Crisis (ICA)' end hasOutput = true wikitext = wikitext .. '\n|-\n|' .. name .. ' ||' .. value['amount'] end

-- quarters local hasDoneQuartersOutput = false for index, value in pairs(quarterData) do		if not hasDoneQuartersOutput then wikitext = wikitext .. '\n|-\n! colspan="2" | Personal Quarters' hasDoneQuartersOutput = true end hasOutput = true local tab = 'Quarters-0' if string.find(index, 'generate') or string.find(index, 'passive') then tab = 'Generator-0' elseif string.find(index, 'increase_bag') or string.find(index, 'stash') then tab = 'Inventory-0' elseif string.find(index, 'reduce_pq') then tab = 'Player_Quarter_Upgrade_Time-0' end wikitext = wikitext .. '\n|-\n|' .. value['inGameName'] .. ' ||' .. value['amount'] useOnceCount = useOnceCount + value['amount'] end -- forge local hasDoneForgeOutput = false for index, value in pairs(forgeData) do		if not hasDoneForgeOutput then wikitext = wikitext .. '\n|-\n! colspan="2" | Forge Recipes' hasDoneForgeOutput = true end hasOutput = true wikitext = wikitext .. '\n|-\n| ' .. value['inGameName'] .. ' ||' .. value['amount'] end -- printing local hasDonePrintingOutput = false for index, value in pairs(printData) do		if not hasDonePrintingOutput then wikitext = wikitext .. '\n|-\n! colspan="2" | Printing Recipes' hasDonePrintingOutput = true end hasOutput = true wikitext = wikitext .. '\n|-\n| ||' .. value['amount'] end wikitext = wikitext .. '\n|}' --return mw.dumpObject(forgeData) if hasOutput == false then return "This item has no uses in any Missions, Jobs, Personal Quarters, Forge Recipes, or Printing Recipes. It is purely for selling to a Faction vendor." end if hasOutput then local textBeforeTable = ' has one or multiple uses in \'\'The Cycle: Frontier\'\'. To complete all missions and quarter upgrades, this item is needed '.. useOnceCount .. ' times.\n' return frame:preprocess(textBeforeTable .. wikitext) end end

function p.contains(list, x)	for _, v in pairs(list) do		if v == x then return true end end return false end return p