[manifest]
version = "1.0.0"
dump_lua = true
priority = 69

# If somehow someone still uses version that old - maybe add this pattern too
#    -- Steamodded<0917b
#	for k, v in ipairs(G.playing_cards) do
#		table.insert(SUITS[v.base.suit], v)
[[patches]]
[patches.pattern]
target = '=[SMODS _ "src/overrides.lua"]'
match_indent = true
pattern = '''
	for k, v in ipairs(G.playing_cards) do
		if v.base.suit then table.insert(SUITS[v.base.suit], v) end'''
position = "at"
payload = '''
local SUITS_SORTED = Cartomancer.tablecopy(SUITS)
for k, v in ipairs(G.playing_cards) do
  if v.base.suit then
  local greyed
  if unplayed_only and not ((v.area and v.area == G.deck) or v.ability.wheel_flipped) then
    greyed = true
  end
  local card_string = v:cart_to_string {deck_view = true, greyed = true}
  if greyed then
    card_string = string.format('%sGreyed', card_string)
  end

  if greyed and Cartomancer.SETTINGS.deck_view_hide_drawn_cards then
  -- Ignore this card.
  elseif not SUITS[v.base.suit][card_string] then
    -- Initiate stack
    table.insert(SUITS_SORTED[v.base.suit], card_string)

    local _scale = 0.7
    local copy = copy_card(v, nil, _scale)

    copy.greyed = greyed
    copy.stacked_quantity = 1

    SUITS[v.base.suit][card_string] = copy
  else
    -- Stack cards
    local stacked_card = SUITS[v.base.suit][card_string]
    stacked_card.stacked_quantity = stacked_card.stacked_quantity + 1
  end
  end
'''

[[patches]]
[patches.pattern]
target = '=[SMODS _ "src/overrides.lua"]'
match_indent = true
pattern = 'card_limit = #SUITS[suit_map[j]],'
position = "at"
payload = 'card_limit = #SUITS_SORTED[suit_map[j]],'

[[patches]]
[patches.pattern]
target = '=[SMODS _ "src/overrides.lua"]'
match_indent = true
pattern = '''
			for i = 1, #SUITS[suit_map[j]] do
				if SUITS[suit_map[j]][i] then
					local greyed, _scale = nil, 0.7
					if unplayed_only and not ((SUITS[suit_map[j]][i].area and SUITS[suit_map[j]][i].area == G.deck) or SUITS[suit_map[j]][i].ability.wheel_flipped) then
						greyed = true
					end
					local copy = copy_card(SUITS[suit_map[j]][i], nil, _scale)
					copy.greyed = greyed
					copy.T.x = view_deck.T.x + view_deck.T.w / 2
					copy.T.y = view_deck.T.y

					copy:hard_set_T()
					view_deck:emplace(copy)
				end
			end'''
position = "at"
payload = '''
for i = 1, #SUITS_SORTED[suit_map[j]] do
  local card_string = SUITS_SORTED[suit_map[j]][i]
  local card = SUITS[suit_map[j]][card_string]

  card.T.x = view_deck.T.x + view_deck.T.w/2
  card.T.y = view_deck.T.y
  card:create_quantity_display()

  card:hard_set_T()
  view_deck:emplace(card)
end
'''

[[patches]]
[patches.pattern]
target = '=[SMODS _ "src/overrides.lua"]'
match_indent = true
pattern = '			modded and {n = G.UIT.R, config = {align = "cm"}, nodes = {'
position = "at"
payload = '''
      not unplayed_only and Cartomancer.add_unique_count() or nil,
			modded and {n = G.UIT.R, config = {align = "cm"}, nodes = {'''
