418 Industries: Backgrounds

by akxcv

A background pack for Factorio

Tweaks
1 year, 4 months ago
1.1
186

i Random BG on game start?

1 year, 6 months ago

To be honest, when I added this mod, I thought it would automatically randomize which background image would show up when I started the game. Took me a few days before I realized I wasn't just getting the craziest RNG and that it wasn't changing at all. Is there any chance you could add an option to either change the background every time the game starts, or have it slideshow and change images every... 15 or 30 seconds?

1 year, 4 months ago

Hmm, as far as I remember, this wasn't possible within the current mod API. But I'll double check when I work on this mod again.

1 year, 4 months ago

Yes, with Factorio mod API, it's not currently possible to randomise values at startup - the game always returns the same value. And, as far as I know, there's no way to leverage any runtime APIs, because everything related to menu backgrounds must be done at startup.

I wish more was possible: I'm playing on a server with a friend, and we're always forced to use the same background, since startup settings must always be synced.

1 year, 4 months ago
(updated 1 year, 4 months ago)

There is a way to randomize it. You can make use of background simulations because they are garenteed to always be in random order.

So what you can do is overwrite startup simulations instead of the image location, and create on simulation for each image you have. Of course, this will create a simulation, which means a map, and not an image. But, you can use LuaRendering to draw your images on the map. For example, I use LuaRendering to draw the little Hall of Fame Emblems on the simulations in the Hall of Fame mod.

So basically something like:

-- data.lua

-- Clear vanilla simulations
data.raw["utility-constants"]["default"].main_menu_simulations = { }

-- Convenience Handle
local simulations = data.raw["utility-constants"]["default"].main_menu_simulations


for background_name, background_path in pairs(backgrounds) do
        -- Create sprites
        data:extend{
                {
                        type = background_name,
                        filename = background_path,
                        -- etc,
                }
        }

        -- Create new simulation and draw the image on the background
        simulations[background_name] = {
                init = [[
                        rendering.draw_sprite{
                                name = "]]..background_name..[[",
                                target = {0, 0},
                                -- etc
                        }

                ]]
        }
end

Note, this won't be perfect, because you'll cut of the image at different places depending on your screen size. So it will be a little trade-off, although I guess the images are always stretched or cropped to fit on different screens anyway in your current implemenation. For some information you can read this Forum Post

New response