A Weird Imagination

Devlog: Pacifist Factorio mod PRs (2 of 3): butter slots, not gun slots

The problem#

Continuing from last week, in my work on the Pacifist Factorio mod, I wanted to remove the character's gun slots. They are always visible in the bottom-left of the screen with gun and ammo icons, making it clear there's an expectation of weapons.

The solution#

This PR, which is included in the latest version of Pacifist, replaces the icon on the slots and rewords some of the text shown in the game about them.

The details#

Gun slots1#

One of the more visible hints of violence is the gun/ammo slots in the bottom left of the screen. After determining that they cannot be removed by a mod, I posted a feature request for mods to be able to do so. I later noticed I wasn't the first to request that feature, so I don't expect it to be implemented.

As a workaround, I changed the icon to not show a gun. I searched around for references to "gun" and found slot_icon_gun, and replacing it did in fact change the icon in the bottom-left of the screen. As I wanted to reuse an existing icon if possible, I went looking in data/core/graphics for an appropriate choice and found set-bar-slot.png for showing an "X" in a slot. As described in FileName's documentation, any mod can reference files from any other mod or the core/base directories, so I was able to reuse that image by setting slot_icon_gun.filename to "__core__/graphics/set-bar-slot.png".

Not all guns are guns#

Well, that was my first iteration. The catch is that some mods add "guns" that aren't weapons, so Pacifist doesn't remove them. So those slots actually are usable. I hadn't realized this and wasn't really thinking about compatibility with other mods, but the developer of Pacifist informed me that I needed to handle that case. So I changed all of the strings referring to "guns" and "ammo" to instead talk about "tools" and "tool charges" (for lack of a better term).

Additionally, that meant I needed an icon representing a tool. Well, Factorio used to have a tool slot before the pickaxe was removed, so I opened an old install of Factorio that still had that icon and copied it over to be used for those slots when a mod was active that added tools.

Dealing with mod interactions#

In general, making mods compatible with each other is a hard problem as mods can do all kinds of things you would never think of, including, in this case, making guns that aren't weapons. Obviously, your mod should try to do as little as possible to achieve its goals to avoid getting in the way of other mods, but especially for a mod like Pacifist that changes a lot of things, that's just not an option.

Factorio provides APIs to help with making mods work well together. The most basic of which is the mods dictionary which can be used to check which other mods are loaded. For more complicated interactions, the data lifecycle is defined with multiple stages so mods have the opportunity to act at different stages to act after one part of another mod's computation while acting before another part. Dependencies can also be used to affect load order. Additionally, there's explicit documentation on working with the mod settings of another mod.

In practice, mod compatibility involves testing and having users provide bug reports when they find something that breaks because there's so many mods that you can only test compatibility with a small fraction of them.

  1. There's no actual butter slots, the title is a reference to the guns versus butter model


Have something to add? Post a comment by sending an email to comments@aweirdimagination.net. You may use Markdown for formatting.

There are no comments yet.