Module:AlternateRecipesTable/sandbox

local cargo = mw.ext.cargo local moduleTooltips = require('Module:ItemTooltip') local argList = { '_pageName', 'experimental', 'alternateRecipe', 'recipeName', 'researchTier', 'craftingTime', 'product', 'productCount', 'productsPerMinute', 'product2', 'productCount2', 'productsPerMinute2', 'product3', 'productCount3', 'productsPerMinute3', 'product4', 'productCount4', 'productsPerMinute4', 'ingredient1', 'quantity1', 'ingredient2', 'quantity2', 'ingredient3', 'quantity3', 'ingredient4', 'quantity4', 'ingredient5', 'quantity5', 'ingredient6', 'quantity6', 'ingredient7', 'quantity7', 'ingredient8', 'quantity8', 'ingredient9', 'quantity9', 'ingredient10', 'quantity10' } local altRecipesCount = 0 local ExpAltRecip = 0 local StaAltRecip = 0 local p = {} local ribbonStyle = ' position:absolute; font-variant:all-small-caps; font-size:small; font-weight:bold; left:0; top:0; background:red; color:white; padding: 1px 20px;' local experimental_style = ribbonStyle .. ' background:red; transform:rotate(-45deg) translate(-25px, -5px);' local stable_style = ribbonStyle .. ' background:orange; transform:rotate(-45deg) translate(-34px, -7px); ' local isStable = 0 local enlarged = 0

-- creates debugging variables local debugx = '' -- what the user specified to debug local tablindeb = 0 -- the variable as to if it should log the variables related to the original ingredients /s (used to add 2 lines of padding to each alternate column) Full var name: tableLineDebug local stabribdeb = 0 -- the variable for debugging the stable ribbons Full Var Name: Stable Ribbon Debug local stabribdeb2 = 0 -- the variable for debugging the stable ribbons Full Var Name: Stable Ribbon Debug 2 local debugging = 0

-- displays a table with info about alternate recipes compared to their default counterpart function p.table local html = '' local rows = {} -- lookup recipe data from database local fields = table.concat(argList, ',') local queryArgs = { where = 'product IS NOT NULL', orderBy = 'alternateRecipe ASC, researchTier ASC, product ASC, recipeName ASC', limit = 500 } local recipes = cargo.query('crafting_recipes', fields, queryArgs) local recipes2 = cargo.query('crafting_recipes', fields, queryArgs) -- store the default recipes for comparison local defaultRecipes = {} local r = 1 local f = 1 while recipes[r] and not (recipes[r].alternateRecipe and recipes[r].alternateRecipe == '1') do   local craftingTime = tonumber(recipes[r].craftingTime) if craftingTime and craftingTime > 0 then defaultRecipes[recipes[r].product] = recipes[r] local ingRows = {} local ii = 1 local batchPerMinute = 60 / craftingTime while recipes[r]['ingredient'..ii] and tonumber(recipes[r]['quantity'..ii]) do       table.insert(ingRows, ' '..' '..recipes[r]['ingredient'..ii]..''..' '..round(batchPerMinute * tonumber(recipes[r]['quantity'..ii]))..' ') ii = ii + 1 if tablindeb == 1 then -- debug mw.log('recipes[r].recipeName: ' .. recipes[r].recipeName .. '     |      ii: ' .. ii .. '      |      recipes[r].product: ' .. recipes[r].product) end end defaultRecipes[recipes[r].product].ingredientTable = table.concat(ingRows,'') end r = r + 1 end

