Module:List

p={};

--This is the main table builder for the list of all uses of a particular ingredient --Expected format: first parameter is the name of the ingredient. Then each product --is in the format of 3 parameters: name, amount of the ingredient needed, and level. --These parameters are to be passed, as stated, to the template which calls this --function. --If the name used for the image is anything other than what this function expects, --add to overRideImageName list below. To use a tooltip text which is different than --what this function uses automatically, add to overRideToolTipName list below. --Note that these overrides also apply in the list for all products made by a --specific production building. function p.usage(frame) frame = frame:getParent; pairs = pairs(frame.args); items = {}; for i,j in pairs do       items[i]=j; end --the first parameter is the product name, then each product takes 3 parameters paramCount= #items; itemCount = (paramCount-1)/3; local percent; columnCount = items["columns"];

if columnCount==nil then if itemCount<=4 then columnCount= itemCount; else columnCount=3; end end rowCount = math.ceil(itemCount/columnCount); --we need to trim off the newline character ingredient= mw.text.trim(items[1]); --start building the table retVal = "{| border=\"0\" cellpadding=\"4\" cellspacing=\"2\" style=\"text-align: center; margin: .5em auto; border-collapse: collapse; border: 1px solid #ccc\"\n"; if columnCount==2 then percent=50; elseif columnCount==4 then percent=25; else percent=33; end for row=1,rowCount do       retVal = retVal .. "|- style=\"background: #ddd;\"\n"; for col =1,columnCount,1 do           retVal = retVal .. "|";           --First row we need the width information if row==1 then retVal = retVal .. "style=\"width: "..percent.."%\".|\n"; end index = (row-1)*columnCount+col; if index<=itemCount then name=mw.text.trim(items[3*index-1]); imageName=overRideImageName[name]; if imageName == nil then imageName =name..".png"; end retVal = retVal .. "";           end retVal = retVal .. "\n"; end retVal = retVal .. "|- style=\"background: #ddd;\"\n"; for col = 1,columnCount do           index = (row-1)*columnCount+col; retVal = retVal.. "|";           if index<=itemCount then -- For most products, the piped link is completely unnecessary. However, -- for products with long names, we don't want to occupy too wide an area, -- so we use a wrapped text (go to the next line) and for this we do need -- a piped link. retVal = retVal .. ""..autowrap(items[3*index-1],20)..""; end retVal = retVal .. "\n"; end retVal = retVal .. "|- style=\"border: 1px solid #ccc;\"\n"; for col=1,columnCount do           index = (row-1)*columnCount+col; retVal = retVal .. "|";           if index<=itemCount then retVal = retVal .. "x"..items[index*3].."" end retVal = retVal .. "\n"; end retVal = retVal .. "|- style=\"border: 1px solid #ccc;\"\n";

for col=1,columnCount do           index = (row-1)*columnCount+col; retVal = retVal .. "|";           if index<=itemCount then retVal = retVal .. "Level "..items[3*index+1]; end retVal = retVal .. "\n"; end end retVal=retVal .. "|}";   return retVal; end

--This is the main table builder for the list of all uses of a particular production --building. Expected format: Each product is in the format of 4 parameters: name, --level, full production time and maximum price for one item. The amount of time is --used to figure the amount of diamonds it would take to make the product --instintaniously; if this data is incorrect, append the time with a slash and the --correct number of diamonds. Similarly, it attempts to figure the amount of XP you --get from producing a single item from the price. If the result is incorrect, append --with a slash and the correct amount of XP. --These parameters are to be passed, as stated, to the template which calls this --function. --If the name used for the image is anything other than what this function expects, --add to overRideImageName list below. To use a tooltip text which is different than --what this function uses automatically, add to overRideToolTipName list below. --Note that these overrides also apply in the list for all products made from a --specific ingredient. function p.building(frame) frame = frame:getParent; pairs = pairs(frame.args); items = {}; for i,j in pairs do       items[i]=j; end --Each product takes 4 parameters paramCount= #items; itemCount = paramCount/4; --For use in the lure workbench and net maker noPrice = (items["noPrice"]~=nil); local percent; --Allow manual override of column number columnCount = items["columns"]; if columnCount==nil then if itemCount<=4 then columnCount= itemCount; else columnCount=3; end end rowCount = math.ceil(itemCount/columnCount); -- start building the table local retVal = "{| border=\"0\" cellpadding=\"3\" cellspacing=\"1\" style=\"text-align: center; margin: 1em auto; border-collapse: collapse; border: 1px solid #bbb;\"\n";

