Event for expired/destroyed renderings

Coming soon!
Post Reply
Pi-C
Smart Inserter
Smart Inserter
Posts: 1703
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Event for expired/destroyed renderings

Post by Pi-C »

What?
I wonder if there is a chance to get an event that's raised when a LuaRendering expires (time_to_live runs out; I realize that time_to_live == 0 is a special case where the rendering will persist forever) or is removed with destroy().

This could be achieved with one catch-all event, or two separate events (e.g. on_rendering_expired and on_rendering_destroyed).
Why?
Being able to respond to events would make it easier for mods to schedule things. This is relevant for mods that want to do several things at once when a rendering becomes invalid, or for different mods that keep track of the same rendering.
Use case
In GCKI, players can claim vehicles, which will then be put on their GUI. The GUI contains a button opening a new GUI with a "camera" element focusing on the vehicle.

When a vehicle is destroyed or mined by another player, I leave a rendered text message at the position of the removed vehicle. This rendering is only visible to the owner of the vehicle and will expire after a certain time (depending on a per-player setting). If the player is leaving the game before the rendering has expired, I store the remaining time_to_live in my global table and set the rendering's time_to_live to 0, thus making it non-expirable. When the player joins again, I set the time_to_live to the stored value. This way, players will have a chance to see the message even if they log off immediately after the vehicle has been removed and return after the rendering would normally have been expired.

While the vehicle will be removed from GUIs, the camera GUI will be kept open (with focus changed from entity to position). Currently, I use on_nth_tick to close camera GUIs that focus on the position of an expired rendering. However, it would be much nicer if the GUI would be closed immediately after the rendering has expired. I probably could add another scheduler by using on_pre_player_left_game, on_player_joined_game, and on_tick. However, there may be still more things I want to do: For example, if the removed vehicle is on camera in my associated mod Autodrive, that camera view should also persist until GCKI's rendered message expires. This would require yet another scheduler.

From my point of view, the easiest thing would be to only schedule the rendering itself in GCKI, and then close camera view in response to an event raised by the expired rendering. Alas, the problem is that we don't have such an event yet. Would you consider adding it, please? :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2323
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Event for expired/destroyed renderings

Post by boskid »

This is now implemented for 2.0. Objects from LuaRendering will be provided as LuaRenderObject (viewtopic.php?p=591699#p591699) and those objects are one of supported types for a "register_on_object_destroyed".

Pi-C
Smart Inserter
Smart Inserter
Posts: 1703
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Event for expired/destroyed renderings

Post by Pi-C »

Thank you! I think that would be useful. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

Post Reply

Return to “Implemented for 2.0”