File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 21
21
--- Registers a safe state callback.
22
22
--- It will be called whenever the input manager is in a safe state.
23
23
--- @param callback fun ( info : mc.SafeStateInfo )
24
- function core .onSafeState (callback )
25
- inputManager :onSafeState (callback )
24
+ --- @param opts ? { once ?: boolean }
25
+ function core .onSafeState (callback , opts )
26
+ inputManager :onSafeState (callback , opts )
26
27
end
27
28
28
29
--- Registers a keymap layer callback.
Original file line number Diff line number Diff line change @@ -121,10 +121,18 @@ end
121
121
--- @field wasMode string
122
122
123
123
--- @param callback fun ( info : mc.SafeStateInfo )
124
- function InputManager :onSafeState (callback )
124
+ --- @param opts ? { once ?: boolean }
125
+ function InputManager :onSafeState (callback , opts )
125
126
if not self ._safeStateCallbacks then
126
127
self ._safeStateCallbacks = {}
127
128
end
129
+ if opts and opts .once then
130
+ local wrapped = callback
131
+ callback = function (info )
132
+ wrapped (info )
133
+ tbl .remove (self ._safeStateCallbacks , callback )
134
+ end
135
+ end
128
136
self ._safeStateCallbacks [# self ._safeStateCallbacks + 1 ] = callback
129
137
end
130
138
Original file line number Diff line number Diff line change @@ -65,6 +65,16 @@ function tbl.filter(t, callback)
65
65
return result
66
66
end
67
67
68
+ --- @generic T
69
+ --- @param t T[]
70
+ --- @param value T
71
+ function tbl .remove (t , value )
72
+ local idx = tbl .indexOf (t , value )
73
+ if idx then
74
+ table.remove (t , idx )
75
+ end
76
+ end
77
+
68
78
--- @generic T
69
79
--- @param t T[]
70
80
--- @callback fun(v: T, i: integer, t: T[]): any
You can’t perform that action at this time.
0 commit comments