Auto Research (updated for 1.0) deprecated

by SirTony

Automates research. Toggle GUI with Shift+T (customizable).

3 years ago
0.18 - 1.0
19

b Current code only pulls the first icons layer, which is improper...

3 years ago
(updated 3 years ago)

I suggest the following code block to replace the existing code block in data-final-fixes.lua:

-- Dynamically add sprites for tools (to display research ingredients)
for _, tool in pairs(data.raw.tool) do
    -- Setup locals
    local sprite_layers = {}

    -- Check for an icons definition
    if tool.icons then
        -- We're working with an icons definition, this may be fully defined or only partially defined, if partially defined we will fully define it for our local layer
        for _, icon_data in pairs(tool.icons) do
            table.insert(sprite_layers, {
                filename = icon_data.icon,
                size = icon_data.icon_size or tool.icon_size,
                mipmap_count = icon_data.icon_mipmaps or tool.icon_mipmaps,
                tint = icon_data.tint,
                blend_mode = icon_data.blend_mode,
                shift = icon_data.shift,
                scale = 20 / (icon_data.icon_size or tool.icon_size),
                flags = {"gui-icon"},
            })
        end
    else
        -- We're working with a standard icon, no icons table
        table.insert(sprite_layers, {
            filename = tool.icon,
            size = tool.icon_size,
            mipmap_count = tool.icon_mipmaps,
            scale = 20 / tool.icon_size,
            flags = {"gui-icon"},
        })
    end

    -- Build the sprite
    data:extend({
        {
            type = "sprite",
            name = "auto_research_tool_" .. tool.name,
            layers = sprite_layers,
        }
    })
end

This has been tested and works, will load multi-layer icons, protect against pixelation from improper scaling in the GUI, and scales the icons to a GUI-friendly size (20px is standard line height).

There are issues when you increase GUI scaling, but the current implementation has identical issues.

3 years ago

Updated the code and pushed a new version, thanks for the contribution!

New response