diff --git a/core/core.lua b/core/core.lua index 46981028..597bc261 100644 --- a/core/core.lua +++ b/core/core.lua @@ -14,7 +14,6 @@ SMODS.BUFFERS = { Vouchers = {}, } - MODDED_VERSION = "0.9.5-STEAMODDED" function STR_UNPACK(str) @@ -978,24 +977,5 @@ function SMODS.LOAD_LOC() end end --- retain added objects on profile reload -local init_item_prototypes_ref = Game.init_item_prototypes -function Game:init_item_prototypes() - local P_CENTERS = self.P_CENTERS - local P_CENTER_POOLS = self.P_CENTER_POOLS - local P_JOKER_RARITY_POOLS = self.P_JOKER_RARITY_POOLS - local P_BLINDS = self.P_BLINDS - local P_SEALS = self.P_SEALS - local P_CARDS = self.P_CARDS - init_item_prototypes_ref(self) - if P_CENTERS then self.P_CENTERS = P_CENTERS end - if P_CENTER_POOLS then self.P_CENTER_POOLS = P_CENTER_POOLS end - if P_JOKER_RARITY_POOLS then self.P_JOKER_RARITY_POOLS = P_JOKER_RARITY_POOLS end - if P_BLINDS then self.P_BLINDS = P_BLINDS end - if P_SEALS then self.P_SEALS = P_SEALS end - if P_CARDS then self.P_CARDS = P_CARDS end - SMODS.SAVE_UNLOCKS() -end - ---------------------------------------------- ------------MOD CORE END---------------------- diff --git a/core/deck.lua b/core/deck.lua index 30b2e66b..3a746198 100644 --- a/core/deck.lua +++ b/core/deck.lua @@ -71,8 +71,8 @@ local back_initref = Back.init; function Back:init(selected_back) back_initref(self, selected_back) self.atlas = "centers" - if selected_back.config.atlas then - self.atlas = selected_back.config.atlas + if self.effect.center.config.atlas then + self.atlas = self.effect.center.config.atlas end end diff --git a/core/joker.lua b/core/joker.lua index 03543ef1..62becca8 100644 --- a/core/joker.lua +++ b/core/joker.lua @@ -100,33 +100,28 @@ function SMODS.injectJokers() sendDebugMessage("The Joker named " .. joker.name .. " with the slug " .. joker.slug .. " have been registered at the id " .. id .. ".") end - SMODS.BUFFERS.Jokers = {} end local cardset_abilityRef = Card.set_ability function Card.set_ability(self, center, initial, delay_sprites) cardset_abilityRef(self, center, initial, delay_sprites) - - -- Iterate over each object in SMODS.JKR_EFFECT - for _k, obj in pairs(SMODS.Jokers) do - --! CHANGED from effect due to overlap - if obj.set_ability and type(obj.set_ability) == "function" and _k == self.config.center.key then - obj.set_ability(self, center, initial, delay_sprites) - end + local key = self.config.center.key + local joker_obj = SMODS.Jokers[key] + if joker_obj and joker_obj.set_ability and type(joker_obj.set_ability) == 'function' then + joker_obj.set_ability(self, center, initial, delay_sprites) end end local calculate_jokerref = Card.calculate_joker; function Card:calculate_joker(context) - local ret_val = calculate_jokerref(self, context); - - if self.ability.set == "Joker" and not self.debuff then + local ret_val = calculate_jokerref(self, context) + if not self.debuff then 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 + local center_obj = SMODS.Jokers[key] or SMODS.Tarots[key] or SMODS.Planets[key] or SMODS.Spectrals[key] + if center_obj and center_obj.calculate and type(center_obj.calculate) == "function" then + local o = center_obj.calculate(self, context) + if o then return o end + end end return ret_val; @@ -154,8 +149,8 @@ function Card:generate_UIBox_ability_table() 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 + if o then loc_vars = o end + if m then main_end = m end end end if loc_vars then diff --git a/core/planet.lua b/core/planet.lua index 91d53d4e..490026de 100644 --- a/core/planet.lua +++ b/core/planet.lua @@ -99,7 +99,6 @@ function SMODS.injectPlanets() sendDebugMessage("The Planet named " .. planet.name .. " with the slug " .. planet.slug .. " have been registered at the id " .. id .. ".") end - SMODS.BUFFERS.Planets = {} end function create_UIBox_your_collection_planets() diff --git a/core/r_blind.lua b/core/r_blind.lua index 5e10eef6..ec710bf3 100644 --- a/core/r_blind.lua +++ b/core/r_blind.lua @@ -75,7 +75,6 @@ function SMODS.injectBlinds() sendDebugMessage("The Blind named " .. blind.name .. " with the slug " .. blind.slug .. " have been registered at the id " .. id .. ".") end - SMODS.BUFFERS.Blinds = {} end local set_blindref = Blind.set_blind; @@ -94,10 +93,10 @@ function Blind:set_blind(blind, reset, silent) self.children.animatedSprite.states = prev_anim.states self.children.animatedSprite.states.visible = prev_anim.states.visible self.children.animatedSprite.states.drag.can = prev_anim.states.drag.can - for _k, v in pairs(SMODS.Blinds) do - if v.set and type(v.set) == 'function' and self.config.blind.key == _k then - v.set(self, blind, reset, silent) - end + local key = self.config.blind.key + local blind_obj = SMODS.Blinds[key] + if blind_obj and blind_obj.set_blind and type(blind_obj.set_blind) == 'function' then + blind_obj.set_blind(self, blind, reset, silent) end end for _, v in ipairs(G.playing_cards) do @@ -110,24 +109,121 @@ end local blind_disable_ref = Blind.disable function Blind:disable() - for _k,v in pairs(SMODS.Blinds) do - if v.disable and type(v.disable) == 'function' and self.config.blind.key == _k then - v.disable(self) - end + local key = self.config.blind.key + local blind_obj = SMODS.Blinds[key] + if blind_obj and blind_obj.disable and type(blind_obj.disable) == 'function' then + blind_obj.disable(self) end blind_disable_ref(self) end local blind_defeat_ref = Blind.defeat function Blind:defeat(silent) - for _k,v in pairs(SMODS.Blinds) do - if v.defeat and type(v.defeat) == 'function' and self.config.blind.key == _k then - v.defeat(self, silent) - end + local key = self.config.blind.key + local blind_obj = SMODS.Blinds[key] + if blind_obj and blind_obj.defeat and type(blind_obj.defeat) == 'function' then + blind_obj.set_blind(self, silent) end blind_defeat_ref(self, silent) end +local blind_debuff_card_ref = Blind.debuff_card +function Blind:debuff_card(card, from_blind) + blind_debuff_card_ref(self, card, from_blind) + local key = self.config.blind.key + local blind_obj = SMODS.Blinds[key] + if blind_obj and blind_obj.debuff_card and type(blind_obj.debuff_card) == 'function' and not self.disabled then + blind_obj.debuff_card(self, card, from_blind) + end +end + +local blind_stay_flipped_ref = Blind.stay_flipped +function Blind:stay_flipped(area, card) + local key = self.config.blind.key + local blind_obj = SMODS.Blinds[key] + if blind_obj and blind_obj.stay_flipped and type(blind_obj.stay_flipped) == 'function' and not self.disabled and area == G.hand then + return blind_obj.stay_flipped(self, area, card) + end + return blind_stay_flipped_ref(self, area, card) +end + +local blind_drawn_to_hand_ref = Blind.drawn_to_hand +function Blind:drawn_to_hand() + local key = self.config.blind.key + local blind_obj = SMODS.Blinds[key] + if blind_obj and blind_obj.drawn_to_hand and type(blind_obj.drawn_to_hand) == 'function' and not self.disabled then + blind_obj.drawn_to_hand(self) + end + blind_drawn_to_hand_ref(self) +end + +local blind_debuff_hand_ref = Blind.debuff_hand +function Blind:debuff_hand(cards, hand, handname, check) + local key = self.config.blind.key + local blind_obj = SMODS.Blinds[key] + if blind_obj and blind_obj.debuff_hand and type(blind_obj.debuff_hand) == 'function' and not self.disabled then + return blind_obj.debuff_hand(self, cards, hand, handname, check) + end + return blind_debuff_hand_ref(self, cards, hand, handname, check) +end + +local blind_modify_hand_ref = Blind.modify_hand +function Blind:modify_hand(cards, poker_hands, text, mult, hand_chips) + local key = self.config.blind.key + local blind_obj = SMODS.Blinds[key] + if blind_obj and blind_obj.modify_hand and type(blind_obj.modify_hand) == 'function' and not self.debuff then + return blind_obj.modify_hand(cards, poker_hands, text, mult, hand_chips) + end + return blind_modify_hand_ref(cards, poker_hands, text, mult, hand_chips) +end + +local blind_press_play_ref = Blind.press_play +function Blind:press_play() + local key = self.config.blind.key + local blind_obj = SMODS.Blinds[key] + if blind_obj and blind_obj.press_play and type(blind_obj.press_play) == 'function' and not self.disabled then + return blind_obj.press_play(self) + end + return blind_press_play_ref(self) +end + +local blind_get_loc_debuff_text_ref = Blind.get_loc_debuff_text +function Blind:get_loc_debuff_text() + local key = self.config.blind.key + local blind_obj = SMODS.Blinds[key] + if blind_obj and blind_obj.get_loc_debuff_text and type(blind_obj.get_loc_debuff_text) == 'function' then + return blind_obj.get_loc_debuff_text(self) + end + return blind_get_loc_debuff_text_ref(self) +end + +local blind_set_text = Blind.set_text +function Blind:set_text() + local key = self.config.blind.key + local blind_obj = SMODS.Blinds[key] + local loc_vars = nil + if blind_obj and blind_obj.loc_def and type(blind_obj.loc_def) == 'function' and not self.disabled then + loc_vars = blind_obj.loc_def(self) + local loc_target = localize { type = 'raw_descriptions', key = self.config.blind.key, set = 'Blind', vars = loc_vars or self.config.blind.vars } + if loc_target then + self.loc_name = self.name == '' and self.name or + localize { type = 'name_text', key = self.config.blind.key, set = 'Blind' } + self.loc_debuff_text = '' + for k, v in ipairs(loc_target) do + self.loc_debuff_text = self.loc_debuff_text .. v .. (k <= #loc_target and ' ' or '') + end + self.loc_debuff_lines[1] = loc_target[1] or '' + self.loc_debuff_lines[2] = loc_target[2] or '' + else + self.loc_name = ''; self.loc_debuff_text = '' + self.loc_debuff_lines[1] = '' + self.loc_debuff_lines[2] = '' + end + return + end + blind_set_text(self) +end + function create_UIBox_blind_choice(type, run_info) if not G.GAME.blind_on_deck then G.GAME.blind_on_deck = 'Small' diff --git a/core/seal.lua b/core/seal.lua index dade1fe3..b1672d65 100644 --- a/core/seal.lua +++ b/core/seal.lua @@ -60,7 +60,6 @@ function SMODS.injectSeals() sendDebugMessage("The Seal named " .. seal.name .. " have been registered at the id " .. #G.P_CENTER_POOLS.Seal .. ".") end - SMODS.BUFFERS.Seals = {} end local get_badge_colourref = get_badge_colour diff --git a/core/spectral.lua b/core/spectral.lua index 605fe591..352113f1 100644 --- a/core/spectral.lua +++ b/core/spectral.lua @@ -81,7 +81,6 @@ function SMODS.injectSpectrals() sendDebugMessage("The Spectral named " .. spectral.name .. " with the slug " .. spectral.slug .. " have been registered at the id " .. id .. ".") end - SMODS.BUFFERS.Spectrals = {} end function create_UIBox_your_collection_spectrals() diff --git a/core/suit.lua b/core/suit.lua index 963cb825..e14d7513 100644 --- a/core/suit.lua +++ b/core/suit.lua @@ -7,26 +7,30 @@ SMODS.Card.SUITS = { name = 'Hearts', prefix = 'H', suit_nominal = 0.03, - ui_pos = { x = 0, y = 1 } + ui_pos = { x = 0, y = 1 }, + card_pos = { y = 0 }, }, ["Diamonds"] = { name = 'Diamonds', prefix = 'D', suit_nominal = 0.01, ui_pos = { x = 1, y = 1 }, + card_pos = { y = 2 }, }, ["Clubs"] = { name = 'Clubs', prefix = 'C', suit_nominal = 0.02, ui_pos = { x = 2, y = 1 }, + card_pos = { y = 1 }, }, ["Spades"] = { name = 'Spades', prefix = 'S', suit_nominal = 0.04, - ui_pos = { x = 3, y = 1 } - }, + ui_pos = { x = 3, y = 1 }, + card_pos = { y = 3 } + }, } SMODS.Card.MAX_SUIT_NOMINAL = 0.04 SMODS.Card.RANKS = { @@ -39,23 +43,29 @@ SMODS.Card.RANKS = { ['8'] = { value = '8', pos = { x = 6 }, id = 8, nominal = 8, next = { '9' } }, ['9'] = { value = '9', pos = { x = 7 }, id = 9, nominal = 9, next = { '10' } }, ['10'] = { suffix = 'T', value = '10', pos = { x = 8 }, id = 10, nominal = 10, next = { 'Jack' } }, - ['Jack'] = { suffix = 'J', value = 'Jack', pos = { x = 9 }, id = 11, nominal = 10, face_nominal = 0.1, face = true, next = { 'Queen' } }, - ['Queen'] = { suffix = 'Q', value = 'Queen', pos = { x = 10 }, id = 12, nominal = 10, face_nominal = 0.2, face = true, next = { 'King' } }, - ['King'] = { suffix = 'K', value = 'King', pos = { x = 11 }, id = 13, nominal = 10, face_nominal = 0.3, face = true, next = { 'Ace' } }, - ['Ace'] = { suffix = 'A', value = 'Ace', pos = { x = 12 }, id = 14, nominal = 11, face_nominal = 0.4, next = { '2' }, straight_edge = true } + ['Jack'] = { suffix = 'J', value = 'Jack', pos = { x = 9 }, id = 11, nominal = 10, face_nominal = 0.1, face = true, next = { 'Queen' }, shorthand = 'J' }, + ['Queen'] = { suffix = 'Q', value = 'Queen', pos = { x = 10 }, id = 12, nominal = 10, face_nominal = 0.2, face = true, next = { 'King' }, shorthand = 'Q' }, + ['King'] = { suffix = 'K', value = 'King', pos = { x = 11 }, id = 13, nominal = 10, face_nominal = 0.3, face = true, next = { 'Ace', shorthand = 'K' } }, + ['Ace'] = { suffix = 'A', value = 'Ace', pos = { x = 12 }, id = 14, nominal = 11, face_nominal = 0.4, next = { '2' }, straight_edge = true, shorthand = 'A' } } SMODS.Card.RANK_LIST = { '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A' } +SMODS.Card.RANK_SHORTHAND_LOOKUP = { + ['J'] = 'Jack', + ['Q'] = 'Queen', + ['K'] = 'King', + ['A'] = 'Ace', +} SMODS.Card.MAX_ID = 14 function SMODS.Card.generate_prefix() local permutations - permutations = function(list, len) + permutations = function(list, len) len = len or 2 - if len <= 1 then return list end - local t = permutations(list, len-1) - local o = {} - for _,a in ipairs(list) do - for _,b in ipairs(t) do - table.insert(o, a..b) + if len <= 1 then return list end + local t = permutations(list, len - 1) + local o = {} + for _, a in ipairs(list) do + for _, b in ipairs(t) do + table.insert(o, a .. b) end end return o @@ -64,7 +74,7 @@ function SMODS.Card.generate_prefix() 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9' } local perm = permutations(possible_prefixes, 2) - for _,a in ipairs(perm) do + for _, a in ipairs(perm) do table.insert(possible_prefixes, a) end for _, v in pairs(SMODS.Card.SUITS) do @@ -79,14 +89,14 @@ end function SMODS.Card.generate_suffix() local permutations - permutations = function(list, len) + permutations = function(list, len) len = len or 2 - if len <= 1 then return list end - local t = permutations(list, len-1) - local o = {} - for _,a in ipairs(list) do - for _,b in ipairs(t) do - table.insert(o, a..b) + if len <= 1 then return list end + local t = permutations(list, len - 1) + local o = {} + for _, a in ipairs(list) do + for _, b in ipairs(t) do + table.insert(o, a .. b) end end return o @@ -94,9 +104,10 @@ function SMODS.Card.generate_suffix() local possible_suffixes = { 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' } - for _,a in permutations(possible_suffixes, 2) do - table.insert(possible_suffixes, a) - end + local perm = permutations(possible_suffixes, 2) + for _, a in ipairs(perm) do + table.insert(possible_suffixes, a) + end for _, v in pairs(SMODS.Card.RANKS) do for i, vv in ipairs(possible_suffixes) do if v.suffix == vv then @@ -118,6 +129,7 @@ function SMODS.Card:new_suit(name, card_atlas_low_contrast, card_atlas_high_cont sendDebugMessage('Too many suits! Failed to assign valid prefix to:' .. name) end SMODS.Card.MAX_SUIT_NOMINAL = SMODS.Card.MAX_SUIT_NOMINAL + 0.01 + create_cards = not (create_cards == false) SMODS.Card.SUITS[name] = { name = name, prefix = prefix, @@ -127,7 +139,8 @@ function SMODS.Card:new_suit(name, card_atlas_low_contrast, card_atlas_high_cont card_pos = { y = card_pos.y }, ui_atlas_low_contrast = ui_atlas_low_contrast, ui_atlas_high_contrast = ui_atlas_high_contrast, - ui_pos = ui_pos + ui_pos = ui_pos, + disabled = not create_cards or nil } SMODS.Card.SUIT_LIST[#SMODS.Card.SUIT_LIST + 1] = name colour_low_contrast = colour_low_contrast or '000000' @@ -139,121 +152,220 @@ function SMODS.Card:new_suit(name, card_atlas_low_contrast, card_atlas_high_cont G.C.SUITS[name] = G.C["SO_" .. (G.SETTINGS.colourblind_option and 2 or 1)][name] G.localization.misc['suits_plural'][name] = name G.localization.misc['suits_singular'][name] = name:match("(.+)s$") - create_cards = not (create_cards == false) if create_cards then - for _, v in pairs(SMODS.Card.RANKS) do - G.P_CARDS[prefix .. '_' .. (v.suffix or v.value)] = { + SMODS.Card:populate_suit(name) + end + return SMODS.Card.SUITS[name] +end + +-- DELETES ALL DATA ASSOCIATED WITH THE PROVIDED SUIT EXCEPT LOCALIZATION +function SMODS.Card:delete_suit(name) + local suit_data = SMODS.Card.SUITS[name] + if not suit_data then + sendWarnMessage('Tried to delete non-existent suit: ' .. name) + return false + end + local prefix = suit_data.prefix + for _, v in pairs(SMODS.Card.RANKS) do + G.P_CARDS[prefix .. '_' .. (v.suffix or v.value)] = nil + end + local i + for j, v in ipairs(SMODS.Card.SUIT_LIST) do if v == suit_data.name then i = j end end + table.remove(SMODS.Card.SUIT_LIST, i) + SMODS.Card.SUITS[name] = nil + return true +end + +-- Deletes the playing cards of the provided suit from G.P_CARDS +function SMODS.Card:wipe_suit(name) + local suit_data = SMODS.Card.SUITS[name] + if not suit_data then + sendWarnMessage('Tried to wipe non-existent suit: ' .. name) + return false + end + local prefix = suit_data.prefix + for _, v in pairs(SMODS.Card.RANKS) do + G.P_CARDS[prefix .. '_' .. (v.suffix or v.value)] = nil + end + SMODS.Card.SUITS[name].disabled = true + return true +end + +-- Populates G.P_CARDS with cards of all ranks and the given suit +function SMODS.Card:populate_suit(name) + local suit_data = SMODS.Card.SUITS[name] + if not suit_data then + sendWarnMessage('Tried to populate non-existent suit: ' .. name) + return false + end + for _, v in pairs(SMODS.Card.RANKS) do + if not v.disabled then + G.P_CARDS[suit_data.prefix .. '_' .. (v.suffix or v.value)] = { name = v.value .. ' of ' .. name, value = v.value, suit = name, - pos = { x = v.pos.x, y = (v.suit_map and v.suit_map[name]) and v.suit_map[name].y or card_pos.y }, + pos = { x = v.pos.x, y = (v.suit_map and v.suit_map[name]) and v.suit_map[name].y or suit_data.card_pos.y }, card_atlas_low_contrast = (v.atlas_low_contrast and v.suit_map and v.suit_map[name]) and v - .atlas_low_contrast or card_atlas_low_contrast, + .atlas_low_contrast or suit_data.card_atlas_low_contrast, card_atlas_high_contrast = (v.atlas_low_contrast and v.suit_map and v.suit_map[name]) and - v.atlas_high_contrast or card_atlas_high_contrast, + v.atlas_high_contrast or suit_data.card_atlas_high_contrast, } end end - return SMODS.Card.SUITS[name] + SMODS.Card.SUITS[name].disabled = nil + return true end function SMODS.Card:new_rank(value, nominal, atlas_low_contrast, atlas_high_contrast, pos, suit_map, options, - create_cards) - options = options or {} - if SMODS.Card.RANKS[value] then - sendDebugMessage('Failed to register duplicate rank: ' .. value) - return nil - end - local suffix = SMODS.Card:generate_suffix() - if not suffix then - sendDebugMessage('Too many ranks! Failed to assign valid suffix to: ' .. value) - return nil - end - SMODS.Card.MAX_ID = SMODS.Card.MAX_ID + 1 - SMODS.Card.RANKS[value] = { - value = value, - suffix = suffix, - pos = { x = pos.x }, - id = SMODS.Card.MAX_ID, - nominal = nominal, - atlas_low_contrast = atlas_low_contrast, - atlas_high_contrast = atlas_high_contrast, - suit_map = suit_map, - face = options.face, - face_nominal = options.face_nominal, - strength_effect = options.strength_effect or { - fixed = 1, - random = false, - ignore = false - }, - next = options.next, - straight_edge = options.straight_edge - } - SMODS.Card.RANK_LIST[#SMODS.Card.RANK_LIST + 1] = - options.shorthand.unique or + create_cards) + options = options or {} + if SMODS.Card.RANKS[value] then + sendDebugMessage('Failed to register duplicate rank: ' .. value) + return nil + end + local suffix = SMODS.Card:generate_suffix() + if not suffix then + sendDebugMessage('Too many ranks! Failed to assign valid suffix to: ' .. value) + return nil + end + SMODS.Card.MAX_ID = SMODS.Card.MAX_ID + 1 + create_cards = not (create_cards == false) + local shorthand = + options.shorthand.unique or options.shorthand.length and string.sub(value, 1, options.shorthand.length) or string.sub(value, 1, 1) - create_cards = not (create_cards == false) - if create_cards then - for k, v in pairs(SMODS.Card.SUITS) do - if suit_map[k] then - G.P_CARDS[v.prefix .. '_' .. suffix] = { - name = value .. ' of ' .. v.name, - value = value, - pos = { x = pos.x, y = suit_map[k].y }, - suit = v.name, - card_atlas_low_contrast = atlas_low_contrast, - card_atlas_high_contrast = atlas_high_contrast - } - else - -- blank sprite - G.P_CARDS[v.prefix .. '_' .. suffix] = { - name = value .. ' of ' .. v.name, - value = value, - suit = v.name, - pos = { x = 0, y = 5 } - } - end - end - end - G.localization.misc['ranks'][value] = value + SMODS.Card.RANK_LIST[#SMODS.Card.RANK_LIST + 1] = shorthand + SMODS.Card.RANK_SHORTHAND_LOOKUP[shorthand] = value + SMODS.Card.RANKS[value] = { + value = value, + suffix = suffix, + pos = { x = pos.x }, + id = SMODS.Card.MAX_ID, + nominal = nominal, + atlas_low_contrast = atlas_low_contrast, + atlas_high_contrast = atlas_high_contrast, + suit_map = suit_map, + face = options.face, + face_nominal = options.face_nominal, + strength_effect = options.strength_effect or { + fixed = 1, + random = false, + ignore = false + }, + next = options.next, + straight_edge = options.straight_edge, + disabled = not create_cards or nil, + shorthand = shorthand, + } + if create_cards then + SMODS.Card:populate_rank(value) + end + G.localization.misc['ranks'][value] = value + return SMODS.Card.RANKS[value] +end + +-- DELETES ALL DATA ASSOCIATED WITH THE PROVIDED RANK EXCEPT LOCALIZATION +function SMODS.Card:delete_rank(value) + local rank_data = SMODS.Card.RANKS[value] + if not rank_data then + sendWarnMessage('Tried to delete non-existent rank: ' .. value) + return false + end + local suffix = rank_data.suffix or rank_data.value + for _, v in pairs(SMODS.Card.SUITS) do + G.P_CARDS[v.prefix .. '_' .. suffix] = nil + end + local i + for j, v in ipairs(SMODS.Card.RANK_LIST) do if v == rank_data.shorthand or v == rank_data.value then i = j end end + table.remove(SMODS.Card.RANK_LIST, i) + SMODS.Card.RANKS[value] = nil + return true +end + +-- Deletes the playing cards of the provided rank from G.P_CARDS +function SMODS.Card:wipe_rank(value) + local rank_data = SMODS.Card.RANKS[value] + if not rank_data then + sendWarnMessage('Tried to wipe non-existent rank: ' .. value) + return false + end + local suffix = rank_data.suffix or rank_data.value + for _, v in pairs(SMODS.Card.SUITS) do + G.P_CARDS[v.prefix .. '_' .. suffix] = nil + end + SMODS.Card.RANKS[value].disabled = true + return true +end + +-- Populates G.P_CARDS with cards of all suits and the provided rank +function SMODS.Card:populate_rank(value) + local rank_data = SMODS.Card.RANKS[value] + if not rank_data then + sendWarnMessage('Tried to populate non-existent rank: ' .. value) + return false + end + local suffix = rank_data.suffix or rank_data.value + for k, v in pairs(SMODS.Card.SUITS) do + if not v.disabled then + if rank_data.suit_map[k] then + G.P_CARDS[v.prefix .. '_' .. suffix] = { + name = value .. ' of ' .. v.name, + value = value, + pos = { x = rank_data.pos.x, y = rank_data.suit_map[k].y or v.card_pos.y }, + suit = v.name, + card_atlas_low_contrast = rank_data.atlas_low_contrast, + card_atlas_high_contrast = rank_data.atlas_high_contrast + } + else + -- blank sprite + G.P_CARDS[v.prefix .. '_' .. suffix] = { + name = value .. ' of ' .. v.name, + value = value, + suit = v.name, + pos = { x = 0, y = 5 } + } + end + end + end + SMODS.Card.RANKS[value].disabled = nil + return true end function SMODS.Card:new(suit, value, name, pos, atlas_low_contrast, atlas_high_contrast) - local suit_data = SMODS.Card.SUITS[suit] - local rank_data = SMODS.Card.RANKS[value] - if not suit_data then - sendDebugMessage('Suit does not exist: ' .. suit) - return nil - elseif not rank_data then - sendDebugMessage('Rank does not exist: ' .. value) - return nil - end - G.P_CARDS[suit_data.prefix .. '_' .. (rank_data.suffix or rank_data.value)] = { - name = name or (value .. ' of ' .. suit), - suit = suit, - value = value, - pos = pos or { x = rank_data.pos.x, y = suit_data.card_pos.y }, - card_atlas_low_contrast = atlas_low_contrast or rank_data.atlas_low_contrast or suit_data.atlas_low_contrast, - card_atlas_high_contrast = atlas_high_contrast or rank_data.atlas_high_contrast or suit_data.atlas_high_contrast - } - return G.P_CARDS[suit_data.prefix .. '_' .. (rank_data.suffix or rank_data.value)] + local suit_data = SMODS.Card.SUITS[suit] + local rank_data = SMODS.Card.RANKS[value] + if not suit_data then + sendWarnMessage('Suit does not exist: ' .. suit) + return nil + elseif not rank_data then + sendWarnMessage('Rank does not exist: ' .. value) + return nil + end + G.P_CARDS[suit_data.prefix .. '_' .. (rank_data.suffix or rank_data.value)] = { + name = name or (value .. ' of ' .. suit), + suit = suit, + value = value, + pos = pos or { x = rank_data.pos.x, y = suit_data.card_pos.y }, + card_atlas_low_contrast = atlas_low_contrast or rank_data.atlas_low_contrast or suit_data.atlas_low_contrast, + card_atlas_high_contrast = atlas_high_contrast or rank_data.atlas_high_contrast or suit_data.atlas_high_contrast + } + return G.P_CARDS[suit_data.prefix .. '_' .. (rank_data.suffix or rank_data.value)] end function SMODS.Card:remove(suit, value) local suit_data = SMODS.Card.SUITS[suit] - local rank_data = SMODS.Card.RANKS[value] - if not suit_data then - sendDebugMessage('Suit does not exist: ' .. suit) - return false - elseif not rank_data then - sendDebugMessage('Rank does not exist: ' .. value) - return false + local rank_data = SMODS.Card.RANKS[value] + if not suit_data then + sendWarnMessage('Suit does not exist: ' .. suit) + return false + elseif not rank_data then + sendWarnMessage('Rank does not exist: ' .. value) + return false elseif not G.P_CARDS[suit_data.prefix .. '_' .. (rank_data.suffix or rank_data.value)] then - sendDebugMessage('Card not found at index: ' .. suit_data.prefix .. '_' .. (rank_data.suffix or rank_data.value)) + sendWarnMessage('Card not found at index: ' .. suit_data.prefix .. '_' .. (rank_data.suffix or rank_data.value)) return false end - G.P_CARDS[suit_data.prefix .. '_' .. (rank_data.suffix or rank_data.value)] = nil + G.P_CARDS[suit_data.prefix .. '_' .. (rank_data.suffix or rank_data.value)] = nil return true end @@ -271,8 +383,8 @@ function SMODS.Card:_extend() 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] + for k, c in pairs(G.C.SUITS) do + G.ARGS.LOC_COLOURS[k:lower()] = c end return G.ARGS.LOC_COLOURS[_c] or _default or G.C.UI.TEXT_DARK end @@ -322,11 +434,11 @@ function SMODS.Card:_extend() local straight = false local skipped_rank = false local vals = {} - for k, v in pairs(SMODS.Card.RANKS) do - if v.straight_edge then - table.insert(vals, k) - end - end + for k, v in pairs(SMODS.Card.RANKS) do + if v.straight_edge then + table.insert(vals, k) + end + end local init_vals = {} for _, v in ipairs(vals) do init_vals[v] = true @@ -474,10 +586,13 @@ function SMODS.Card:_extend() end local rank_tallies = {} local mod_rank_tallies = {} - local rank_name_mapping = SMODS.Card.RANK_LIST - for _, v in ipairs(SMODS.Card.RANK_LIST) do - rank_tallies[#rank_tallies + 1] = 0 - mod_rank_tallies[#mod_rank_tallies + 1] = 0 + local rank_name_mapping = SMODS.Card.RANK_LIST + local id_index_mapping = {} + for i, v in ipairs(SMODS.Card.RANK_LIST) do + local rank_data = SMODS.Card.RANKS[SMODS.Card.RANK_SHORTHAND_LOOKUP[v] or v] + id_index_mapping[rank_data.id] = i + rank_tallies[i] = 0 + mod_rank_tallies[i] = 0 end local face_tally = 0 local mod_face_tally = 0 @@ -510,8 +625,8 @@ function SMODS.Card:_extend() end --ranks - rank_tallies[card_id - 1] = rank_tallies[card_id - 1] + 1 - if not v.debuff then mod_rank_tallies[card_id - 1] = mod_rank_tallies[card_id - 1] + 1 end + rank_tallies[id_index_mapping[card_id]] = rank_tallies[id_index_mapping[card_id]] + 1 + if not v.debuff then mod_rank_tallies[id_index_mapping[card_id]] = mod_rank_tallies[id_index_mapping[card_id]] + 1 end end end @@ -716,7 +831,7 @@ function SMODS.Card:_extend() if not card_protos then card_protos = {} - for k, v in pairs(G.P_CARDS) do + for k, v in pairs(G.P_CARDS) do local rank_data = SMODS.Card.RANKS[v.value] local suit_data = SMODS.Card.SUITS[v.suit] local _r, _s = (rank_data.suffix or rank_data.value), suit_data.prefix @@ -818,9 +933,13 @@ function SMODS.Card:_extend() end local stones = nil - local rank_name_mapping = {} - for i = #SMODS.Card.RANK_LIST, 1, -1 do - rank_name_mapping[#rank_name_mapping + 1] = SMODS.Card.RANK_LIST[i] + local rank_name_mapping = {} + local id_index_mapping = {} + for i = #SMODS.Card.RANK_LIST, 1, -1 do + local v = SMODS.Card.RANK_LIST[i] + local rank_data = SMODS.Card.RANKS[SMODS.Card.RANK_SHORTHAND_LOOKUP[v] or v] + id_index_mapping[rank_data.id] = #rank_name_mapping+1 + rank_name_mapping[#rank_name_mapping + 1] = v end for k, v in ipairs(G.playing_cards) do @@ -839,7 +958,7 @@ function SMODS.Card:_extend() if SUITS[v.base.suit][v.base.id] then table.insert(SUITS[v.base.suit][v.base.id], v) end - rank_counts[v.base.id] = (rank_counts[v.base.id] or 0) + 1 + rank_counts[id_index_mapping[v.base.id]] = (rank_counts[id_index_mapping[v.base.id]] or 0) + 1 end end end @@ -888,7 +1007,7 @@ function SMODS.Card:_extend() n = G.UIT.R, config = { align = "cm", minw = _minw + 0.04, minh = _minh, colour = G.C.L_BLACK, r = 0.1 }, nodes = { - { n = G.UIT.T, config = { text = '' .. (rank_counts[15 - k] or 0), colour = flip_col, scale = _tscale, shadow = true } } + { n = G.UIT.T, config = { text = '' .. (rank_counts[id_index_mapping[k]] or 0), colour = flip_col, scale = _tscale, shadow = true } } } } } @@ -913,7 +1032,7 @@ function SMODS.Card:_extend() { n = G.UIT.T, config = { text = '' .. #SUITS[suit_list[j]][i], colour = _colour, scale = _tscale, shadow = true, lang = G.LANGUAGES['en-us'] } }, } } - table.insert(_row, _col) + if id_index_mapping[i] then table.insert(_row, _col) end end table.insert(deck_tables, { @@ -1065,7 +1184,7 @@ 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 diff --git a/core/tarot.lua b/core/tarot.lua index c94e32e1..dc8de31c 100644 --- a/core/tarot.lua +++ b/core/tarot.lua @@ -65,6 +65,7 @@ function SMODS.injectTarots() pos = tarot.pos, config = tarot.config, effect = tarot.effect, + cost = tarot.cost, cost_mult = tarot.cost_mult, atlas = tarot.atlas, mod_name = tarot.mod_name, @@ -86,7 +87,6 @@ function SMODS.injectTarots() sendDebugMessage("The Tarot named " .. tarot.name .. " with the slug " .. tarot.slug .. " have been registered at the id " .. id .. ".") end - SMODS.BUFFERS.Tarots = {} end function create_UIBox_your_collection_tarots() @@ -175,14 +175,14 @@ function generate_card_ui(_c, full_UI_table, specific_vars, card_type, badges, h local name_override = nil local info_queue = {} - local loc_vars = {} + local loc_vars = nil 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 o then loc_vars = o end if m then main_end = m end end local joker_obj = SMODS.Jokers[key] @@ -197,7 +197,7 @@ function generate_card_ui(_c, full_UI_table, specific_vars, card_type, badges, h end end - if next(loc_vars) or next(info_queue) then + if loc_vars or next(info_queue) then 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] @@ -226,7 +226,7 @@ function generate_card_ui(_c, full_UI_table, specific_vars, card_type, badges, h if main_start then desc_nodes[#desc_nodes + 1] = main_start end - if next(loc_vars) then + if loc_vars then localize { type = 'descriptions', key = _c.key, set = _c.set, nodes = desc_nodes, vars = loc_vars } 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 @@ -277,32 +277,36 @@ end local card_can_use_consumeable_ref = Card.can_use_consumeable function Card:can_use_consumeable(any_state, skip_check) - if not skip_check and ((G.play and #G.play.cards > 0) or - (G.CONTROLLER.locked) or - (G.GAME.STOP_USE and G.GAME.STOP_USE > 0)) - then - return false - end - if (G.STATE == G.STATES.HAND_PLAYED or G.STATE == G.STATES.DRAW_TO_HAND or G.STATE == G.STATES.PLAY_TAROT) and not any_state then - return false - end - local t = nil - 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 - else - return card_can_use_consumeable_ref(self, any_state, skip_check) - end + if not skip_check and ((G.play and #G.play.cards > 0) or + (G.CONTROLLER.locked) or + (G.GAME.STOP_USE and G.GAME.STOP_USE > 0)) + then + return false + end + if (G.STATE == G.STATES.HAND_PLAYED or G.STATE == G.STATES.DRAW_TO_HAND or G.STATE == G.STATES.PLAY_TAROT) and not any_state then + return false + end + local t = nil + 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 + else + 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 + if not card.config.center or -- no center + (card.config.center.unlocked == false and not card.bypass_lock) or -- locked card + card.debuff or -- debuffed card + (not card.config.center.discovered and ((card.area ~= G.jokers and card.area ~= G.consumeables and card.area) or not card.area)) -- undiscovered card + 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 @@ -329,4 +333,4 @@ function G.UIDEF.settings_tab(tab) t.nodes[7] = create_toggle { label = 'Disable Mod Tracking', ref_table = G.SETTINGS, ref_value = 'no_mod_tracking' } end return t -end +end \ No newline at end of file diff --git a/core/voucher.lua b/core/voucher.lua index 2b0676ec..036360c6 100644 --- a/core/voucher.lua +++ b/core/voucher.lua @@ -87,7 +87,6 @@ function SMODS.injectVouchers() sendDebugMessage("The Voucher named " .. voucher.name .. " with the slug " .. voucher.slug .. " have been registered at the id " .. id .. ".") end - SMODS.BUFFERS.Vouchers = {} end local Card_apply_to_run_ref = Card.apply_to_run @@ -96,10 +95,10 @@ function Card:apply_to_run(center) name = center and center.name or self and self.ability.name, extra = center and center.config.extra or self and self.ability.extra } - for _k, v in pairs(SMODS.Vouchers) do - if v.redeem and type(v.redeem) == 'function' and self.config.center.key == _k then - v.redeem(center_table) - end + local key = center and center.key or self and self.config.center.key + local voucher_obj = SMODS.Vouchers[key] + if voucher_obj and voucher_obj.redeem and type(voucher_obj.redeem) == 'function' then + voucher_obj.redeem(center_table) end Card_apply_to_run_ref(self, center) end \ No newline at end of file diff --git a/loader/loader.lua b/loader/loader.lua index ea9666d2..b0cfcafa 100644 --- a/loader/loader.lua +++ b/loader/loader.lua @@ -148,18 +148,35 @@ end function initSteamodded() injectStackTrace() - SMODS.MODS = loadMods(SMODS.MODS_DIR) + SMODS.MODS = loadMods(SMODS.MODS_DIR) - sendDebugMessage(inspectDepth(SMODS.MODS, 0, 0)) + sendDebugMessage(inspectDepth(SMODS.MODS, 0, 0)) initGlobals() - if SMODS.MODS then - initializeModUIFunctions() - initMods() - end - + if SMODS.MODS then + initializeModUIFunctions() + initMods() + end SMODS.injectSprites() + SMODS.injectDecks() + SMODS.injectJokers() + SMODS.injectTarots() + SMODS.injectPlanets() + SMODS.injectSpectrals() + SMODS.injectVouchers() + SMODS.injectBlinds() + SMODS.injectSeals() + SMODS.LOAD_LOC() + SMODS.SAVE_UNLOCKS() + sendDebugMessage(inspectDepth(G.P_CENTER_POOLS.Back)) +end + +-- retain added objects on profile reload +local init_item_prototypes_ref = Game.init_item_prototypes +function Game:init_item_prototypes() + init_item_prototypes_ref(self) + SMODS.injectSprites() SMODS.injectDecks() SMODS.injectJokers() SMODS.injectTarots() @@ -170,7 +187,11 @@ function initSteamodded() SMODS.injectSeals() SMODS.LOAD_LOC() SMODS.SAVE_UNLOCKS() - sendDebugMessage(inspectDepth(G.P_CENTER_POOLS.Back)) + for _, v in pairs(SMODS.Card.SUITS) do + if not v.disabled then + SMODS.Card:populate_suit(v.name) + end + end end ---------------------------------------------- diff --git a/lovely.toml b/lovely.toml index 0ccc37f7..fa2803b6 100644 --- a/lovely.toml +++ b/lovely.toml @@ -32,4 +32,4 @@ sources = [ "core/StackTracePlus.lua", "debug/debug.lua", "loader/loader.lua", -] +] \ No newline at end of file