This commit is contained in:
Crispy 2025-06-22 00:08:46 +02:00
parent f8fd2513c8
commit 491112768c
27 changed files with 1095 additions and 3537 deletions

View file

@ -1,7 +1,44 @@
pp = require("cc.pretty").pretty_print
require("stringshit")
require("fluids")
recipes = {}
local knownAmounts = {}
knownAmounts["111"] = 9000
knownAmounts["222"] = 18000
knownAmounts["333"] = 27000
knownAmounts["444"] = 36000
knownAmounts["41.6"] = 3375 -- 500mB / 12
knownAmounts["41"] = 3375 -- 500mB / 12
knownAmounts["12"] = 1000
function mb2droplet(amount)
return math.floor(amount * 81 + 0.5)
end
function droplet2mb(amount)
return amount / 81
end
function droplet2string(droplets)
local mb = droplet2mb(droplets)
local out = tostring(math.floor(mb))
-- local frac = math.fmod(mb, 1)
-- if frac > 0 then
-- out = out .. ""
-- end
out = out .. " mB"
return out
end
function parseFluidAmount(text)
-- local parts = splitString(text, "*")
if knownAmounts[text] then
return knownAmounts[text]
end
return mb2droplet(tonumber(text))
end
function read_recipe(file)
product = file.readLine()
if product == nil then return nil end
@ -18,8 +55,11 @@ function read_recipe(file)
intermediate = string.sub(line, 14)
elseif string.sub(line, 1, 7) == "repeat " then
repeats = tonumber(string.sub(line, 8))
elseif string.sub(line, 1, 6) == "yield " then
elseif string.sub(line, 1, 6) == "yield " then
yield = tonumber(string.sub(line, 7))
if isFluid[product] then
yield = parseFluidAmount(yield)
end
elseif line == "steps:" then
break
end
@ -35,9 +75,14 @@ function read_recipe(file)
extra_items = {}
for i = 2, #words do
itemdata = splitString(words[i], ":")
if isFluid[itemdata[1]] and itemdata[2] then
amount = parseFluidAmount(itemdata[2])
else
amount = tonumber(itemdata[2]) or 1
end
table.insert(extra_items, {
name = itemdata[1],
count = tonumber(itemdata[2] or 1)
count = amount
})
end
table.insert(steps, {
@ -71,9 +116,9 @@ end
function ingredientsOf(recipe)
items = {}
for step_index = 1,#recipe.steps do
for step_index = 1, #recipe.steps do
step = recipe.steps[step_index]
for _,item in pairs(step.extra_items) do
for _, item in pairs(step.extra_items) do
if item.name ~= "nil" then
old_sum = items[item.name] or 0
items[item.name] = old_sum + item.count * recipe.repeats