-- header local cols={'Alternate name','Product', 'Ingredients /min', 'Rate/min', 'Original Rate/min', 'Original Ingredients /min', 'Prerequisites'} table.insert(rows,' '..table.concat(cols,'  ')..'  ') function p.reset if stabribdeb2 == 1 then mw.log('reset!') end f = 1 end -- checks if the recipe is only in stable function p.stable while recipes2[f] do     if recipes2[f].alternateRecipe ~= '0' then if recipes2[f].recipeName == stablerecipe and recipes2[f].experimental == '1' then if stabribdeb2 == 1 then mw.log('beep') end isStable = 1 p.reset return("") end end f = f + 1 end p.reset end -- loop the alt recipes while recipes[r] do   local craftingTime = tonumber(recipes[r].craftingTime) if craftingTime and craftingTime > 0 then local stripe = '' if recipes[r].experimental ~= '1' then if stabribdeb == 1 then mw.log('recipe: '..recipes[r].recipeName..' experimental: '..recipes[r].experimental) end stablerecipe = recipes[r].recipeName p.stable(stablerecipe) end if recipes[r].experimental == '1' then ExpAltRecip = ExpAltRecip + 1 stripe = '' .. mw.getCurrentFrame:expandTemplate{title='Tooltip', args={[1]='Exp Only', [2]='This recipe is available only in Experimental version of Satisfactory', [3]='no underline'}} .. ' '   enlarged = 1 elseif isStable == 1 then stripe = '' ..mw.getCurrentFrame:expandTemplate{title='Tooltip', args={[1]='Stable Only', [2]='This recipe is available only in Stable version of Satisfactory', [3]='no underline'}} .. ' '   isStable = 0 enlarged = 1 else enlarged = 0 end local batchPerMinute = 60 / craftingTime local ingRows = {} local ii = 1 while recipes[r]['ingredient'..ii] and tonumber(recipes[r]['quantity'..ii]) do       table.insert(ingRows, ' '..recipes[r]['ingredient'..ii]..' '..round(batchPerMinute * tonumber(recipes[r]['quantity'..ii]))..' ') ii = ii + 1 end if enlarged == 1 then cols = {''..((recipes[r].recipeName and recipes[r].recipeName ~= '') and recipes[r].recipeName or recipes[r].product)..stripe..' ', ' '..recipes[r].product..' ', ''..table.concat(ingRows,'')..' ', ''..round(recipes[r].productsPerMinute)..' ' }     elseif enlarged == 0 then cols = {''..((recipes[r].recipeName and recipes[r].recipeName ~= '') and recipes[r].recipeName or recipes[r].product)..stripe..' ', ' '..recipes[r].product..' ', ''..table.concat(ingRows,'')..' ', ''..round(recipes[r].productsPerMinute)..' ' }     end -- if default recipe is available, show it for comparison if defaultRecipes[recipes[r].product] then table.insert(cols, ''..round(defaultRecipes[recipes[r].product].productsPerMinute)..' ') table.insert(cols, ''..defaultRecipes[recipes[r].product].ingredientTable..' ') else table.insert(cols,''..'N/A'..' ') table.insert(cols,''..'N/A'..' ') end table.insert(cols, ' '..(recipes[r].researchTier and recipes[r].researchTier or '')..' ') table.insert(rows,' '..table.concat(cols)..' ') altRecipesCount = altRecipesCount + 1 else html = html .. ' '   end r = r + 1 end return ' ' end -- debugging, leave in, may help in future -- to debug, in the console do p.debug(x), x being one of the following: Table | TableLines -- example: p.debug(TableAll)

function p.debug(debugx) if debugx == "TableAll" then mw.log('Running Entire Table') p.table elseif debugx == "TableLines" then mw.log('Running Table Lines') tablindeb = 1 p.table elseif debugx == "Stable" then mw.log('Running Stable Ribbon') stabribdeb = 1 p.table elseif debugx == "Stable2" then mw.log('Running Stable Ribbon 2') stabribdeb2 = 1 p.table else mw.log('Unrecognized selector! Available selectors: "TableAll" | "TableLines" | "Stable" | "Stable2"') end end

-- round to 1 decimal for display (string) function round(n) local tentimes = math.floor(n*10+0.5) local suffix = '' if tentimes % 10 == 0 then suffix = '.0' end return (tentimes/10)..suffix end

return p

-- prime inefficiency

-- if not common_sense: --  head.bash_against_wall