Factory Planner


This mod allows you to plan your production in advance, specifying the recipes and machines that make up each assembly line. It provides powerful features that are fast and intuitive to use, so you can focus on actually building your factory.

Utilities
4 months ago
0.17 - 1.1
209K

i Item breakdown in tooltips

1 year, 21 days ago
(updated 1 year, 21 days ago)

Hi, great mod and thank you for your work!

I would like to have an item breakdown in the tooltips, to see the rates and where a item is being produced or consumed.
Example UI draft below (image on top is from RateCalculator mod as reference). The draft only shows the top-floor-table but I would like to see this functionality also for the Products/Byproducts/Ingredients sections on top.

(the idea is based on one of the recent updates of https://mods.factorio.com/mod/RateCalculator)

1 year, 21 days ago

So just to make sure I understand, the breakdown explains for which products this item is consumed right?

1 year, 21 days ago

Yes, to see where it is consumed would be the most important information (first priority).

But you can also think the other way around: if you have multiple recipes to produce an item, an breakdown for "where it's getting produced at which rate" might be also an idea - but this case is more rarely and not so useful (second priority).

1 year, 21 days ago

Hm I see why Rate Calculator has this, but doesn't FP show you this already in the ingredient lists? I get that it's a nicer way to have it shown in one place, but it feels a bit niche for somewhat complicated data to collect and a lot of tooltip real estate. Hmm I'll have to think about it, but tbh I don't see it being super appealing.

1 year, 21 days ago

Yes, it's part of the ingredients but to gather that information manually, you have to scroll up and down, looking for it with eagle eyes which is quite tedious (see screenshot below with 2 out of 4 marked). When dealing with a bigger main bus, I noticed that I need to do this quite often - so for my way of using FP it would be really helpful.
As you said, I want to have it at one place to get a quick glance. I want to know quickly, how many consumers I have and who is my "main" consumer so I can design the belts for it accordingly.
Maybe it's also related how I use FP, because I like having big "subfactories" without any "subfloors" - just lots of information at one place (without any duplicates, because I like to centralize my production).

1 year, 20 days ago
(updated 1 year, 20 days ago)

As I wanted to learn Lua one day I used my basic knowledge to create something. I'm pretty sure there are more edge cases to be considered.
Do with it whatever you want :)

Testing:

Code changes overview inside production_table.lua -> function builders.products
https://i.imgur.com/sDKZ05C.png

Code

local break_down_tooltip = ""
local parent = line.parent
local cancel = false
if (line.active == nil or line.active) then
    for _, parent_line in ipairs(Line.get_in_order(parent, "Line")) do
        if line == parent_line and not metadata.matrix_solver_active then
            cancel = true -- traditional solver only uses products from below so we MUST cancel further breakdown here
        end

        if not cancel and line ~= parent_line and (parent_line.active == nil or parent_line.active) then
            for _, ingredient in ipairs(Line.get_in_order(parent_line, "Ingredient")) do
                if product.proto.name == ingredient.proto.name then
                    local machine_count_break_down = (not parent_line.subfloor) and parent_line.machine.count or nil
                    local amount_breakdown = ingredient.amount

                    if ingredient.amount > product.amount then
                        local percentage = product.amount / ingredient.amount
                        if machine_count_break_down ~= nil then
                            machine_count_break_down = machine_count_break_down * percentage
                        end
                        amount_breakdown = amount_breakdown * percentage
                    end


                    local amount_break_down, number_tooltip_break_down = view_state.process_item(metadata.view_state_metadata, ingredient, amount_breakdown, machine_count_break_down)

                    if amount_break_down ~= "0" then
                        if break_down_tooltip == "" then
                            break_down_tooltip = {"", "\n", {"fp.tt_title", "Breakdown"}}
                        end

                        local recipe = parent_line.recipe
                        local subfloor_text = ""
                        if recipe == nil then
                            recipe = parent_line.subfloor.defining_line.recipe
                            subfloor_text = "(subfloor) "
                        end

                        local tooltip_icon = "[recipe=" .. recipe.proto.name .. "] "
                        if recipe.proto.name == "impostor-silo-rocket-silo-item-satellite" then 
                            tooltip_icon = "[item=space-science-pack] "
                        end

                        table.insert(break_down_tooltip, "\n")
                        table.insert(break_down_tooltip, {"", tooltip_icon .. subfloor_text, number_tooltip_break_down})
                    end
                end
            end
        end
    end
end

local name_line = (note == nil) and {"fp.tt_title", product.proto.localised_name}
    or {"fp.tt_title_with_note", product.proto.localised_name, note}
local number_line = (number_tooltip) and {"", "\n", number_tooltip} or ""
local tooltip = {"", name_line, number_line, break_down_tooltip, metadata.product_tutorial_tt}
1 year, 18 days ago

Hey thanks, appreciate the code! Looks pretty good. I'd do this as part of the calculation process, not as part of the GUI creation, since this'll be quite performance-intensive to do every time. But still, a nice proof of concept!

I'm still not quite sure if I want to include this feature. I guess you showed that it isn't too complicated to write and maintain, and having this sort of thing behind a preference has precedent. I'll make a note of it and think about it a bit!

11 months ago

Hello, so I just implemented something with similar effect to this: When you hover over an item in the compact subfactory view, it'll highlight all other identical items. This isn't quite what you asked for, and it's only for the compact dialog at the moment, but if you want to, give it a try and let me know what you think, and whether it solves your issue.

11 months ago

Nice idea, but this is limited only to the visible part of the screen. So it doesn't provide me the full overview of each item at one place. I would still need to scroll through the list and manually look where it is being used. This might be handy for smaller lists, but for my use-case it's not that beneficial.

In the screenshot below the Transistors are being used at 4 places, but I can just see 1 here.

11 months ago

Yeah I was aware of that limitation, but thanks for confirming this doesn't quite work for you.