factoriolib / flib

A set of high-quality, commonly-used utilities for creating Factorio mods.
https://mods.factorio.com/mod/flib
MIT License
64 stars 15 forks source link

Contributions from robot256lib #12

Closed robot256 closed 3 years ago

robot256 commented 4 years ago

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:

raiguard commented 4 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.

robot256 commented 4 years ago

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.

0ptera commented 4 years ago

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.

raiguard commented 4 years ago

Could you roll your code into flib-style modules, add documentation, and create a pull request? Then we can collaborate and talk about specifics.

robot256 commented 4 years ago

Okay, sounds good. I'll give it a shot when I have time. I have been spending some time away from Factorio lately.

raiguard commented 3 years ago

Are you still interested in merging in your library?

robot256 commented 3 years ago

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.