Allow mods BP orders to be undo-able!

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Allow mods BP orders to be undo-able!

Post by Qon »

TL;DR
When a mod orders a bp or deconstruction the undo queue doesn't undo the action, even if a player was supplied in the call as "the player that did it". If the order was added to the undo-stack (as an option) then CTRL+Z should undo the order.
What?
The code

Code: Select all

p.selected.order_deconstruction(p.force, p)
is one such example. I want to run this code whenever the player is mining something as an example so that you can just sweep over things and have bots deconstruct them instead of manually waiting for each item to be picked up. This is clearly a user-initiated deconstruction order, but it's done by a mod on behalf of a user that made some input. This works pretty great (at least with long reach mod also, I would like to order my bots outside my reach too) but the actions suddenly becomes non-undo-able... It's quite jarring once you got used to relying on undo. It's such a great feature that mods that don't work with undo become not worth it regardless of how great their features are.
Other examples:
A mod "blueprint alignment" can force blueprints to be placed aligned to a configurable grid for each blueprint. This is amazing for chunk-sized blueprints you want to place in a neat row and makes long walls and rails and lots of other things much simpler and faster. But any blueprint order that is modified by the mod can't be undone because of the API limitations. Once the mod acts to help you the game sees it as if it's not the player that ordered the action.

The mod "Recursive Blueprints" can place blueprints commanded by circuit network (It should definitely be a vanilla feature though, automating placing blueprints is the most fun and Factorio-ish thing possible). Sometimes a circuit might order a blueprint or deconstruction based on some calculation without player involvement and then it makes sense that the player that doesn't know about the placement doesn't undo the blueprint deployers actions when he uses undo to undo what he himself just did. But in other cases, the player might press a pushbutton to tell the circuit to initiate some blueprint orders. The combinator circuit, built by the player, could then supply a "add to player undo queue"-signal on the wire when it orders the construction and the mod (or vanilla feature when it's added) would detect this and supply the "add to players undo queue" argument to the API call in those cases.
Let us modify undo stack.
Another related and modified version of the request would be to allow mods to also modify what's on the undo-stack. Things like if you mine 2 times in a row within a second then instead of adding a new entry in the undo stack the mod adds the action to the topmost entry so that the undo action will undo both deconstructions.
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
smcpeak
Burner Inserter
Burner Inserter
Posts: 9
Joined: Tue Dec 05, 2017 7:50 am
Contact:

Re: Allow mods BP orders to be undo-able!

Post by smcpeak »

+1

I'm working on a mod that adds a form of deconstruction planner that analyzes a portion of the factory to find unused entities and marks them for deconstruction. It would be very convenient if the user could undo this action, but the API offers no way to accomplish that.

Furthermore, I think users would expect to be able to undo commands created this way, since it is meant to work similar to the deconstruction planner; but in fact if the user does hit Ctrl+Z, they will undo whatever was the most recent undo-able action, which could have been a long time ago, thus breaking their factory without any clear indication that something even happened. Consequently, just being able to clear the undo stack would be an improvement since then I could limit the damage to mere inconvenience.

@Qon, I suggest adjusting the title of this post to spell out "blueprint" (instead of "BP") and add "deconstruction" to make it easier for people to see what this request is about.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Allow mods BP orders to be undo-able!

Post by eradicator »

+∞

After two years of vanilla-undo mods are still second-class citizens. @Qon: Btw you can now use LuaPlayer.build_from_cursor() to at least partially get something undoable.

Related topics:
LuaPlayer.build_history [RW]. A way to read and edit the undo queue, Collect undo-able actions from the same tick into one action.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Allow mods BP orders to be undo-able!

Post by Qon »

eradicator wrote: Mon Apr 26, 2021 5:10 pm @Qon: Btw you can now use LuaPlayer.build_from_cursor() to at least partially get something undoable.
Thanks for sharing :)
Might require some horrible hacks that break other things and only works for some mods with awkward interaction but that could at least be something.
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Anachrony
Fast Inserter
Fast Inserter
Posts: 143
Joined: Thu Sep 21, 2017 10:55 pm
Contact:

Re: Allow mods BP orders to be undo-able!

Post by Anachrony »

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2920
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Allow mods BP orders to be undo-able!

Post by Optera »

+1 (yearly bump)

Would be nice to have undo work with script controlled entities and their circuit connections.
Post Reply

Return to “Modding interface requests”