z_mirror/CursorEnhancements

git clone https://git.raiguard.me/z_mirror/CursorEnhancements

Caleb HeuerMove scripts into a scripts subfolderb4ff864

smart-quickbar
1001 B45 linesraw
1local util = require("__CursorEnhancements__/scripts/util")
2
3--- @param e EventData.CustomInputEvent
4local function on_recall_last_item(e)
5  local player = game.get_player(e.player_index)
6  if not player then
7    return
8  end
9
10  local last_item = global.last_item[e.player_index]
11  if not last_item then
12    return
13  end
14
15  util.set_cursor(player, last_item)
16end
17
18--- @param e EventData.on_player_cursor_stack_changed
19local function on_player_cursor_stack_changed(e)
20  local player = game.get_player(e.player_index)
21  if not player then
22    return
23  end
24
25  local item = util.get_cursor_item(player)
26  if not item then
27    return
28  end
29
30  global.last_item[e.player_index] = item
31end
32
33local recall_last_item = {}
34
35recall_last_item.on_init = function()
36  --- @type table<uint, string?>
37  global.last_item = {}
38end
39
40recall_last_item.events = {
41  ["cen-recall-last-item"] = on_recall_last_item,
42  [defines.events.on_player_cursor_stack_changed] = on_player_cursor_stack_changed,
43}
44
45return recall_last_item