z_mirror/RateCalculator

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

Caleb HeuerMerge branch 'RateCalculator'1c882db

trunk
922 B34 linesraw
1local gui = require("scripts.gui")
2
3--- @param e EventData.CustomInputEvent|EventData.on_lua_shortcut
4local function on_shortcut(e)
5  local name = e.input_name or e.prototype_name
6  if name ~= "rcalc-get-selection-tool" then
7    return
8  end
9  local player = game.get_player(e.player_index)
10  if not player then
11    return
12  end
13  local cursor_stack = player.cursor_stack
14  if cursor_stack and cursor_stack.valid_for_read and cursor_stack.name == "rcalc-selection-tool" then
15    local self = storage.gui[e.player_index]
16    if self and self.elems.rcalc_window.valid then
17      gui.show(self)
18    end
19    return
20  end
21  if not cursor_stack or not player.clear_cursor() then
22    return
23  end
24  cursor_stack.set_stack({ name = "rcalc-selection-tool", count = 1 })
25end
26
27local shortcut = {}
28
29shortcut.events = {
30  [defines.events.on_lua_shortcut] = on_shortcut,
31  ["rcalc-get-selection-tool"] = on_shortcut,
32}
33
34return shortcut