Skip to content
Open
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
6 changes: 6 additions & 0 deletions lsp_def/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,12 @@ function SMODS.copy_card(card, args) end
---@return Card|table
function SMODS.add_to_deck(card, args) end

-- Util function to render one card to a `.png` file, saved to `love.filesystem.getSaveDirectory()`
---@param card Card|table Card to save as an image
---@param scale number? Scale to render the card at (default = G.SETTINGS.GRAPHICS.texture_scaling)
---@param filename string? Name of the file (default = [center.key])
function SMODS.card_to_image(card, scale, filename) end

---Checks if a card counts as at least one suit that matches the provided suit shade
---@param card Card|table Card to check
---@param shade string Suit shade to check for
Expand Down
62 changes: 62 additions & 0 deletions src/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4293,6 +4293,68 @@ function SMODS.add_to_deck(card, args)
return card
end

-- Hook for the below Util function
local sprite_draw_from_ref = Sprite.draw_from
function Sprite:draw_from(...)
local old_filter_min, old_filter_mag
if self.atlas and SMODS.texture_filter_override then
old_filter_min, old_filter_mag = self.atlas.image:getFilter()
self.atlas.image:setFilter(SMODS.texture_filter_override, SMODS.texture_filter_override)
end
local ret = sprite_draw_from_ref(self, ...)
if self.atlas and SMODS.texture_filter_override then
self.atlas.image:setFilter(old_filter_min, old_filter_mag)
end
return ret
end

-- Hook for the below Util function
local sprite_draw_self_ref = Sprite.draw_self
function Sprite:draw_self(...)
local old_filter_min, old_filter_mag
if self.atlas and SMODS.texture_filter_override then
old_filter_min, old_filter_mag = self.atlas.image:getFilter()
self.atlas.image:setFilter(SMODS.texture_filter_override, SMODS.texture_filter_override)
end
local ret = sprite_draw_self_ref(self, ...)
if self.atlas and SMODS.texture_filter_override then
self.atlas.image:setFilter(old_filter_min, old_filter_mag)
end
return ret
end

-- Util function to render one card to a .png file (usually saved to the mods folder's parent directory)
function SMODS.card_to_image(card, scale, filename)
if not type(card) == "table" then return end
local key = ((card.config or {}).center or {}).key or "card_to_image"
scale = scale or G.SETTINGS.GRAPHICS.texture_scaling
filename = (filename or key == "j_joker" and "jimbo" or key) .. ".png"

local canvas = love.graphics.newCanvas(71 * scale, 95 * scale, {type = '2d', readable = true})
canvas:setFilter('nearest', 'nearest')

local old_t = SMODS.shallow_copy(card.T)
local old_shadow = card.no_shadow
local old_rm = G.SETTINGS.reduced_motion
card.T.r = 0
local old_scale = card.T.scale
card.T.scale = scale / G.TILE_H * G.window_prev.orig_scale * G.window_prev.orig_scale/G.TILESCALE * 1.5 * 763/768 -- Don't ask me why I had to multiply by 1.5 * 763/768 here, I do not know,,, (this may have been brute-tinkered) (well the times 763/768 is to remove an extra pixel in height for scales == 2.0 -> 16.0 (at least))
card:hard_set_T(card.T.w/2*(card.T.scale-1), card.T.h/2*(card.T.scale-1))
card.no_shadow = true
G.SETTINGS.reduced_motion = true
SMODS.texture_filter_override = "nearest"
canvas:renderTo(card.draw, card)
SMODS.texture_filter_override = nil
G.SETTINGS.reduced_motion = old_rm
card.no_shadow = old_shadow
card.T.scale = old_scale
card:hard_set_T(old_t.x, old_t.y, old_t.w, old_t.h)

local image_data = canvas:newImageData()
image_data:encode("png", filename)
print("SMODS : Saved card image to "..love.filesystem.getSaveDirectory().."/"..filename)
end

function Card:is_suit_shade(shade, bypass_debuff)
if self.debuff and not bypass_debuff then return end
if SMODS.has_no_suit(self) then
Expand Down