What?
A selection tool that can only exist in the cursor_stack.
Whaat?
In a recent FFF you mentioned that 0.17 will have a copy/paste functionality that does not require an item. I'd like to have this functionality for mods too, to be able to select an area and trigger an event on selection without cluttering up the inventory with numerous selection tools.
Current problems/Possible Implementations:
While it is currently possible to put a "selection-tool" into the players cursor when a custom hotkey is pressed there is no way to ensure that they don't drop it on the floor/put it in a chest/etcpp. So a property for selection tools like cursor_only = true that automatically destroys the tool when it leaves the cursor stack should work. (I don't care if it's an actual selection tool or something else, as long as it works :).
Usecase:
I'm trying to update my old mod ScreenshotHotkey to use a selection-tool that only exists while it is in use.
Volatile selection tool (cursor-only).
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Volatile selection tool (cursor-only).
Would be useful for many cases
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Volatile selection tool (cursor-only).
Just for the record, i did a partial solution for 0.16, if i wanted it perfect there's at least 6 different places to check every time the cursor changes.
Code: Select all
script.on_event({'er:controls:clean-cursor', --must work when inventory full!
defines.events.on_player_cursor_stack_changed}, function(e)
local player,pindex,pgui = get_player_data(e)
local camera_settings = get_camera_settings(pindex)
--prevent deleting in the same tick it is created
if camera_settings.camera_tick == e.tick then return end
--clean cursor stack
if player.cursor_stack.valid_for_read
and (player.cursor_stack.name == selection_tool_name)
then player.cursor_stack.clear() end
--clean opened entitiy
if player.opened and (player.opened_gui_type == defines.gui_type.entity) then
player.opened.remove_item{name=selection_tool_name,count=4e9}
end
--clean player inventories (main+toolbar)
player.remove_item{name=selection_tool_name,count=4e9}
--clean player trash slots
local trash = player.get_inventory(defines.inventory.player_trash)
if trash then
trash.remove{name=selection_tool_name,count=4e9}
end
--clean items with inventory?
--catch item dropped on belt?
end)
I'll take that as a "yes" and am looking forward to 0.17 :p.Klonan wrote:Would be useful for many cases
Re: Volatile selection tool (cursor-only).
Its added in 0.17 now as a flag, e.g:
Code: Select all
flags = {"only-in-cursor"}
- eradicator
- Smart Inserter
- Posts: 5211
- Joined: Tue Jul 12, 2016 9:03 am
- Contact:
Re: Volatile selection tool (cursor-only).
Wohoo! Lots of ugly code i can remove on my side when it comes :D.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Re: Volatile selection tool (cursor-only).
holy crap this is super useful for my RTS mod concept as well!