diff --git a/big-num/bignumber.lua b/big-num/bignumber.lua index 968027b..07b5bc7 100644 --- a/big-num/bignumber.lua +++ b/big-num/bignumber.lua @@ -12,7 +12,7 @@ BigMeta.__index = Big -- -- numbers are stored in the form `m * 10 ^ e` function Big:new(m, e) - if type(m) == "table" then + if is_big(m) then return setmetatable({m = m.m, e = m.e}, BigMeta):normalized() end if e == nil then e = 0 end @@ -146,7 +146,7 @@ function Big:pow(pow) end function BigMeta.__pow(b1, n) - if type(n) == "table" then n = n:to_number() end + if is_big(n) then n = n:to_number() end if type(b1) ~= "table" then b1 = Big:new(b1) end return b1:pow(n) end diff --git a/big-num/notations/Balatro.lua b/big-num/notations/Balatro.lua index 7e7757e..8e6196f 100644 --- a/big-num/notations/Balatro.lua +++ b/big-num/notations/Balatro.lua @@ -16,7 +16,7 @@ function BalaNotation:format(n, places) --vanilla balatro number_format function basically local function e_ify(num) --if not num then return "0" end - if type(num) == "table" then + if is_big(num) then num = num:to_number() end if (num or 0) >= 10^6 then diff --git a/big-num/omeganum.lua b/big-num/omeganum.lua index 4d1ea82..a1aaa68 100644 --- a/big-num/omeganum.lua +++ b/big-num/omeganum.lua @@ -138,7 +138,7 @@ function Big:compareTo(other) elseif (self_array_size other.array[1] then return 1 * m elseif self.array[1] < other.array[1] then @@ -610,7 +610,7 @@ function Big:create(input) return Big:new({input}) elseif ((type(input) == "string")) then return Big:parse(input) - elseif ((type(input) == "table") and getmetatable(input) == OmegaMeta) then + elseif ((is_big(input)) and getmetatable(input) == OmegaMeta) then return input:clone() else return Big:new(input) @@ -618,7 +618,7 @@ function Big:create(input) end function Big:ensureBig(input) - if ((type(input) == "table") and getmetatable(input) == OmegaMeta) then + if ((is_big(input)) and getmetatable(input) == OmegaMeta) then return input else return Big:create(input) @@ -1135,7 +1135,7 @@ function Big:tetrate(other) end function Big:max_for_op(arrows) - if type(arrows) == "table" then + if is_big(arrows) then arrows = arrows:to_number() end if arrows < 1 or arrows ~= arrows or arrows == R.POSITIVE_INFINITY then @@ -1158,7 +1158,7 @@ function Big:max_for_op(arrows) local limit = math.floor(math.log(arrows, 10)) for i = 6, limit do arr[10^i] = 8 - end + end end arr[arrows - 1] = 8 diff --git a/lovely.toml b/lovely.toml index 29dbe38..200456a 100644 --- a/lovely.toml +++ b/lovely.toml @@ -173,7 +173,7 @@ pattern = "if not G.TAROT_INTERRUPT_PULSE then G.FUNCS.text_super_juice(e, math. position = "at" payload = ''' local num = 0 -if to_big(is_number(G.GAME.current_round.current_hand.mult) and G.GAME.current_round.current_hand.mult or 1) > to_big(1e300) then +if to_big(is_number(G.GAME.current_round.current_hand.mult) and G.GAME.current_round.current_hand.mult or 1) > to_big(1e300) then num = math.min(2,math.max(0,math.floor(math.log10(is_number(G.GAME.current_round.current_hand.mult) and G.GAME.current_round.current_hand.mult or 1)))) else num = 1e300 @@ -189,7 +189,7 @@ pattern = "if not G.TAROT_INTERRUPT_PULSE then G.FUNCS.text_super_juice(e, math. position = "at" payload = ''' local num = 0 -if to_big(is_number(G.GAME.current_round.current_hand.chips) and G.GAME.current_round.current_hand.chips or 1) > to_big(1e300) then +if to_big(is_number(G.GAME.current_round.current_hand.chips) and G.GAME.current_round.current_hand.chips or 1) > to_big(1e300) then num = math.min(2,math.max(0,math.floor(math.log10(is_number(G.GAME.current_round.current_hand.chips) and G.GAME.current_round.current_hand.chips or 1)))) else num = 1e300 @@ -329,10 +329,10 @@ position = "before" line_prepend = "$indent" payload = ''' if Big then - if type(self.strings[k].W) == 'table' then + if is_big(self.strings[k].W) then self.strings[k].W = to_number(self.strings[k].W) end - if type(self.strings[k].H) == 'table' then + if is_big(self.strings[k].H) then self.strings[k].H = to_number(self.strings[k].H) end end @@ -537,7 +537,7 @@ position = "at" payload = '''if to_big(card.unlock_condition.extra) <= to_big(G.GAME.dollars) then''' match_indent = true -# Talisman compat for vanilla jokers +# Talisman compat for vanilla jokers [[patches]] [patches.pattern] target = "card.lua" @@ -833,28 +833,28 @@ target = "functions/common_events.lua" pattern = "elseif eval_type == 'dollars' then" position = "before" payload = ''' -elseif eval_type == 'x_chips' then +elseif eval_type == 'x_chips' then sound = 'talisman_xchip' amt = amt text = 'X' .. amt colour = G.C.CHIPS config.type = 'fade' config.scale = 0.7 -elseif eval_type == 'e_chips' then +elseif eval_type == 'e_chips' then sound = 'talisman_echip' amt = amt text = '^' .. amt colour = G.C.CHIPS config.type = 'fade' config.scale = 0.7 -elseif eval_type == 'ee_chips' then +elseif eval_type == 'ee_chips' then sound = 'talisman_eechip' amt = amt text = '^^' .. amt colour = G.C.CHIPS config.type = 'fade' config.scale = 0.7 -elseif eval_type == 'eee_chips' then +elseif eval_type == 'eee_chips' then sound = 'talisman_eeechip' amt = amt text = '^^^' .. amt @@ -868,28 +868,28 @@ elseif eval_type == 'hyper_chips' then colour = G.C.CHIPS config.type = 'fade' config.scale = 0.7 -elseif eval_type == 'e_mult' then +elseif eval_type == 'e_mult' then sound = 'talisman_emult' amt = amt text = '^' .. amt .. ' ' .. localize('k_mult') colour = G.C.MULT config.type = 'fade' config.scale = 0.7 -elseif eval_type == 'ee_mult' then +elseif eval_type == 'ee_mult' then sound = 'talisman_eemult' amt = amt text = '^^' .. amt .. ' ' .. localize('k_mult') colour = G.C.MULT config.type = 'fade' config.scale = 0.7 -elseif eval_type == 'eee_mult' then +elseif eval_type == 'eee_mult' then sound = 'talisman_eeemult' amt = amt text = '^^^' .. amt .. ' ' .. localize('k_mult') colour = G.C.MULT config.type = 'fade' config.scale = 0.7 -elseif eval_type == 'hyper_mult' then +elseif eval_type == 'hyper_mult' then sound = 'talisman_eeemult' text = (amt[1] > 5 and ('{' .. tostring(amt[1]) .. '}') or string.rep('^', amt[1])) .. tostring(amt[2]) .. ' ' .. localize('k_mult') amt = amt[2] @@ -1274,7 +1274,7 @@ target = 'functions/misc_functions.lua' pattern = "assembled_string = assembled_string..(type(subpart) == 'string' and subpart or args.vars[tonumber(subpart[1])] or 'ERROR')" position = 'before' payload = ''' -if not SMODS and type(subpart) ~= 'string' then +if not SMODS and type(subpart) ~= 'string' then if type(args.vars[tonumber(subpart[ 1 ])]) ~= 'number' then args.vars[tonumber(subpart[ 1 ])] = tostring(args.vars[tonumber(subpart[ 1 ])]) else @@ -1443,7 +1443,7 @@ target = 'engine/sprite.lua' pattern = "G.SHADERS[_shader]:send(v.name, v.val or (v.func and v.func()) or v.ref_table[v.ref_value])" position = 'at' payload = '''local val = v.val or (v.func and v.func()) or v.ref_table[v.ref_value] -if type(val) == "table" and is_number(val) then +if is_big(val) and is_number(val) then if val > to_big(1e300) then val = 1e300 else @@ -1460,14 +1460,14 @@ target = 'functions/misc_functions.lua' pattern = "AC[k].vol = (not G.video_organ and G.STATE == G.STATES.SPLASH) and 0 or AC[k].vol and v.volfunc(AC[k].vol) or 0" position = 'after' payload = ''' -if type(AC[k].vol) == "table" then +if is_big(AC[k].vol) then if AC[k].vol > to_big(1e300) then AC[k].vol = 1e300 else AC[k].vol = to_number(AC[k].vol) end end -if type(AC[k].per) == "table" then +if is_big(AC[k].per) then if AC[k].per > to_big(1e300) then AC[k].per = 1e300 else @@ -1482,7 +1482,7 @@ match_indent = true target = 'functions/button_callbacks.lua' pattern = "_F.intensity = ((G.pack_cards and not G.pack_cards.REMOVED) or (G.TAROT_INTERRUPT)) and 0 or math.max(0., math.log(G.ARGS.score_intensity.earned_score, 5)-2)" position = 'after' -payload = '''if type(_F.intensity) == "table" then +payload = '''if is_big(_F.intensity) then if _F.intensity > to_big(1e300) then _F.intensity = 1e300 else diff --git a/talisman.lua b/talisman.lua index bfa2fee..047dbaf 100644 --- a/talisman.lua +++ b/talisman.lua @@ -160,6 +160,15 @@ G.FUNCS.talisman_upd_score_opt = function(e) nativefs.write(talisman_path .. "/config.lua", STR_PACK(Talisman.config_file)) end +function is_big(x) + return type(x) == "table" and ((x.e and x.m) or (x.array and x.sign)) +end + +function is_number(x) + return type(x) == 'number' or is_big(x) +end + + G.FUNCS.talisman_upd_notation_opt = function(e) Talisman.config_file.notation_id = e.to_key Talisman.config_file.notation_key = Talisman.notations.filenames[e.to_key] @@ -190,7 +199,7 @@ if Talisman.config_file.break_infinity then local nf = number_format function number_format(num, e_switch_point) - if type(num) == 'table' or override_non_bigs then + if is_big(num) or override_non_bigs then --num = to_big(num) if override_non_bigs then num = to_big(num) @@ -212,12 +221,12 @@ if Talisman.config_file.break_infinity then local mf = math.floor function math.floor(x) - if type(x) == 'table' then return x.floor and x:floor() or x end + if is_big(x) then return x.floor and x:floor() or x end return mf(x) end local mc = math.ceil function math.ceil(x) - if type(x) == 'table' then return x:ceil() end + if is_big(x) then return x:ceil() end return mc(x) end @@ -233,7 +242,7 @@ function lenient_bignum(x) local sns = score_number_scale function score_number_scale(scale, amt) local ret = sns(scale, amt) - if type(ret) == "table" then + if is_big(ret) then if ret > to_big(1e300) then return 1e300 end return ret:to_number() end @@ -242,7 +251,7 @@ function lenient_bignum(x) local gftsj = G.FUNCS.text_super_juice function G.FUNCS.text_super_juice(e, _amount) - if type(_amount) == "table" then + if is_big(_amount) then if _amount > to_big(1e300) then _amount = 1e300 else @@ -254,7 +263,7 @@ function lenient_bignum(x) local l10 = math.log10 function math.log10(x) - if type(x) == 'table' then + if is_big(x) then if x.log10 then return lenient_bignum(x:log10()) end return lenient_bignum(l10(math.min(x:to_number(),1e300))) end @@ -264,7 +273,7 @@ function lenient_bignum(x) local lg = math.log function math.log(x, y) if not y then y = 2.718281828459045 end - if type(x) == 'table' then + if is_big(x) then if x.log then return lenient_bignum(x:log(to_big(y))) end if x.logBase then return lenient_bignum(x:logBase(to_big(y))) end return lenient_bignum(lg(math.min(x:to_number(),1e300),y)) @@ -274,13 +283,13 @@ function lenient_bignum(x) function math.exp(x) local big_e = to_big(2.718281828459045) - + if type(big_e) == "number" then return lenient_bignum(big_e ^ x) else return lenient_bignum(big_e:pow(x)) end - end + end if SMODS then function SMODS.get_blind_amount(ante) @@ -296,9 +305,9 @@ function lenient_bignum(x) to_big(10000 + 25000*(scale+1)*((scale/4)^2)), to_big(50000 * (scale+1)^2 * (scale/7)^2) } - + if ante < 1 then return to_big(100) end - if ante <= 8 then + if ante <= 8 then local amount = amounts[ante] if (amount:lt(R.E_MAX_SAFE_INTEGER)) then local exponent = to_big(10)^(math.floor(amount:log10() - to_big(1))):to_number() @@ -324,7 +333,7 @@ function lenient_bignum(x) if G.GAME.modifiers.scaling and (G.GAME.modifiers.scaling ~= 1 and G.GAME.modifiers.scaling ~= 2 and G.GAME.modifiers.scaling ~= 3) then return SMODS.get_blind_amount(ante) end if type(to_big(1)) == 'number' then return gba(ante) end local k = to_big(0.75) - if not G.GAME.modifiers.scaling or G.GAME.modifiers.scaling == 1 then + if not G.GAME.modifiers.scaling or G.GAME.modifiers.scaling == 1 then local amounts = { to_big(300), to_big(800), to_big(2000), to_big(5000), to_big(11000), to_big(20000), to_big(35000), to_big(50000) } @@ -338,7 +347,7 @@ function lenient_bignum(x) end amount:normalize() return amount - elseif G.GAME.modifiers.scaling == 2 then + elseif G.GAME.modifiers.scaling == 2 then local amounts = { to_big(300), to_big(900), to_big(2600), to_big(8000), to_big(20000), to_big(36000), to_big(60000), to_big(100000) --300, 900, 2400, 7000, 18000, 32000, 56000, 90000 @@ -353,7 +362,7 @@ function lenient_bignum(x) end amount:normalize() return amount - elseif G.GAME.modifiers.scaling == 3 then + elseif G.GAME.modifiers.scaling == 3 then local amounts = { to_big(300), to_big(1000), to_big(3200), to_big(9000), to_big(25000), to_big(60000), to_big(110000), to_big(200000) --300, 1000, 3000, 8000, 22000, 50000, 90000, 180000 @@ -391,7 +400,7 @@ function lenient_bignum(x) if not G.PROFILES[G.SETTINGS.profile].career_stats[stat] then G.PROFILES[G.SETTINGS.profile].career_stats[stat] = 0 end G.PROFILES[G.SETTINGS.profile].career_stats[stat] = G.PROFILES[G.SETTINGS.profile].career_stats[stat] + (mod or 0) -- Make sure this isn't ever a talisman number - if type(G.PROFILES[G.SETTINGS.profile].career_stats[stat]) == 'table' then + if is_big(G.PROFILES[G.SETTINGS.profile].career_stats[stat]) then if G.PROFILES[G.SETTINGS.profile].career_stats[stat] > to_big(1e300) then G.PROFILES[G.SETTINGS.profile].career_stats[stat] = to_big(1e300) elseif G.PROFILES[G.SETTINGS.profile].career_stats[stat] < to_big(-1e300) then @@ -437,7 +446,7 @@ function lenient_bignum(x) local tsj = G.FUNCS.text_super_juice function G.FUNCS.text_super_juice(e, _amount) - if type(_amount) == 'table' then + if is_big(_amount) then if _amount > to_big(2) then _amount = 2 end else if _amount > 2 then _amount = 2 end @@ -448,7 +457,7 @@ function lenient_bignum(x) local max = math.max --don't return a Big unless we have to - it causes nativefs to break function math.max(x, y) - if type(x) == 'table' or type(y) == 'table' then + if is_big(x) or is_big(y) then x = to_big(x) y = to_big(y) if (x > y) then @@ -461,7 +470,7 @@ function lenient_bignum(x) local min = math.min function math.min(x, y) - if type(x) == 'table' or type(y) == 'table' then + if is_big(x) or is_big(y) then x = to_big(x) y = to_big(y) if (x < y) then @@ -474,18 +483,18 @@ function lenient_bignum(x) local sqrt = math.sqrt function math.sqrt(x) - if type(x) == 'table' then + if is_big(x) then if getmetatable(x) == BigMeta then return x:sqrt() end if getmetatable(x) == OmegaMeta then return x:pow(0.5) end end return sqrt(x) end - + local old_abs = math.abs function math.abs(x) - if type(x) == 'table' then + if is_big(x) then x = to_big(x) if (x < to_big(0)) then return -1 * x @@ -496,12 +505,6 @@ function lenient_bignum(x) end end -function is_number(x) - if type(x) == 'number' then return true end - if type(x) == 'table' and ((x.e and x.m) or (x.array and x.sign)) then return true end - return false -end - function to_big(x, y) if type(x) == 'string' and x == "0" then --hack for when 0 is asked to be a bignumber need to really figure out the fix return 0 @@ -528,7 +531,7 @@ function to_big(x, y) end end function to_number(x) - if type(x) == 'table' and (getmetatable(x) == BigMeta or getmetatable(x) == OmegaMeta) then + if is_big(x) and (getmetatable(x) == BigMeta or getmetatable(x) == OmegaMeta) then return x:to_number() else return x @@ -695,7 +698,7 @@ if not Talisman.F_NO_COROUTINE then G.SCORING_TEXT = nil if not G.OVERLAY_MENU then G.scoring_text = {localize("talisman_string_D"), "", "", ""} - G.SCORING_TEXT = { + G.SCORING_TEXT = { {n = G.UIT.C, nodes = { {n = G.UIT.R, config = {padding = 0.1, align = "cm"}, nodes = { {n=G.UIT.O, config={object = DynaText({string = {{ref_table = G.scoring_text, ref_value = 1}}, colours = {G.C.UI.TEXT_LIGHT}, shadow = true, pop_in = 0, scale = 1, silent = true})}}, @@ -715,8 +718,8 @@ if not Talisman.F_NO_COROUTINE then })}}, }}} G.FUNCS.overlay_menu({ - definition = - {n=G.UIT.ROOT, minw = G.ROOM.T.w*5, minh = G.ROOM.T.h*5, config={align = "cm", padding = 9999, offset = {x = 0, y = -3}, r = 0.1, colour = {G.C.GREY[1], G.C.GREY[2], G.C.GREY[3],0.7}}, nodes= G.SCORING_TEXT}, + definition = + {n=G.UIT.ROOT, minw = G.ROOM.T.w*5, minh = G.ROOM.T.h*5, config={align = "cm", padding = 9999, offset = {x = 0, y = -3}, r = 0.1, colour = {G.C.GREY[1], G.C.GREY[2], G.C.GREY[3],0.7}}, nodes= G.SCORING_TEXT}, config = {align="cm", offset = {x=0,y=0}, major = G.ROOM_ATTACH, bond = 'Weak'} }) else @@ -741,9 +744,9 @@ if not Talisman.F_NO_COROUTINE then --event queue overhead seems to not exist if Talismans Disable Scoring Animations is off. --event manager has to wait for scoring to finish until it can keep processing events anyways. - + G.LAST_SCORING_YIELD = love.timer.getTime() - + local success, msg = coroutine.resume(G.SCORING_COROUTINE) if not success then error(msg)