if columnCount==2 then percent=50; elseif columnCount==4 then percent=25; else percent=33; end for row=1,rowCount do   	--We build the table with several logical rows representing each visual --row. We first build each logical row, then build the visual row using --them. This allows us to only iterate over the imens once. imageRow = ""; nameRow = ""; levelRow = ""; fullTimeRow = ""; fullStarTimeRow = ""; diamondRow = ""; priceRow = ""; xpRow=""; for col =1,columnCount,1 do           imageRow = imageRow .. "|";           nameRow = nameRow .. "|";           levelRow = levelRow .. "|";           fullTimeRow = fullTimeRow .. "|";           fullStarTimeRow = fullStarTimeRow .. "|";           diamondRow = diamondRow .. "|";           priceRow = priceRow .. "|";           xpRow = xpRow .. "|";           --In the first row we need the width information if row==1 then imageRow = imageRow .. "style=\"width: "..percent.."%\".|\n"; end --get the item index from the row and column; confirm valid to allow --for last partial row. index = (row-1)*columnCount+col; if index<=itemCount then --First logical row: The image name=mw.text.trim(items[4*index-3]); imageName=overRideImageName[name]; if imageName == nil then imageName =name..".png"; end imageRow = imageRow .. "";               --Second logical row: The product name. To prevent products with --long names from uglifying the table, we autowrap the product --name as shown to the reader; this can't be done in the link. nameRow = nameRow .. ""..autowrap(name,20).."";

--Third logical row: necessary level. levelStr = mw.text.trim(items[4*index-2]); --Allow for use with reputation level (used for feed mill with 				--feed for sanctuary animals) if (string.sub(levelStr,1,1)=="R") then levelRow = levelRow.."Reputation "; levelStr = string.sub(levelStr,2); else levelRow = levelRow .. "Level "; end levelRow = levelRow .. levelStr;

--Fourth logical row: Full production time. Note that we may --need to separate the parameter into production time and --diamonds. If so, we remember the latter with no need to --re-extract it. local timeStr = mw.text.trim(items[4*index-1]); local diamonds; local slash = string.find(timeStr,"/"); if (slash ~= nil) then diamonds = tonumber(string.sub(timeStr,slash+1,-1)); timeStr = string.sub(timeStr,1,slash-1); end local time; --Allow for use of question mark as place holder if (timeStr=="?") then time="?"; diamonds="?"; --Translate time format into number of minutes elseif (string.sub(timeStr,-1,-1)=="h") then time = tonumber(string.sub(timeStr,1,-2))*60; elseif (string.sub(timeStr,-1,-1)=="m") then time = tonumber(string.sub(timeStr,1,-2)); else timeSeparator = string.find(timeStr,":"); time=tonumber(string.sub(timeStr,1,timeSeparator-1))*60+ tonumber(string.sub(timeStr,timeSeparator+1,-1)); end fullTimeRow = fullTimeRow .. displayTime(time); --Fifth logical row: Time for a 3-star machine. Note that we               --don't give the 1-star or 2-star, even for the machines where --this is reduced. fullStarTimeRow = fullStarTimeRow .. "★★★ ";               if (time=="?") then fullStarTimeRow = fullStarTimeRow.."?"; else fullStarTimeRow = fullStarTimeRow..displayTime(math.floor(time*17/20)); end --Sixth logical row: The number of diamonds needed to make the --product instintaniously. if diamonds==nil then diamonds = 1; while (diamonds<#diamondCost and diamondCost[diamonds+1][1]<=time) do                       diamonds = diamonds+1; end end diamondRow = diamondRow .. tostring(diamonds).. frame:expandTemplate({title="Infoicon",args={"dia"}});

