From 4aa83328cd655d6e06ae89033caedfeede0ce68d Mon Sep 17 00:00:00 2001 From: Aure <80920463+Aurelius7309@users.noreply.github.com> Date: Mon, 25 Mar 2024 17:14:31 +0100 Subject: [PATCH] Fixes / utility for joker API --- core/core.lua | 159 ++++++++++++++++++++++++++++++------------------ core/joker.lua | 98 +++++++++++++++++++++++++---- core/sprite.lua | 18 +++++- core/suit.lua | 27 +++++--- 4 files changed, 219 insertions(+), 83 deletions(-) diff --git a/core/core.lua b/core/core.lua index 4eec5a8b..ea4d97df 100644 --- a/core/core.lua +++ b/core/core.lua @@ -801,70 +801,113 @@ function SMODS.GUI.staticModListContent() end function SMODS.GUI.dynamicModListContent(page) + local scale = 0.75 + local _, __, showingList, startIndex, endIndex, modsPerPage = recalculateModsList(page) + + local modNodes = {} + + -- If no mods are loaded, show a default message + if showingList == false then + table.insert(modNodes, { + n = G.UIT.R, + config = { + padding = 0, + align = "cm" + }, + nodes = { + { + n = G.UIT.T, + config = { + text = "No mods have been detected...", + shadow = true, + scale = scale * 0.5, + colour = G.C.UI.TEXT_DARK + } + } + } + }) + table.insert(modNodes, { + n = G.UIT.R, + config = { + padding = 0, + align = "cm", + }, + nodes = { + UIBox_button({ + label = { "Open Mods directory" }, + shadow = true, + scale = scale, + colour = G.C.BOOSTER, + button = "openModsDirectory", + minh = 0.8, + minw = 8 + }) + } + }) + else + local modCount = 0 + for id, modInfo in ipairs(SMODS.MODS) do + if id >= startIndex and id <= endIndex then + table.insert(modNodes, createClickableModBox(modInfo, scale * 0.5)) + modCount = modCount + 1 + if modCount >= modsPerPage then break end + end + end + end - local scale = 0.75 - local _, __, showingList, startIndex, endIndex, modsPerPage = recalculateModsList(page) + return { + n = G.UIT.R, + config = { + r = 0.1, + align = "cm", + padding = 0.2, + }, + nodes = modNodes + } +end - local modNodes = {} +function SMODS.SAVE_UNLOCKS() + ------------------------------------- + local TESTHELPER_unlocks = false and not _RELEASE_MODE + ------------------------------------- + if not love.filesystem.getInfo(G.SETTINGS.profile .. '') then + love.filesystem.createDirectory(G.SETTINGS.profile .. + '') + end + if not love.filesystem.getInfo(G.SETTINGS.profile .. '/' .. 'meta.jkr') then + love.filesystem.append( + G.SETTINGS.profile .. '/' .. 'meta.jkr', 'return {}') + end - -- If no mods are loaded, show a default message - if showingList == false then - table.insert(modNodes, { - n = G.UIT.R, - config = { - padding = 0, - align = "cm" - }, - nodes = { - { - n = G.UIT.T, - config = { - text = "No mods have been detected...", - shadow = true, - scale = scale * 0.5, - colour = G.C.UI.TEXT_DARK - } - } - } - }) - table.insert(modNodes, { - n = G.UIT.R, - config = { - padding = 0, - align = "cm", - }, - nodes = { - UIBox_button({ - label = {"Open Mods directory"}, - shadow = true, - scale = scale, - colour = G.C.BOOSTER, - button = "openModsDirectory", - minh = 0.8, - minw = 8 - }) - } - }) - else - local modCount = 0 - for id, modInfo in ipairs(SMODS.MODS) do - if id >= startIndex and id <= endIndex then - table.insert(modNodes, createClickableModBox(modInfo, scale * 0.5)) - modCount = modCount + 1 - if modCount >= modsPerPage then break end + convert_save_to_meta() + + local meta = STR_UNPACK(get_compressed(G.SETTINGS.profile .. '/' .. 'meta.jkr') or 'return {}') + meta.unlocked = meta.unlocked or {} + meta.discovered = meta.discovered or {} + meta.alerted = meta.alerted or {} + + for k, v in pairs(G.P_CENTERS) do + if not v.wip and not v.demo then + if TESTHELPER_unlocks then + v.unlocked = true; v.discovered = true; v.alerted = true + end --REMOVE THIS + if not v.unlocked and (string.find(k, '^j_') or string.find(k, '^b_') or string.find(k, '^v_')) and meta.unlocked[k] then + v.unlocked = true + end + if not v.unlocked and (string.find(k, '^j_') or string.find(k, '^b_') or string.find(k, '^v_')) then + G.P_LOCKED[#G.P_LOCKED + 1] = + v + end + if not v.discovered and (string.find(k, '^j_') or string.find(k, '^b_') or string.find(k, '^e_') or string.find(k, '^c_') or string.find(k, '^p_') or string.find(k, '^v_')) and meta.discovered[k] then + v.discovered = true + end + if v.discovered and meta.alerted[k] or v.set == 'Back' or v.start_alerted then + v.alerted = true + elseif v.discovered then + v.alerted = false end end end - - return { - n = G.UIT.R, - config = { - r = 0.1, - align = "cm", - padding = 0.2, - }, - nodes = modNodes - } end ---------------------------------------------- diff --git a/core/joker.lua b/core/joker.lua index d2af8f15..4d209414 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) + eternal_compat, effect, atlas) o = {} setmetatable(o, self) self.__index = self @@ -33,11 +33,12 @@ function SMODS.Joker:new(name, slug, config, spritePos, loc_txt, rarity, cost, u } o.rarity = rarity or 1 o.cost = cost - o.unlocked = unlocked or true - o.discovered = discovered or true + o.unlocked = (unlocked == nil) and true or unlocked + o.discovered = (discovered == nil) and true or discovered o.blueprint_compat = blueprint_compat or false - o.eternal_compat = eternal_compat or true - o.effect = nil + o.eternal_compat = (eternal_compat == nil) and true or eternal_compat + o.effect = effect or '' + o.atlas = atlas or nil return o end @@ -69,8 +70,10 @@ function SMODS.injectJokers() rarity = joker.rarity, blueprint_compat = joker.blueprint_compat, eternal_compat = joker.eternal_compat, + effect = joker.effect, cost = joker.cost, - cost_mult = 1.0 + cost_mult = 1.0, + atlas = joker.atlas or nil } for _i, sprite in ipairs(SMODS.Sprites) do @@ -99,7 +102,7 @@ function SMODS.injectJokers() center.text_parsed[#center.text_parsed + 1] = loc_parse_string(line) end center.name_parsed = {} - for _, line in ipairs(type(center.name) == 'table' and center.name or {center.name}) do + for _, line in ipairs(type(center.name) == 'table' and center.name or { center.name }) do center.name_parsed[#center.name_parsed + 1] = loc_parse_string(line) end if center.unlock then @@ -114,8 +117,9 @@ function SMODS.injectJokers() end sendDebugMessage("The Joker named " .. joker.name .. " with the slug " .. joker.slug .. - " have been registered at the id " .. id .. ".") + " have been registered at the id " .. id .. ".") end + SMODS.SAVE_UNLOCKS() end local carfset_abilityRef = Card.set_ability @@ -124,9 +128,10 @@ function Card.set_ability(self, center, initial, delay_sprites) -- Iterate over each object in SMODS.JKR_EFFECT for _k, obj in pairs(SMODS.Jokers) do - -- Check if the object's name matches self.ability.name and if it has an effect function - if obj.name == self.ability.name and type(obj.effect) == "function" then - obj.effect(self, context) + --! CHANGED from effect due to overlap + -- Check if the object's name matches self.ability.name and if it has an ability function + if obj.name == self.ability.name and type(obj.set_ability) == "function" then + obj.set_ability(self, center, initial, delay_sprites) end end end @@ -139,15 +144,82 @@ function Card:calculate_joker(context) for _k, obj in pairs(SMODS.Jokers) do -- Check if the object's name matches self.ability.name and if it has a calculate function if obj.name == self.ability.name and type(obj.calculate) == "function" then - return obj.calculate(self, context) + local o = obj.calculate(self, context) + if o then return o end end end - end return ret_val; end +local ability_table_ref = Card.generate_UIBox_ability_table +function Card:generate_UIBox_ability_table() + local card_type, hide_desc = self.ability.set or "None", nil + local loc_vars = nil + local main_start, main_end = nil, nil + local no_badge = nil + if not self.bypass_lock and self.config.center.unlocked ~= false and + self.ability.set == 'Joker' and + not self.config.center.discovered and + ((self.area ~= G.jokers and self.area ~= G.consumeables and self.area) or not self.area) then + card_type = 'Undiscovered' + end + + if self.config.center.unlocked == false and not self.bypass_lock then -- For everyting that is locked + elseif card_type == 'Undiscovered' and not self.bypass_discovery_ui then -- Any Joker or tarot/planet/voucher that is not yet discovered + elseif self.debuff then + elseif card_type == 'Default' or card_type == 'Enhanced' then + elseif self.ability.set == 'Joker' then + for _, v in pairs(SMODS.Jokers) do + if v.loc_def and type(v.loc_def) == 'function' then + loc_vars = v:loc_def(self) or loc_vars + end + end + end + if loc_vars then + local badges = {} + if (card_type ~= 'Locked' and card_type ~= 'Undiscovered' and card_type ~= 'Default') or self.debuff then + badges.card_type = card_type + end + if self.ability.set == 'Joker' and self.bypass_discovery_ui and (not no_badge) then + badges.force_rarity = true + end + if self.edition then + if self.edition.type == 'negative' and self.ability.consumeable then + badges[#badges + 1] = 'negative_consumable' + else + badges[#badges + 1] = (self.edition.type == 'holo' and 'holographic' or self.edition.type) + end + end + if self.seal then + badges[#badges + 1] = string.lower(self.seal) .. '_seal' + end + if self.ability.eternal then + badges[#badges + 1] = 'eternal' + end + if self.pinned then + badges[#badges + 1] = 'pinned_left' + end + + if self.sticker then + loc_vars = loc_vars or {}; + loc_vars.sticker = self.sticker + end + + local center = self.config.center + return generate_card_ui(center, nil, loc_vars, card_type, badges, hide_desc, main_start, main_end) + end + return ability_table_ref(self) +end +--[[ + function SMODS.Joker.j_example:loc_def(card) + if card.ability.name == 'Example Joker' then + return {card.ability.extra.mult} + end + end +]] + function SMODS.end_calculate_context(c) if not c.after and not c.before and not c.other_joker and not c.repetition and not c.individual and not c.end_of_round and not c.discard and not c.pre_discard and not c.debuffed_hand and not c.using_consumeable and diff --git a/core/sprite.lua b/core/sprite.lua index 02024c62..8c4c5112 100644 --- a/core/sprite.lua +++ b/core/sprite.lua @@ -167,9 +167,21 @@ function Card:set_sprites(_center, _front) if _center then if _center.set then if (_center.set == 'Joker' or _center.consumeable or _center.set == 'Voucher') and _center.atlas then - self.children.center.atlas = G.ASSET_ATLAS - [(_center.atlas or (_center.set == 'Joker' or _center.consumeable or _center.set == 'Voucher') and _center.set) or 'centers'] - self.children.center:set_sprite_pos(_center.pos) + if self.params.bypass_discovery_center or (_center.unlocked and _center.discovered) then + self.children.center.atlas = G.ASSET_ATLAS + [(_center.atlas or (_center.set == 'Joker' or _center.consumeable or _center.set == 'Voucher') and _center.set) or 'centers'] + self.children.center:set_sprite_pos(_center.pos) + elseif not _center.discovered then + self.children.center.atlas = G.ASSET_ATLAS[_center.set] + self.children.center:set_sprite_pos( + (_center.set == 'Joker' and G.j_undiscovered.pos) or + (_center.set == 'Edition' and G.j_undiscovered.pos) or + (_center.set == 'Tarot' and G.t_undiscovered.pos) or + (_center.set == 'Planet' and G.p_undiscovered.pos) or + (_center.set == 'Spectral' and G.s_undiscovered.pos) or + (_center.set == 'Voucher' and G.v_undiscovered.pos) or + (_center.set == 'Booster' and G.booster_undiscovered.pos)) + end end end end diff --git a/core/suit.lua b/core/suit.lua index 2ba15691..d3c36621 100644 --- a/core/suit.lua +++ b/core/suit.lua @@ -103,7 +103,7 @@ function SMODS.Card:new_suit(name, card_atlas_low_contrast, card_atlas_high_cont if not (type(colour_high_contrast) == 'table') then colour_high_contrast = HEX(colour_high_contrast) end G.C.SO_1[name] = colour_low_contrast G.C.SO_2[name] = colour_high_contrast - G.C.SUITS[name] = G.C["SO_" .. (G.SETTINGS.colourblind_option and 2 or 1)][name] + G.C.SUITS[name] = G.C["SO_" .. (G.SETTINGS.colourblind_option and 2 or 1)][name] for _, v in pairs(SMODS.Card.RANKS) do G.P_CARDS[prefix .. '_' .. (v.suffix or v.value)] = { name = v.value .. ' of ' .. name, @@ -117,7 +117,7 @@ function SMODS.Card:new_suit(name, card_atlas_low_contrast, card_atlas_high_cont } end G.localization.misc['suits_plural'][name] = name - G.localization.misc['suits_singular'][name] = name + G.localization.misc['suits_singular'][name] = name:match("(.+)s$") return SMODS.Card.SUITS[name] end @@ -177,14 +177,23 @@ end function SMODS.Card:_extend() local Game_init_game_object = Game.init_game_object - function Game:init_game_object() - local t = Game_init_game_object(self) - t.cards_played = {} - for k, v in pairs(SMODS.Card.RANKS) do - t.cards_played[k] = { suits = {}, total = 0 } + function Game:init_game_object() + local t = Game_init_game_object(self) + t.cards_played = {} + for k, v in pairs(SMODS.Card.RANKS) do + t.cards_played[k] = { suits = {}, total = 0 } + end + return t + end + + local loc_colour_ref = loc_colour + function loc_colour(_c, _default) + loc_colour_ref(_c, _default) + for k,_ in pairs(SMODS.Card.SUITS) do + G.ARGS.LOC_COLOURS[k:lower()] = G.ARGS.LOC_COLOURS[k:lower()] or G.C.SUITS[k] end - return t - end + return G.ARGS.LOC_COLOURS[_c] or _default or G.C.UI.TEXT_DARK + end function get_flush(hand) local ret = {}