From a5bc9a323225394bdb03ef3bc8fa653b09fcd9d7 Mon Sep 17 00:00:00 2001 From: Casimir Eisenach Date: Mon, 1 Apr 2024 18:23:16 +0200 Subject: [PATCH] Optimization, bug fixes, mod tracking --- core/joker.lua | 29 ++++--- core/planet.lua | 8 +- core/sound.lua | 2 +- core/spectral.lua | 8 +- core/sprite.lua | 4 +- core/suit.lua | 3 +- core/tarot.lua | 211 ++++++++++++++++++++++++---------------------- core/voucher.lua | 4 + loader/loader.lua | 25 ++++-- 9 files changed, 163 insertions(+), 131 deletions(-) diff --git a/core/joker.lua b/core/joker.lua index 775a26af..f7422aad 100644 --- a/core/joker.lua +++ b/core/joker.lua @@ -18,7 +18,7 @@ SMODS.Joker = { } function SMODS.Joker:new(name, slug, config, spritePos, loc_txt, rarity, cost, unlocked, discovered, blueprint_compat, - eternal_compat, effect, atlas) + eternal_compat, effect, atlas, soul_pos) o = {} setmetatable(o, self) self.__index = self @@ -31,6 +31,7 @@ function SMODS.Joker:new(name, slug, config, spritePos, loc_txt, rarity, cost, u x = 0, y = 0 } + o.soul_pos = soul_pos o.rarity = rarity or 1 o.cost = cost o.unlocked = (unlocked == nil) and true or unlocked @@ -39,6 +40,8 @@ function SMODS.Joker:new(name, slug, config, spritePos, loc_txt, rarity, cost, u o.eternal_compat = (eternal_compat == nil) and true or eternal_compat o.effect = effect or '' o.atlas = atlas or nil + o.mod_name = SMODS._MOD_NAME + o.badge_colour = SMODS._BADGE_COLOUR return o end @@ -74,12 +77,13 @@ function SMODS.injectJokers() effect = joker.effect, cost = joker.cost, cost_mult = 1.0, - atlas = joker.atlas or nil + atlas = joker.atlas or nil, + mod_name = joker.mod_name, + badge_colour = joker.badge_colour, + soul_pos = joker.soul_pos } for _i, sprite in ipairs(SMODS.Sprites) do - sendDebugMessage(sprite.name) - sendDebugMessage(joker_obj.key) if sprite.name == joker_obj.key then joker_obj.atlas = sprite.name end @@ -117,12 +121,12 @@ function Card:calculate_joker(context) local ret_val = calculate_jokerref(self, context); if self.ability.set == "Joker" and not self.debuff then - for _k, obj in pairs(SMODS.Jokers) do - if obj.calculate and type(obj.calculate) == "function" and _k == self.config.center.key then - local o = obj.calculate(self, context) + local key = self.config.center.key + local joker_obj = SMODS.Jokers[key] + if joker_obj and joker_obj.calculate and type(joker_obj.calculate) == "function" then + local o = joker_obj.calculate(self, context) if o then return o end end - end end return ret_val; @@ -146,14 +150,13 @@ function Card:generate_UIBox_ability_table() elseif self.debuff then elseif card_type == 'Default' or card_type == 'Enhanced' then elseif self.ability.set == 'Joker' then - sendDebugMessage(inspect(self.config.center)) - for k, v in pairs(SMODS.Jokers) do - if v.loc_def and type(v.loc_def) == 'function' and k == self.config.center.key then - local o, m = v.loc_def(self) + local key = self.config.center.key + local joker_obj = SMODS.Jokers[key] + if joker_obj and joker_obj.loc_def and type(joker_obj.loc_def) == 'function' then + local o, m = joker_obj.loc_def(self) if o and next(o) then loc_vars = o end if m and next(m) then main_end = m end end - end end if loc_vars then local badges = {} diff --git a/core/planet.lua b/core/planet.lua index 53c36a33..91d53d4e 100644 --- a/core/planet.lua +++ b/core/planet.lua @@ -42,6 +42,8 @@ function SMODS.Planet:new(name, slug, config, pos, loc_txt, cost, cost_mult, eff o.freq = freq or 1 o.cost_mult = cost_mult or 1.0 o.atlas = atlas + o.mod_name = SMODS._MOD_NAME + o.badge_colour = SMODS._BADGE_COLOUR return o end @@ -76,12 +78,12 @@ function SMODS.injectPlanets() effect = planet.effect, cost_mult = planet.cost_mult, freq = planet.freq, - atlas = planet.atlas + atlas = planet.atlas, + mod_name = planet.mod_name, + badge_colour = planet.badge_colour } for _i, sprite in ipairs(SMODS.Sprites) do - sendDebugMessage(sprite.name) - sendDebugMessage(planet_obj.key) if sprite.name == planet_obj.key then planet_obj.atlas = sprite.name end diff --git a/core/sound.lua b/core/sound.lua index a246ee00..5cf4c5cf 100644 --- a/core/sound.lua +++ b/core/sound.lua @@ -10,7 +10,7 @@ function register_sound(name, path, filename) s.original_volume = 0.75 s.sound_code = name - sendDebugMessage("Registered sound " .. name .. " from file " .. filename) + sendDebugMessage("Registered sound " .. name .. " from file " .. filename) SMODS.SOUND_SOURCES[name] = s end diff --git a/core/spectral.lua b/core/spectral.lua index 8a95337b..605fe591 100644 --- a/core/spectral.lua +++ b/core/spectral.lua @@ -28,6 +28,8 @@ function SMODS.Spectral:new(name, slug, config, pos, loc_txt, cost, consumeable, o.unlocked = true o.consumeable = consumeable or true o.atlas = atlas + o.mod_name = SMODS._MOD_NAME + o.badge_colour = SMODS._BADGE_COLOUR return o end @@ -58,12 +60,12 @@ function SMODS.injectSpectrals() pos = spectral.pos, config = spectral.config, atlas = spectral.atlas, - cost = spectral.cost + cost = spectral.cost, + mod_name = spectral.mod_name, + badge_colour = spectral.badge_colour } for _i, sprite in ipairs(SMODS.Sprites) do - sendDebugMessage(sprite.name) - sendDebugMessage(tarot_obj.key) if sprite.name == tarot_obj.key then tarot_obj.atlas = sprite.name end diff --git a/core/sprite.lua b/core/sprite.lua index 6f131386..b1fdefb0 100644 --- a/core/sprite.lua +++ b/core/sprite.lua @@ -101,8 +101,8 @@ function SMODS.injectSprites() else error("Bad Sprite type") end - - sendDebugMessage("The Sprite named " .. sprite.name .. " with path " .. sprite.path .. " have been registered.") + + sendDebugMessage("The Sprite named " .. sprite.name .. " with path " .. sprite.path .. " have been registered.") end --Reload Textures diff --git a/core/suit.lua b/core/suit.lua index 9f592167..963cb825 100644 --- a/core/suit.lua +++ b/core/suit.lua @@ -1065,7 +1065,8 @@ function SMODS.Card:_extend() end function Card:is_face(from_boss) - if self.debuff and not from_boss then return end + if self.debuff and not from_boss then return end + if self:get_id() < 0 then return end local val = self.base.value if next(find_joker('Pareidolia')) or (val and SMODS.Card.RANKS[val] and SMODS.Card.RANKS[val].face) then return true end end diff --git a/core/tarot.lua b/core/tarot.lua index 12b13d22..66e9b76c 100644 --- a/core/tarot.lua +++ b/core/tarot.lua @@ -9,7 +9,7 @@ SMODS.Tarot = { discovered = false, consumeable = true, effect = "", - cost_mult = 1.0 + cost_mult = 1.0, } function SMODS.Tarot:new(name, slug, config, pos, loc_txt, cost, cost_mult, effect, consumeable, discovered, atlas) @@ -32,6 +32,8 @@ function SMODS.Tarot:new(name, slug, config, pos, loc_txt, cost, cost_mult, effe o.effect = effect or "" o.cost_mult = cost_mult or 1.0 o.atlas = atlas + o.mod_name = SMODS._MOD_NAME + o.badge_colour = SMODS._BADGE_COLOUR return o end @@ -64,7 +66,9 @@ function SMODS.injectTarots() config = tarot.config, effect = tarot.effect, cost_mult = tarot.cost_mult, - atlas = tarot.atlas + atlas = tarot.atlas, + mod_name = tarot.mod_name, + badge_colour = tarot.badge_colour } for _i, sprite in ipairs(SMODS.Sprites) do @@ -153,103 +157,91 @@ end local generate_card_ui_ref = generate_card_ui function generate_card_ui(_c, full_UI_table, specific_vars, card_type, badges, hide_desc, main_start, main_end) - local original_full_UI_table = full_UI_table - local original_main_end = main_end - local first_pass = nil - if not full_UI_table then - first_pass = true - full_UI_table = { - main = {}, - info = {}, - type = {}, - name = nil, - badges = badges or {} - } - end + local original_full_UI_table = full_UI_table + local original_main_end = main_end + local first_pass = nil + if not full_UI_table then + first_pass = true + full_UI_table = { + main = {}, + info = {}, + type = {}, + name = nil, + badges = badges or {} + } + end - local desc_nodes = (not full_UI_table.name and full_UI_table.main) or full_UI_table.info - local name_override = nil + local desc_nodes = (not full_UI_table.name and full_UI_table.main) or full_UI_table.info + local name_override = nil local info_queue = {} - local loc_vars = {} - if main_start then - desc_nodes[#desc_nodes + 1] = main_start - end - - if not (card_type == 'Locked') and not hide_desc then - if _c.set == 'Tarot' then - for _k, v in pairs(SMODS.Tarots) do - if v.loc_def and type(v.loc_def) == 'function' and _c.key == _k then - local o, m = v.loc_def(_c, info_queue) - if o and next(o) then loc_vars = o end - if m then main_end = m end - end - end - end - if _c.set == 'Spectral' then - for _k, v in pairs(SMODS.Spectrals) do - if v.loc_def and type(v.loc_def) == 'function' and _c.key == _k then - local o, m = v.loc_def(_c, info_queue) - if o and next(o) then loc_vars = o end - if m then main_end = m end - end - end - end - if _c.set == 'Voucher' then - for _k, v in pairs(SMODS.Vouchers) do - if v.loc_def and type(v.loc_def) == 'function' and _c.key == _k then - local o, m = v.loc_def(_c, info_queue) - if o and next(o) then loc_vars = o end - if m then main_end = m end - end - end - end - end + + local loc_vars = {} - if first_pass and not (_c.set == 'Edition') and badges and next(badges) then - for _, v in ipairs(badges) do - for k, _ in pairs(SMODS.Seals) do - if k == v then info_queue[#info_queue + 1] = { key = v, set = 'Other' } end - end - end - end + if not (card_type == 'Locked') and not hide_desc and not (specific_vars and specific_vars.debuffed) then + local key = _c.key + local center_obj = SMODS.Tarots[key] or SMODS.Planets[key] or SMODS.Spectrals[key] or SMODS.Vouchers[key] + if center_obj and center_obj.loc_def and type(center_obj.loc_def) == 'function' then + local o, m = center_obj.loc_def(_c, info_queue) + if o and next(o) then loc_vars = o end + if m then main_end = m end + end + end + + if first_pass and not (_c.set == 'Edition') and badges and next(badges) then + for _, v in ipairs(badges) do + if SMODS.Seals[v] then info_queue[#info_queue + 1] = { key = v, set = 'Other' } end + end + end if next(loc_vars) then - full_UI_table.name = localize { type = 'name', set = _c.set, key = _c.key, nodes = full_UI_table.name } - full_UI_table.card_type = card_type or _c.set + if full_UI_table.name then + full_UI_table.info[#full_UI_table.info + 1] = {} + desc_nodes = full_UI_table.info[#full_UI_table.info] + end + if not full_UI_table.name then + full_UI_table.name = localize { type = 'name', set = _c.set, key = _c.key, nodes = full_UI_table.name } + full_UI_table.card_type = card_type or _c.set + end + if main_start then + desc_nodes[#desc_nodes + 1] = main_start + end localize { type = 'descriptions', key = _c.key, set = _c.set, nodes = desc_nodes, vars = loc_vars } - end - + if not ((specific_vars and not specific_vars.sticker) and (card_type == 'Default' or card_type == 'Enhanced')) then + if desc_nodes == full_UI_table.main and not full_UI_table.name then + localize{type = 'name', key = _c.key, set = _c.set, nodes = full_UI_table.name} + if not full_UI_table.name then full_UI_table.name = {} end + elseif desc_nodes ~= full_UI_table.main then + desc_nodes.name = localize{type = 'name_text', key = name_override or _c.key, set = name_override and 'Other' or _c.set} + end + end + end + if main_end then desc_nodes[#desc_nodes + 1] = main_end end - for _, v in ipairs(info_queue) do - sendDebugMessage(inspect(v)) - generate_card_ui(v, full_UI_table) - end - if next(loc_vars) or next(info_queue) then return full_UI_table end - return generate_card_ui_ref(_c, original_full_UI_table, specific_vars, card_type, badges, hide_desc, main_start, - original_main_end) + for _, v in ipairs(info_queue) do + generate_card_ui(v, full_UI_table) + end + if next(loc_vars) or next(info_queue) then return full_UI_table end + return generate_card_ui_ref(_c, original_full_UI_table, specific_vars, card_type, badges, hide_desc, main_start, + original_main_end) end local card_use_consumeable_ref = Card.use_consumeable function Card:use_consumeable(area, copier) - if self.debuff then return nil end - card_use_consumeable_ref(self, area, copier) - for _k, v in pairs(SMODS.Tarots) do - if (v.use and type(v.use) == 'function') and self.config.center.key == _k then - v.use(self, area, copier) - end - end - for _k, v in pairs(SMODS.Planets) do - if (v.use and type(v.use) == 'function') and self.config.center.key == _k then - v.use(self, area, copier) - end - end - for _k, v in pairs(SMODS.Spectrals) do - if (v.use and type(v.use) == 'function') and self.config.center.key == _k then - v.use(self, area, copier) + local key = self.config.center.key + local center_obj = SMODS.Tarots[key] or SMODS.Planets[key] or SMODS.Spectrals[key] + if center_obj and center_obj.use and type(center_obj.use) == 'function' then + stop_use() + if not copier then set_consumeable_usage(self) end + if self.debuff then return nil end + if self.ability.consumeable.max_highlighted then + update_hand_text({immediate = true, nopulse = true, delay = 0}, {mult = 0, chips = 0, level = '', handname = ''}) end + center_obj.use(self, area, copier) + else + card_use_consumeable_ref(self, area, copier) end end @@ -265,23 +257,10 @@ function Card:can_use_consumeable(any_state, skip_check) return false end local t = nil - for _k, v in pairs(SMODS.Tarots) do - if (v.can_use and type(v.use) == 'function') and self.config.center.key == _k then - local o = v:can_use(self) - t = (o == nil) and t or o - end - end - for _k, v in pairs(SMODS.Planets) do - if (v.can_use and type(v.can_use) == 'function') and self.config.center.key == _k then - local o = v:can_use(self) - t = (o == nil) and t or o - end - end - for _k, v in pairs(SMODS.Spectrals) do - if (v.can_use and type(v.can_use) == 'function') and self.config.center.key == _k then - local o = v:can_use(self) - t = (o == nil) and t or o - end + local key = self.config.center.key + local center_obj = SMODS.Tarots[key] or SMODS.Planets[key] or SMODS.Spectrals[key] + if center_obj and center_obj.can_use and type(center_obj.can_use) == 'function' then + t = center_obj.can_use(self) or t end if not (t == nil) then return t @@ -289,3 +268,33 @@ function Card:can_use_consumeable(any_state, skip_check) return card_can_use_consumeable_ref(self, any_state, skip_check) end end + +local card_h_popup_ref = G.UIDEF.card_h_popup +function G.UIDEF.card_h_popup(card) + local t = card_h_popup_ref(card) + if not card.config.center then return t end + local badges = t.nodes[1].nodes[1].nodes[1].nodes[3] + badges = badges and badges.nodes or nil + local key = card.config.center.key + local center_obj = SMODS.Jokers[key] or SMODS.Tarots[key] or SMODS.Planets[key] or SMODS.Spectrals[key] or SMODS.Vouchers[key] + if center_obj then + if center_obj.set_badges and type(center_obj.set_badges) == 'function' then + badges = center_obj.set_badges(card, badges) + end + if not G.SETTINGS.no_mod_tracking then + local mod_name = string.sub(center_obj.mod_name, 1, 16) + local len = string.len(mod_name) + badges[#badges + 1] = create_badge(mod_name, center_obj.badge_colour or G.C.UI.BACKGROUND_INACTIVE, nil, len <= 6 and 0.9 or 0.9 - 0.02*(len-6)) + end + end + return t +end + +local settings_ref = G.UIDEF.settings_tab +function G.UIDEF.settings_tab(tab) + local t = settings_ref(tab) + if tab == 'Game' then + t.nodes[7] = create_toggle { label = 'Disable Mod Tracking', ref_table = G.SETTINGS, ref_value = 'no_mod_tracking' } + end + return t +end \ No newline at end of file diff --git a/core/voucher.lua b/core/voucher.lua index 8227b1e7..2b0676ec 100644 --- a/core/voucher.lua +++ b/core/voucher.lua @@ -31,6 +31,8 @@ function SMODS.Voucher:new(name, slug, config, pos, loc_txt, cost, unlocked, dis o.available = available or true o.requires = requires o.atlas = atlas + o.mod_name = SMODS._MOD_NAME + o.badge_colour = SMODS._BADGE_COLOUR return o end @@ -63,6 +65,8 @@ function SMODS.injectVouchers() cost = voucher.cost, atlas = voucher.atlas, requires = voucher.requires, + mod_name = voucher.mod_name, + badge_colour = voucher.badge_colour } for _i, sprite in ipairs(SMODS.Sprites) do diff --git a/loader/loader.lua b/loader/loader.lua index a7259c52..ea9666d2 100644 --- a/loader/loader.lua +++ b/loader/loader.lua @@ -5,6 +5,9 @@ SMODS.INIT = {} SMODS._MOD_PRIO_MAP = {} SMODS._INIT_PRIO_MAP = {} SMODS._INIT_KEYS = {} +SMODS._MOD_FROM_INIT = {} +SMODS._MOD_NAME = '' +SMODS._BADGE_COLOUR = {} -- Attempt to require nativefs local nfs_success, nativefs = pcall(require, "nativefs") @@ -57,7 +60,9 @@ function loadMods(modsDirectory) local modName, modID, modAuthorString, modDescription = fileContent:match("%-%-%- MOD_NAME: ([^\n]+)\n%-%-%- MOD_ID: ([^\n]+)\n%-%-%- MOD_AUTHOR: %[(.-)%]\n%-%-%- MOD_DESCRIPTION: ([^\n]+)") local priority = fileContent:match("%-%-%- PRIORITY: (%-?%d+)") priority = priority and priority + 0 or 0 - + local badge_colour = fileContent:match("%-%-%- BADGE_COLO[U?]R: (%x-)\n") + badge_colour = HEX(badge_colour or '666666FF') + local display_name = fileContent:match("%-%-%- DISPLAY_NAME: (.-)\n") -- Validate MOD_ID to ensure it doesn't contain spaces if modID and string.find(modID, " ") then sendDebugMessage("Invalid mod ID: " .. modID) @@ -72,18 +77,21 @@ function loadMods(modsDirectory) end -- Store mod information in the global table, including the directory path - table.insert(mods, { + local mod = { name = modName, id = modID, author = modAuthorArray, description = modDescription, path = directory .. "/", -- Store the directory path priority = priority, - }) + badge_colour = badge_colour, + display_name = display_name or modName + } + table.insert(mods, mod) modIDs[modID] = true -- Mark this ID as used SMODS._MOD_PRIO_MAP[priority] = SMODS._MOD_PRIO_MAP[priority] or {} - table.insert(SMODS._MOD_PRIO_MAP[priority], fileContent) + table.insert(SMODS._MOD_PRIO_MAP[priority], { content = fileContent, mod = mod }) end end else @@ -105,14 +113,15 @@ function loadMods(modsDirectory) -- load the mod files for _,priority in ipairs(keyset) do - for __,v in ipairs(SMODS._MOD_PRIO_MAP[priority]) do - assert(load(v))() + for _,v in ipairs(SMODS._MOD_PRIO_MAP[priority]) do + assert(load(v.content))() -- set priority of added init functions for modName, initFunc in pairs(SMODS.INIT) do if type(initFunc) == 'function' and SMODS._INIT_KEYS[modName] == nil then SMODS._INIT_PRIO_MAP[priority] = SMODS._INIT_PRIO_MAP[priority] or {} table.insert(SMODS._INIT_PRIO_MAP[priority], modName) SMODS._INIT_KEYS[modName] = true + SMODS._MOD_FROM_INIT[modName] = v.mod end end end @@ -129,6 +138,8 @@ function initMods() table.sort(keyset) for _,k in ipairs(keyset) do for _, modName in ipairs(SMODS._INIT_PRIO_MAP[k]) do + SMODS._MOD_NAME = SMODS._MOD_FROM_INIT[modName].display_name + SMODS._BADGE_COLOUR = SMODS._MOD_FROM_INIT[modName].badge_colour sendDebugMessage("Launch Init Function for: " .. modName .. ".") SMODS.INIT[modName]() end @@ -163,4 +174,4 @@ function initSteamodded() end ---------------------------------------------- -------------MOD LOADER END-------------------- +------------MOD LOADER END-------------------- \ No newline at end of file