Page 1 of 1

Allow mods BP orders to be undo-able!

Posted: Sat May 04, 2019 9:21 pm
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.

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

Posted: Mon Dec 21, 2020 5:35 am
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.

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

Posted: Mon Apr 26, 2021 5:10 pm
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.

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

Posted: Mon May 03, 2021 12:49 pm
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.

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

Posted: Thu Dec 09, 2021 8:42 am
by Anachrony

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

Posted: Fri Nov 25, 2022 7:32 am
by Optera
+1 (yearly bump)

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