Module:AlternateRecipesTable/sandbox

local cargo = mw.ext.cargo -- DO NOT RELEASE YET | There multiple things im still working on and this could cause issues for people as I make it print an error as my budget console.log, as I cant understand how to use it 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 ExpAltRecip = 0 local StaAltRecip = 0 local p = {} local experimental_style = 'position:absolute; font-variant:all-small-caps; font-size:small; font-weight:bold; left:0; top:0; transform: rotate(0deg) translate(0px, 0px); background:red; color:white; padding: 1px 20px;' local stable_style = 'position:absolute; font-variant:all-small-caps; font-size:small; font-weight:bold; left:0; top:0; transform: rotate(0deg) translate(0px, 0px); background:orange; color:white; padding: 1px 20px;'

-- 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)

ingredient1 = "a" ingredient2 = "b" ingredient3 = "c" ingredient4 = "d"

-- store the default recipes for comparison local defaultRecipes = {} local r = 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 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,'  ')..'  ')

-- loop the alt recipes local altRecipesCount = 0 local iii = 1 while recipes[r] do   local craftingTime = tonumber(recipes[r].craftingTime) if craftingTime and craftingTime > 0 then local stripe = '' local stabletag = 0 -- DO NOT DELETE | Toastry | This is going to automatically label things to be "Stable only" meaning the recipe is only in stable, I've been awake for 33 hours at this point and I need to get some sleep, the keys on my keyboard are wobbling... if recipes[r].experimental ~= '1' then stablerecipie = recipes[r].recipeName local altRecipesCount = 0 while recipes[r]['ingredient'..iii] and tonumber(recipes[r]['quantity'..iii]) do             iii=iii+1 if recipes[r].experimental == 1 and recipes[r].recipeName == stablerecipie then error('Condition 1') stripe = '' ..mw.getCurrentFrame:expandTemplate{title='Tooltip', args={[1]='Stable', [2]='This recipe is available only in Stable version of Satisfactory', [3]='no underline'}} .. ' '         end end end if recipes[r].experimental == '1' then ExpAltRecip = ExpAltRecip + 1 stripe = '' .. mw.getCurrentFrame:expandTemplate{title='Tooltip', args={[1]='Exp', [2]='This recipe is available only in Experimental version of Satisfactory', [3]='no underline'}} .. ' ' end if recipes[r].experimental ~= '1' and recipes[r].recipeName=='Electrode - Aluminum Scrap' or recipes[r].experimental ~= '1' and recipes[r].recipeName=='Electromagnetic Connection Rod' or recipes[r].experimental ~= '1' and recipes[r].recipeName=='Heat Exchanger' or recipes[r].experimental ~= '1' and recipes[r].recipeName=='Infused Uranium Cell' or recipes[r].experimental ~= '1' and recipes[r].recipeName=='Nuclear Fuel Unit' or recipes[r].experimental ~= '1' and recipes[r].recipeName=='Pure Aluminum Ingot' or recipes[r].experimental ~= '1' and recipes[r].recipeName=='Radio Control System' or recipes[r].experimental ~= '1' and recipes[r].recipeName=='Turbo Rigour Motor' then StaAltRecip = StaAltRecip + 1 stripe = '' ..mw.getCurrentFrame:expandTemplate{title='Tooltip', args={[1]='Stable', [2]='This recipe is available only in Stable version of Satisfactory', [3]='no underline'}} .. ' ' end html = html .. '' .. '' .. recipes[r].recipeName .. stripe .. ' '     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 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)..' ' }     -- 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,' ') table.insert(cols,' ') 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 ' Total alternate recipes: '..altRecipesCount..' ' 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