LuaAPI: player.open_map allow to follow entity

User avatar
BrainGamer_
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Sun Nov 14, 2021 9:52 pm
Contact:

LuaAPI: player.open_map allow to follow entity

Post by BrainGamer_ »

TL;DR
I would like to be able to have a mod open the map view that follows an entity (like the train overview GUI can).

What ?
Currently we can only open the map view at a specified position (+ optional zoom level) by using player.open_map(position, zoom)
My sugggestion is to extend this to also allow for passing a LuaEntity to follow in the map view identical to how trains can be followed.
Why ?
I am making a GUI for Constructron-Continued which should/will behave very similar to the train overview GUI.
At the moment it is not really possible to implement the same behaviour when clicking the minimap of each entity like in the train GUI.
Attachments
current WIP state of the GUI I am developing
current WIP state of the GUI I am developing
factorio_ghxHQ0y8lL.png (310.97 KiB) Viewed 1716 times

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

Re: LuaAPI: player.open_map allow to follow entity

Post by Pi-C »

BrainGamer_ wrote:
Sun Dec 11, 2022 2:46 am
Currently we can only open the map view at a specified position (+ optional zoom level) by using player.open_map(position, zoom)
My sugggestion is to extend this to also allow for passing a LuaEntity to follow in the map view identical to how trains can be followed.
That should work already: see here.

EDIT: After cleaning my glasses, I've noticed the "player.open_map" part. That's actually something different! player.open_map will open the real map (the thing you get by pressing <M> in the game) while the minimap is part of a GUI. The GUI element is limited in size and you can't zoom in as much as in real map view. However, it has a huge advantage: player.open_map will only work if the entity you want to watch is on the same surface as the player, while the minimap allows you to watch entities that are on another surface.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
BrainGamer_
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Sun Nov 14, 2021 9:52 pm
Contact:

Re: LuaAPI: player.open_map allow to follow entity

Post by BrainGamer_ »

Yes it is somewhat possible to emulate the map view by using a camera and minimap LuaGuiElement but getting that to behave correctly to player inputs (panning, zooming, using remotes, building blueprints) is either really hard and janky or even not possible at all.

I didn’t know that the Map only works on the current surface the player is standing on but I guess that makes sense. Getting around this limitation will be a lot easier tho (teleporting the player to the surface you want to open the map for temporarily) or player.open_map could even be extended to also allow passing along a surface index / name.

On another note: I didn‘t realize that there is an additional suggestions forum for modding / interface suggestions and that there is already a similar request (that didn‘t appear when I searched for it before posting this): viewtopic.php?t=72351

User avatar
Wiwiweb
Long Handed Inserter
Long Handed Inserter
Posts: 76
Joined: Sat May 08, 2021 2:36 am
Contact:

Re: LuaAPI: player.open_map allow to follow entity

Post by Wiwiweb »

+1 though I'd also love to have a way to get what entity is currently being followed by the camera.

My use case is that if a player's camera is following a train, and the train goes through Space Exploration's elevator, we could have the camera continue following the "new" train for a seamless transition.

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

Re: LuaAPI: player.open_map allow to follow entity

Post by Pi-C »

BrainGamer_ wrote:
Sun Dec 11, 2022 11:37 am
Yes it is somewhat possible to emulate the map view by using a camera and minimap LuaGuiElement but getting that to behave correctly to player inputs (panning, zooming, using remotes, building blueprints) is either really hard and janky or even not possible at all.
Right, in real map view, you can zoom in much more, so that the view would change from "minimap view" (where things are indicated by symbols, e.g. a triangle for cars) to "camera view" (where you can see the real entities). A minimap doesn't support this.
I didn’t know that the Map only works on the current surface the player is standing on but I guess that makes sense. Getting around this limitation will be a lot easier tho (teleporting the player to the surface you want to open the map for temporarily) or player.open_map could even be extended to also allow passing along a surface index / name.
Teleporting the player to the right surface could be a problem if you want to emulate map view for several entities at once. Not sure if the player would have to be on the entity's surface just when the map is initialized. I suspect (but haven't tried out yet) that the map view will always focus the surface the player currently is on. If this really is the case, just priming the camera with something like

Code: Select all

local old_surface = player.surface
if entity.surface ~= old_surface then
	player.teleport(player.position, entity.surface)
	player.open_map(entity.position, scale)
	player.teleport(player.position, old_surface)
end
wouldn't be enough. Especially if you want to keep watching an entity while building something on another surface, continuously teleporting the player and/or player.character wouldn't be ideal.

By the way, I'd be glad myself if player.open_map would get an additional (possibly optional) parameter for the surface, so +1 for that! :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

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

Re: LuaAPI: player.open_map allow to follow entity

Post by Pi-C »

Wiwiweb wrote:
Tue Dec 13, 2022 3:28 am
+1 though I'd also love to have a way to get what entity is currently being followed by the camera.
While there is only one map per player that can be used with player.open_map(), each player may have multiple minimap or camera GUI elements opened simultaneously. If you have a camera, you can access camera.entity (read/write). However, there is no guarantee that camera.entity exists; the camera could have been used with camera.position to focus a fixed location, or camera.entity may have become invalid.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
BrainGamer_
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Sun Nov 14, 2021 9:52 pm
Contact:

Re: LuaAPI: player.open_map allow to follow entity

Post by BrainGamer_ »

Pi-C wrote:
Tue Dec 13, 2022 6:30 am
By the way, I'd be glad myself if player.open_map would get an additional (possibly optional) parameter for the surface, so +1 for that! :-)
This has also been requested apparently. Seems unlikely to happen but one can hope :)

viewtopic.php?t=68105

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5221
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: LuaAPI: player.open_map allow to follow entity

Post by Klonan »

BrainGamer_ wrote:
Sun Dec 11, 2022 2:46 am
I would like to be able to have a mod open the map view that follows an entity (like the train overview GUI can).
Thank you for the request,
I have added it for the next release

Code: Select all

- Added 'entity' to LuaPlayer::open_map and LuaPlayer::zoom_to_world, which specifies an entity to follow.

Post Reply

Return to “Implemented mod requests”