--Seventh logical row: the full price for selling a single item --in the Roadside shop. Note that we may -need to separate the --parameter into maximum price and production XP points. If so, --we remember the latter with no need to re-extract it. priceStr = mw.text.trim(items[4*index]); local price,xp; if (noPrice) then xp=priceStr; else if (priceStr=="?") then price="?"; xp="?"; else slash = string.find(priceStr,"/"); if (slash ~= nil) then price = string.sub(priceStr,1,slash-1); xp = string.sub(priceStr,slash+1,-1); else price=tonumber(priceStr); defaultPrice=math.ceil(price/3.6); xp=math.floor((defaultPrice+1)/2.33); end end priceRow = priceRow..price.. frame:expandTemplate({title="Infoicon",args={"coin"}}).."\n"; end --Eighth logical row: The amount of XP points you get for --producing a single item. xpRow = xpRow..xp.. frame:expandTemplate({title="Infoicon",args={"xp"}}).."\n"; end imageRow = imageRow .. "\n"; nameRow = nameRow .. "\n"; levelRow = levelRow .. "\n"; fullTimeRow = fullTimeRow .. "\n"; fullStarTimeRow = fullStarTimeRow .. "\n"; diamondRow = diamondRow .. "\n"; priceRow = priceRow .. "\n"; xpRow = xpRow .. "\n"; end --Build the actual row out of the logical rows retVal = retVal .. "|- style=\"background: #ddd;\"\n"; retVal = retVal .. imageRow; retVal = retVal .. "|- style=\"background: #ddd;\"\n"; retVal = retVal .. nameRow; retVal = retVal .. "|- style=\"border: 1px solid #bbb;\"\n"; retVal = retVal .. levelRow; retVal = retVal .. "|-\n"; retVal = retVal .. fullTimeRow; retVal = retVal .. "|-\n"; retVal = retVal .. fullStarTimeRow; retVal = retVal .. "|-\n"; retVal = retVal .. diamondRow; retVal = retVal .. "|- style=\"border-top: 1px solid #bbb;\"\n"; if (not(noPrice)) then retVal = retVal .. priceRow; retVal = retVal .. "|-\n"; end retVal = retVal .. xpRow; end

retVal = retVal .. "|}";   return retVal; end

--Special cases for image file name. List is in the form of: --1. Name of product as listed in the template call, surrounded by double quotes, --  inside square brackets. --2. An equals sign. --3. The full name of the file name, inside double quotes. -- --All entries must be comma separated. Please use a new line and line everything up --for better human readability. overRideImageName= {   ["Caffè Latte"]="Caffe Latte.png", ["Caffè Mocha"]="Caffe Mocha.png", ["Shepherd's Pie"]="Shepherds Pie.png" };

-- costs for making items instantaneously based on full time in minutes. This is -- in the form of minimum and maximum observed, excluding outliers. Please note -- that this is a position-indexed list; the indexes in the comments are only -- for human readers. diamondCost= {   {5,5},--1    {10,20},--2    {25,50},--3    {60,80},--4    {90,135},--5    {150,240},--6    {300,360},--7    {390,450},--8    {480,510},--9    {600,600},--10 (none actually observed, need a placeholder) {720,720},--11   {960,960},--12    {1200,1200},--13    {1440,1440}--14 };

-- Special cases for tooltip name. List is in the form of: --1. Name of product as listed in the template call, surrounded by double quotes, --  inside square brackets. --2. An equals sign. --3. The full desired tooltip text, inside double quotes. -- --All entries must be comma separated. Please use a new line and line everything up --for better human readability. overRideToolTipName= {   ["BLT Salad"] = "BLT salad" };

function toolTipName(name) if overRideToolTipName[name] then return overRideToolTipName[name]; else return string.upper(string.sub(name,1,1)) .. string.lower(string.sub(name,2)); end end

function autowrap(str,maxLen) if (#str<=maxLen) then return str; end wrapIndex = string.find(str," ",#str/2); if (wrapIndex~=nil) then str = string.sub(str,1,wrapIndex-1).." "..string.sub(str,wrapIndex+1); end return str; end

function displayTime(time) if (time=="?") then return "?"; end hours = math.floor(time/60); minutes = time%60; retVal = ""; if (hours>0) then retVal = retVal .. tostring(hours).." h "; end if (minutes>0) then retVal = retVal .. tostring(minutes).." min"; end return mw.text.trim(retVal); end

function getDetail(frame,product,detail) return frame:expandTemplate{title="Item Data/"..mw.text.trim(product),args={detail=detail}}; end

function p.allProducts(frame) args=require("Module:Full Item List"); data=require("Module:Item Data"); products={}; for i,j in pairs(args) do       if(data.itemType(j.src)=="Product") then table.insert(products,i); end end return #products; end

return p;