From 18e763be3575ca30e0b3db814536afca1ce2650d Mon Sep 17 00:00:00 2001 From: Emik Date: Fri, 19 Jun 2026 19:01:57 +0200 Subject: [PATCH] Aggressively inline all uses of _G --- .vscode/settings.json | 4 ++++ manifest.json | 2 +- src/back.lua | 5 ++--- src/blind.lua | 25 +++++++++++++------------ src/lib/intellisense.lua | 37 ++++++++++++++++++++++++++----------- src/lib/shared.lua | 5 ++--- src/main.lua | 4 ++-- src/tweaks.lua | 14 +++++++------- 8 files changed, 57 insertions(+), 39 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5e810dd..c9682ce 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -65,4 +65,8 @@ "unused-local": "Error", "unused-vararg": "Error", }, + "Lua.runtime.version": "LuaJIT", + "Lua.workspace.library": [ + "${3rd}/love2d/library" + ], } \ No newline at end of file diff --git a/manifest.json b/manifest.json index 88ccb4a..e4984c3 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "id": "Roland", "name": "Roland", "prefix": "Roland", - "version": "2.9.12", + "version": "2.9.13", "badge_colour": "8BE9FD", "display_name": "Roland", "main_file": "src/main.lua", diff --git a/src/back.lua b/src/back.lua index 3c3c6d6..8610185 100644 --- a/src/back.lua +++ b/src/back.lua @@ -27,9 +27,8 @@ local back = (function() tbl.atlas = "back" x = x + 1 local back = q(SMODS.Back(tbl)) - local sleeve = (_G["CardSleeves"] or {}).Sleeve - local _ = sleeve and sleeve { + local _ = CardSleeves and CardSleeves.Sleeve { key = key, pos = tbl.pos, atlas = "sleeve", @@ -61,7 +60,7 @@ SMODS.Atlas { py = 95, } -local _ = _G["CardSleeves"] and SMODS.Atlas { +local _ = CardSleeves and SMODS.Atlas { key = "sleeve", path = "sleeve.png", px = 73, diff --git a/src/blind.lua b/src/blind.lua index c1d15e7..810f8ca 100644 --- a/src/blind.lua +++ b/src/blind.lua @@ -476,15 +476,15 @@ local venerable_visage = blind { vitriol = function(b) local vitriol = SMODS.Mods.Roland.config.vitriol local resize_to_w, resize_to_h = 320, 200 - local is_fullscreen = _G["love"].window.getFullscreen() + local is_fullscreen = love.window.getFullscreen() if vitriol then - _G["love"].window.setFullscreen(false) + love.window.setFullscreen(false) delay(1.5) end local function jitter() - local x, y = _G["love"].window.getDesktopDimensions() + local x, y = love.window.getDesktopDimensions() return pseudorandom(pseudoseed "RolandVenerableVisageX", 0, x) - x / 2, pseudorandom(pseudoseed "RolandVenerableVisageY", 0, y) - y / 2 @@ -512,15 +512,16 @@ local venerable_visage = blind { play_sound("gong", v) end) + ---@type number, number, table + local w, h, flags = love.window.getMode() local len = #G.playing_cards - local w, h, flags = _G["love"].window.getMode() if vitriol then - _G["love"].window.setMode(resize_to_w, resize_to_h) - _G["love"].resize(resize_to_w, resize_to_h) + love.window.setMode(resize_to_w, resize_to_h) + love.resize(resize_to_w, resize_to_h) end - local x, y = _G["love"].window.getPosition() + local x, y = love.window.getPosition() f(G.playing_cards):each(function(v, i) q { @@ -529,7 +530,7 @@ local venerable_visage = blind { func = function() if vitriol then local x_random, y_random = jitter() - _G["love"].window.setPosition(x + x_random * i / len, y + y_random * i / len) + love.window.setPosition(x + x_random * i / len, y + y_random * i / len) end v:start_dissolve() @@ -543,10 +544,10 @@ local venerable_visage = blind { trigger = "before", delay = 1.5, func = function() - _G["love"].window.setPosition(x, y) - _G["love"].window.setMode(w, h, flags) - _G["love"].resize(w, h) - _G["love"].window.setFullscreen(is_fullscreen) + love.window.setPosition(x, y) + love.window.setMode(w, h, flags) + love.resize(w, h) + love.window.setFullscreen(is_fullscreen) end, } diff --git a/src/lib/intellisense.lua b/src/lib/intellisense.lua index c6cd422..50008d9 100644 --- a/src/lib/intellisense.lua +++ b/src/lib/intellisense.lua @@ -1,19 +1,8 @@ ---@meta ---@alias Attributes "mult"|"chips"|"xmult"|"xchips"|"score"|"xscore"|"blindsize"|"xblindsize"|"balance"|"swap"|"retrigger"|"scaling"|"reset"|"suit"|"diamonds"|"hearts"|"spades"|"clubs"|"hand_type"|"rank"|"ace"|"two"|"three"|"four"|"five"|"six"|"seven"|"eight"|"nine"|"ten"|"jack"|"queen"|"king"|"face"|"economy"|"generation"|"destroy_card"|"hands"|"discard"|"hand_size"|"chance"|"joker_slot"|"mod_chance"|"copying"|"full_deck"|"passive"|"joker"|"tarot"|"planet"|"spectral"|"enhancements"|"seals"|"editions"|"tag"|"skip"|"modify_card"|"perma_bonus"|"prevents_death"|"boss_blind"|"reroll"|"on_sell"|"sell_value"|"food"|"space"|"bakery_double_sided"|"bakery_usable"|"bakery_werewolf" -SMODS.Mods.Roland.config = require "config" - ---@type Card[] CardArea.cards = CardArea.cards ----@type userdata|{getWidth: fun(self: self): number} -SMODS.Atlas.image_data = SMODS.Atlas.image_data - ---- @type { constants?: { TEN: table }, new: (fun(self: self, arr?: number[], sign?: number, noNormalize?: boolean): table), pow: (fun(x: number, y: number): number) } -_G["Big"] = _G["Big"] - ---- @type fun(area: CardArea, ...: ...): Card -create_card_for_shop = create_card_for_shop - --- @overload fun(tbl: SMODS.Joker): SMODS.GameObject Bakery_API.Charm = Bakery_API.Charm @@ -24,6 +13,32 @@ function Bakery_API.credit(obj) error(obj) end +---@type table +Balatest = Balatest + +--- @type { constants?: { TEN: table }, new: (fun(self: self, arr?: number[], sign?: number, noNormalize?: boolean): table), pow: (fun(x: number, y: number): number) } +Big = Big + +--- @type table +CardSleeves = CardSleeves + +--- @type fun(obj: SMODS.Back): SMODS.Back +CardSleeves.Sleeve = CardSleeves.Sleeve + +--- @type fun(area: CardArea, ...: ...): Card +create_card_for_shop = create_card_for_shop + +SMODS.Mods.Roland.config = require "config" + +---@type userdata|{getWidth: fun(self: self): number} +SMODS.Atlas.image_data = SMODS.Atlas.image_data + +--- @type table +Talisman = Talisman + +--- @type fun(obj: any): number +to_number = to_number + -- This exists to remove the @deprecated warning. ---Returns the elements from the given `list`. This function is equivalent to ---```lua diff --git a/src/lib/shared.lua b/src/lib/shared.lua index c1cc165..463d28b 100644 --- a/src/lib/shared.lua +++ b/src/lib/shared.lua @@ -21,14 +21,13 @@ local function protect_ev(fun) return Event { blocking = false, no_delete = true, - func = function() + func = protect(function() if not Bakery_API or not Bakery_API.credit then return false end Bakery_API.credit(fun) - return true - end, + end), } else fun.func = protect(fun.func or fun[1]) diff --git a/src/main.lua b/src/main.lua index e86e246..6f2da77 100644 --- a/src/main.lua +++ b/src/main.lua @@ -63,7 +63,7 @@ f {"challenge", "spectral", "edition", "tweaks", "blind", "charm", "joker", "tar assert(SMODS.load_file("src/" .. v .. ".lua"))(qol) end) -if _G["Balatest"] then +if Balatest then f {"joker", "blind", "spectral"}:each(function(v) assert(SMODS.load_file("src/tests/" .. v .. ".tests.lua"))(qol) end) @@ -107,7 +107,7 @@ function SMODS.current_mod.config_tab() toggle "equinox_assist", SMODS.Mods.DebugPlus and toggle "import_funky", G.P_CENTERS.c_Bakery_Scribe and toggle "scribable_basket", - _G["Talisman"] and toggle "harsh_ante_scaling", + Talisman and toggle "harsh_ante_scaling", }, }}, } diff --git a/src/tweaks.lua b/src/tweaks.lua index c08eb04..097e342 100644 --- a/src/tweaks.lua +++ b/src/tweaks.lua @@ -94,11 +94,11 @@ local orig_get_blind_amount = get_blind_amount ---@param ante number ---@return table|number local function blind(ante) - return ante == 39 and 1e294 or (_G["to_number"] or f.id)(orig_get_blind_amount(ante)) + return ante == 39 and 1e294 or (to_number or f.id)(orig_get_blind_amount(ante)) end local function no_harsh_ante_scaling() - return not _G["Talisman"] or not SMODS.Mods.Roland.config.harsh_ante_scaling + return not Talisman or not SMODS.Mods.Roland.config.harsh_ante_scaling end function get_blind_amount(ante, ...) @@ -112,10 +112,10 @@ function get_blind_amount(ante, ...) return 1 / 0 end - local big, rem = _G["Big"], tonumber(blind((ante % loop) + 1)) + local rem = tonumber(blind((ante % loop) + 1)) - return ante / 15 >= loop and big:new(f(blind(ante - (loop * 15))):map(f.const(10)):table()) or - (ante / 9 >= loop and big:new(f(ante / loop - 8):map(f.const(10)):concat {rem}:table()) or - (ante / 2 >= loop and big:new {rem, ante / loop} or - (big.constants and big.constants.TEN or big:new {10}):pow(rem))) + return ante / 15 >= loop and Big:new(f(blind(ante - (loop * 15))):map(f.const(10)):table()) or + (ante / 9 >= loop and Big:new(f(ante / loop - 8):map(f.const(10)):concat {rem}:table()) or + (ante / 2 >= loop and Big:new {rem, ante / loop} or + (Big.constants and Big.constants.TEN or Big:new {10}):pow(rem))) end