Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes / utility for joker API #48

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 101 additions & 58 deletions core/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

----------------------------------------------
Expand Down
98 changes: 85 additions & 13 deletions core/joker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 15 additions & 3 deletions core/sprite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading