Closed robot256 closed 3 years ago
Sorry for the delay, I am terrible at time management so haven't looked here in a while.
May I ask, what are the usecases for these functions? I would like to include them but I don't think they are suitable as-is.
I do think save_restore's functionality is nice and useful.
I maintain three mods that all rely on occasionally changing rolling stock prototype parameters during the game. I do this by silently destroying an entity of one type and creating an entity of a different type in its place. I made one function that can handle all types of rolling stock to simplify code maintenance. If that's too specific to include then I understand.
Only one variant of each is actually craftable. Blueprint_replacement includes functions to detect when a blueprint is created that includes a non-craftable variant, and silently replaces it with the craftable version. This is the same behavior you need if a structure has a "placer" item that gets replace by a different building entity after a player places it. I've given this code to several other modders when I find that pressing Q in cheat mode gives an item you should not be able to hold.
Save_restore_lib is used to preserve properties and contents of the entity between when the old one is destroyed and the new one is created. I also use it to save the contents of vehicles when they are "loaded" on a vehicle wagon.
blueprint and pipette replacement certainly could be helpful.
save restore could do with a better name "entity_serializer" comes to mind.
replacing rolling stock would fit well next to rotate_carriage. Disregard merging, rotate should not change the entity.
Could you roll your code into flib-style modules, add documentation, and create a pull request? Then we can collaborate and talk about specifics.
Okay, sounds good. I'll give it a shot when I have time. I have been spending some time away from Factorio lately.
Are you still interested in merging in your library?
I was kind of waiting for 1.1 to come out before diving back into the code. I guess I should start on this if I want it to be released at the same time.
I'll close this issue and make a pull request when I have something to discuss.
Great project here! I'd love to help out. There are some things in my library that could be useful if they're not too complicated (or trivial) to include:
blueprint_replacement: Handlers for OnPlayerSetupBlueprint and OnPlayerPipette to make sure unplaceable entities are converted to placeable entities when pipetted or blueprinted.
save_restore: Functions to serialize and deserialize LuaInventory, LuaBurner, LuaEquipmentGrid, LuaItemRequestProxy objects into Lua tables, and to spill arbitrary inventories on the ground.
carriage_replacement: Single function to swap one rolling stock entity for another, preserving as many attributes as possible. Supports exchanging entities of different types.