Pipe Visualizer 2.0

by Ashier

Visualize the layout and contents of pipe networks. Press Y to draw the selected entity's fluid systems. Press Shift + Y to draw all visible fluid systems. Press Alt + Y to automatically visualize systems on mouse-over. Press Control + Y to toggle between color-by-fluid and color-by-system.

Utilities
6 months ago
2.0
6.21K

g Making it work with ducts

a month ago
(updated a month ago)

Right now neither the builtin system nor this mod works with Fluid Must Flow's ducts because they are coded as storage tanks. Initially I tried to add the appropriate properties to their prototypes (visualization & disable_visualization) since they have all other connections but sadly storage tanks simply dont support them.

The implimentation is very minimal in "scripts/renderer.lua", albeit somewhat hardcoded. Maybe some sort of remote_interface stuff is better but I dont really know much about that. Although given the widespread use of FMF's ducts and absence of anything similar I feel like this hardcoding isn't too terrible.

Anyways, first we expand the pipe_type table around line #55:

local pipe_types = {
  ["infinity-pipe"] = true,
  ["pipe-to-ground"] = true,
  ["pipe"] = true,
  ["storage-tank"] = {
    ["duct"] = true,
    ["duct-cross"] = true,
    ["duct-curve"] = true,
    ["duct-long"] = true,
    ["duct-small"] = true,
    ["duct-t-junction"] = true,
  },
 }

 local function is_valid_pipe_entity(ent)
  local pipe_type = pipe_types[ent.type]
  if pipe_type == true then
    return pipe_type
  elseif type(pipe_type) == "table" then
    return pipe_type[ent.name]
  end
end

Then we change the access to that table at (the now) line #98

 local is_complex_type = not is_valid_pipe_entity(entity_data.entity) --pipe_types[entity_data.entity.type]

And another at line #150

        if connection.flow_direction ~= "input-output" and not is_valid_pipe_entity(connection.target_owner) then --pipe_types[connection.target_owner.type] then

Making these changes make FMF ducts work almost entirely like the PV's system (and the builtin one) for pipes with the exception they still have their storage-tank-type bounding box outlined since I dont think it can be disabled in Factorio itself.
https://gyazo.com/40e77b2d5012be2080a6e61b8e5b7775

a month ago
(updated a month ago)

Been doing some fiddling and managed to make it less hardcoded. Expanded the blacklist remote interface

local blacklist = {}

blacklist.add_remote_interface = function()
    remote.add_interface("PipeVisualizer", {
        --- @param entity_names string[]
        blacklist = function(entity_names)
            if type(entity_names) ~= "table" then
                return
            end
            for _, entity_name in pairs(entity_names) do
                storage.blacklist[entity_name] = true
            end
        end,
        --- @param entity_type string
        --- @param entity_name string
        whitelist = function(entity_type, entity_name)
            if type(entity_type) ~= "string" or type(entity_name) ~= "string" then
                return
            end
            storage.whitelist[entity_type] = storage.whitelist[entity_type] or {}
            storage.whitelist[entity_type][entity_name] = true
        end,
    })
end

---@param e ConfigurationChangedData?
local function reset(e)
    -- Blacklist has to be rebuilt on every config change
    --- @type table<UnitNumber, boolean>
    storage.blacklist = {}
    --- @type table<UnitType, table<UnitNumber, boolean>>
    storage.whitelist = {}
end

blacklist.on_init = reset
blacklist.on_configuration_changed = reset

return blacklist

And a slightly different is_valid_pipe_entity()

local function is_valid_pipe_entity(ent)
  local pipe_type = pipe_types[ent.type]
  if pipe_type == true then
    return pipe_type
  end
  if storage.whitelist[ent.type] and type(storage.whitelist[ent.type]) == "table" then
    return storage.whitelist[ent.type][ent.name]
  end
end

New response