mirror of
https://github.com/ershisan99/Fantoms-Preview.git
synced 2025-12-16 20:49:23 +00:00
52 lines
1.5 KiB
Lua
52 lines
1.5 KiB
Lua
--- Divvy's Preview for Balatro - Utils.lua
|
|
--
|
|
-- Utilities for checking states and formatting display.
|
|
|
|
function DV.PRE.is_enough_to_win(chips)
|
|
if G.GAME.blind and
|
|
(G.STATE == G.STATES.SELECTING_HAND or
|
|
G.STATE == G.STATES.DRAW_TO_HAND or
|
|
G.STATE == G.STATES.PLAY_TAROT)
|
|
then return (G.GAME.chips + chips >= G.GAME.blind.chips)
|
|
else return false
|
|
end
|
|
end
|
|
|
|
function DV.PRE.format_number(num)
|
|
if not num or type(num) ~= 'number' then return num or '' end
|
|
-- Start using e-notation earlier to reduce number length, if showing min and max for preview:
|
|
if G.SETTINGS.DV.show_min_max and num >= 1e7 then
|
|
local x = string.format("%.4g",num)
|
|
local fac = math.floor(math.log(tonumber(x), 10))
|
|
return string.format("%.2f",x/(10^fac))..'e'..fac
|
|
end
|
|
return number_format(num) -- Default Balatro function.
|
|
end
|
|
|
|
function DV.PRE.get_dollar_colour(n)
|
|
if n == 0 then return HEX("7e7667")
|
|
elseif n > 0 then return G.C.MONEY
|
|
elseif n < 0 then return G.C.RED
|
|
end
|
|
end
|
|
|
|
function DV.PRE.get_sign_str(n)
|
|
if n >= 0 then return "+"
|
|
else return "" -- Negative numbers already have a sign
|
|
end
|
|
end
|
|
|
|
function DV.PRE.enabled()
|
|
return G.SETTINGS.DV.preview_score or G.SETTINGS.DV.preview_dollars
|
|
end
|
|
|
|
function clean_hand(hand)
|
|
local clean_hand = {}
|
|
for _, v in pairs(hand) do
|
|
if v.get_id then -- Should work for all functions even if they don't use get_id because get_id is a meta function and the broken cards don't have meta values
|
|
table.insert(clean_hand, v)
|
|
end
|
|
end
|
|
return clean_hand
|
|
end
|