Page 1 of 1

Direction information of the player cursor

Posted: Wed Jun 15, 2022 12:30 am
by Gweneph
I'm trying to read and/or write the direction of the cursor (for building an entity) but I haven't found any api to do so.

I thought I might have a clever workaround by pipetting an entity that has the desired orientation with LuaPlayer.pipette_entity, but unfortunately, the direction is not taken from the pipetted entity despite that happening when a player does so with q. This does seem like a bit of bug as the API says
Invokes the "smart pipette" action on the player as if the user pressed it.
Then I figured I might be able to keep track of the rotation by tracking when the player rotates, shift rotates, with something rotatable in their cursor, or pipettes something, but unfortunately the on_player_pipette event only includes the LuaItemProtoype, which doesn't contain any direction information.

So then I checked out the tips and tricks simulations, because they have to rotate the build cursor programmatically, and it turns out they use game.camera_player_cursor_direction but this property only seems to be available in simulations not in the main game.

So I would like some way to read or write the direction of the player cursor? If not, could one be added?

As for justification, it's for a mod that's working to allow players with limited to no vision to play by speaking the required information. We already have building and rotation working with accessible speech, but we're working around the system and, as a result, the gui preview doesn't match what happens. This would make playing with low vision or with sighted assist confusing, and make multiplayer with sighted folks untenable.

Re: Direction information of the player cursor

Posted: Sat Oct 29, 2022 4:10 am
by Anfilt
I would also like to add this would be quite helpful to have. For something I am working on this would be quite handy as well. Trying to figure out some way to work around the cursor being such a black box right now. Other than the cursor stack.

Re: Direction information of the player cursor

Posted: Sun Nov 10, 2024 12:23 am
by MrGrim
I also have a use for this. If you alter what's in the cursor in the on_pre_built event then what gets built will be altered, but I cannot control the direction. Right now I think I can work around it by putting a place holder simple entity item in the cursor then destroy the resulting entity in the subsequent on_built_entity event and rebuild what I need in the right direction but that's a bit prone to problems.

Alternatively if the on_pre_built even had some method to cancel the build I could just create what I need there.

Re: Direction information of the player cursor

Posted: Thu Dec 12, 2024 9:51 pm
by ownlyme
i just wondered the same thing.
i'm using the rotation keybind for cycling between variations of my turret (in the cursor stack/cursor ghost), but it feels weird that they keep rotating while doing that

Re: Direction information of the player cursor

Posted: Mon Dec 23, 2024 12:16 am
by braxbro
MrGrim wrote: Sun Nov 10, 2024 12:23 am I also have a use for this. If you alter what's in the cursor in the on_pre_built event then what gets built will be altered, but I cannot control the direction. Right now I think I can work around it by putting a place holder simple entity item in the cursor then destroy the resulting entity in the subsequent on_built_entity event and rebuild what I need in the right direction but that's a bit prone to problems.

Alternatively if the on_pre_built even had some method to cancel the build I could just create what I need there.
If you clear the cursor stack iirc it will cancel the build…? I can’t remember perfectly, but I remember at some point Spaghettorio was doing some nonsense with the cursor stack in pre_build before I found a better solution.

Re: Direction information of the player cursor

Posted: Mon Dec 30, 2024 8:50 pm
by Rseding91
Gweneph wrote: Wed Jun 15, 2022 12:30 am I'm trying to read and/or write the direction of the cursor (for building an entity) but I haven't found any api to do so.
This is because it's not part of the game state and so is not available to mods. If that changes some day, then we will add the Lua API. But, until then, this is a won't-implement.

Re: Direction information of the player cursor

Posted: Mon Dec 30, 2024 9:31 pm
by curiosity
Rseding91 wrote: Mon Dec 30, 2024 8:50 pm This is because it's not part of the game state and so is not available to mods. If that changes some day, then we will add the Lua API. But, until then, this is a won't-implement.
Could you perhaps include it into the action? That gets sent over the network anyway. Then mods will be able to get it on custom input. Seems like it would solve the OP's problem, too.

Re: Direction information of the player cursor

Posted: Mon Dec 30, 2024 9:37 pm
by boskid
curiosity wrote: Mon Dec 30, 2024 9:31 pm Could you perhaps include it into the action? That gets sent over the network anyway. Then mods will be able to get it on custom input. Seems like it would solve the OP's problem, too.
https://lua-api.factorio.com/2.0.28/eve ... InputEvent already contains `cursor_position` that is raised for custom inputs with lua action.

Re: Direction information of the player cursor

Posted: Mon Dec 30, 2024 11:31 pm
by curiosity
boskid wrote: Mon Dec 30, 2024 9:37 pm https://lua-api.factorio.com/2.0.28/eve ... InputEvent already contains `cursor_position` that is raised for custom inputs with lua action.
Exactly. So it could have cursor rotation as well.