Improve versatility of the 'f' export

This commit is contained in:
Emik 2026-02-13 22:31:25 +01:00
parent 87726989d0
commit 6279ccc7a8
Signed by: emik
GPG key ID: 6B0CD72A5E503BDF
2 changed files with 20 additions and 7 deletions

View file

@ -66,8 +66,25 @@ local _ = luaf._proto
---@param f_pairs? fun(t: table): unknown ---@param f_pairs? fun(t: table): unknown
---@param numeric boolean? ---@param numeric boolean?
---@return Query ---@return Query
---@overload fun(obj: true): (fun(): true)
---@overload fun(obj: false): (fun(): false)
---@overload fun(obj: string): (fun(any): any)
local function f(obj, f_pairs, numeric) local function f(obj, f_pairs, numeric)
return f_pairs and luaf.from(obj, f_pairs, numeric ~= false) or (obj[1] and luaf.ipairs(obj) or luaf.pairs(obj)) if obj == true then
return luaf.tru
elseif obj == false then
return luaf.fals
elseif type(obj) == "string" then
return luaf.index(obj)
elseif type(obj) ~= "table" then
error("Invalid argument type for f's obj: " .. type(obj))
elseif f_pairs then
return luaf.from(obj, f_pairs, numeric ~= false)
elseif obj[#obj] then
return luaf.ipairs(obj)
else
return luaf.pairs(obj)
end
end end
--- Queues an event to be run. --- Queues an event to be run.

View file

@ -23,12 +23,8 @@ SMODS.Seal {
local tag = Tag(get_next_tag_key "Roland_glass") local tag = Tag(get_next_tag_key "Roland_glass")
if tag.name == "Orbital Tag" then if tag.name == "Orbital Tag" then
tag.ability.orbital_hand = pseudorandom_element( local hands = f(G.GAME.hands):filter(f "visible"):keys():into()
f(G.GAME.hands):filter(function(v) tag.ability.orbital_hand = pseudorandom_element(hands, pseudoseed "Roland_glass")
return v.visible
end):keys():into(),
pseudoseed "Roland_glass"
)
end end
add_tag(tag) add_tag(tag)