content: [manifest]
  version = "0.1.0"
  dump_lua = true
  priority = 0
  
  # Ash Blossom prevent draw effect
  [[patches]]
  [patches.pattern]
  target = "functions/state_events.lua"
  pattern = "if G.GAME.blind.name == 'The Serpent' and"
  position = 'before'
  match_indent = true
  payload = '''
  if next(SMODS.find_card("j_joy_yokai_ash")) and
      (G.GAME.current_round.hands_played > 0 or G.GAME.current_round.discards_used > 0) then
      for _, joker in ipairs(SMODS.find_card("j_joy_yokai_ash")) do
          if JoyousSpring.can_use_abilities(joker) and
              SMODS.pseudorandom_probability(joker, joker.config.center.key, 1, joker.ability.extra.odds) then
              hand_space = (#G.hand.cards == 0) and 1 or 0
              SMODS.calculate_context({joy_no_draw = true, joy_card = joker})
              break
          end
      end
  end
  '''
  
  # Avramax instawin context
  [[patches]]
  [patches.pattern]
  target = "game.lua"
  pattern = "G.GAME.blind:drawn_to_hand()"
  position = 'before'
  match_indent = true
  payload = '''
  SMODS.calculate_context({joy_selecting_hand = true})
  '''
  
  # Game Over text (stolen from LobCorp <3)
  [[patches]]
  [patches.pattern]
  target = "functions/UI_definitions.lua"
  pattern = "local label_scale = 0.5"
  position = "before"
  payload = '''
  if score == 'defeated_by' and JoyousSpring and JoyousSpring.defeated_by then
      local center = G.P_CENTERS[JoyousSpring.defeated_by]
      local text = localize{type = 'name_text', key = JoyousSpring.defeated_by, set = "Joker"}
      local sprite = Sprite(0, 0, 1.4*(71/95), 1.4, G.ASSET_ATLAS[center.atlas], center.pos)
  
      sprite:define_draw_steps({
          {shader = 'dissolve', shadow_height = 0.05},
          {shader = 'dissolve'}
      })
  
      score_tab[1].nodes[1].config.object:remove()
      score_tab[2].nodes[1].config.object:remove()
      score_tab = {
          {n=G.UIT.R, config={align = "cm", minh = 0.6}, nodes={
              {n=G.UIT.O, config={object = DynaText({string = text, colours = {JoyousSpring.get_name_color(JoyousSpring.defeated_by)},shadow = true, float = true , scale = 0.35})}}
          }},
          {n=G.UIT.R, config={align = "cm", padding = 0.1}, nodes={
              {n=G.UIT.O, config={object = sprite}}
          }},
      }
      JoyousSpring.defeated_by = nil
  end'''
  match_indent = true
  
  # Keep cards flipped after blind
  [[patches]]
  [patches.pattern]
  target = "blind.lua"
  pattern = "if v.facing == 'back' then v:flip() end"
  position = 'at'
  match_indent = true
  payload = '''
  if self.name == 'Amber Acorn' then
      if v.facing == 'back' then v:flip() end
  end
  '''
  
  # Pre-setting_blind context to disable flip blind effects
  [[patches]]
  [patches.pattern]
  target = "functions/state_events.lua"
  pattern = "G.GAME.blind:set_blind(G.GAME.round_resets.blind)"
  position = 'before'
  match_indent = true
  payload = '''
  SMODS.calculate_context({joy_pre_setting_blind = true, joy_blind = G.GAME.round_resets.blind})
  '''
  
  # Add multiple hand_types to planets
  [[patches]]
  [patches.pattern]
  target = "card.lua"
  pattern = '''
  if v.config.hand_type == G.GAME.last_hand_played then
      _planet = v.key
  end
  '''
  position = 'after'
  match_indent = true
  payload = '''
  if v.config.joy_hand_types then
      for _, name in ipairs(v.config.joy_hand_types) do
          if name == G.GAME.last_hand_played then
              _planet = v.key
              break
          end
      end
      if planet ~= 0 then break end
  end
  '''
  
  # Add multiple hand_types to telescope
  [[patches]]
  [patches.pattern]
  target = '=[SMODS _ "src/game_object.lua"]'
  pattern = '''
  if v.config.hand_type == _hand then
      _planet = v.key
  end
  '''
  position = 'after'
  match_indent = true
  payload = '''
  if v.config.joy_hand_types then
      for _, name in ipairs(v.config.joy_hand_types) do
          if name == _hand then
              _planet = v.key
              break
          end
      end
      if planet then break end
  end
  '''
  
  # Don't shuffle after excavating
  [[patches]]
  [patches.pattern]
  target = "functions/state_events.lua"
  pattern = '''
  G.deck:shuffle('nr'..G.GAME.round_resets.ante)
  '''
  position = 'at'
  match_indent = true
  payload = '''
  if not G.GAME.joy_excavated then
      G.deck:shuffle('nr'..G.GAME.round_resets.ante)
  end
  G.GAME.joy_excavated = nil
  '''
  
  [[patches]]
  [patches.pattern]
  target = "functions/button_callbacks.lua"
  pattern = '''
  G.deck:shuffle('cashout'..G.GAME.round_resets.ante)
  '''
  position = 'after'
  match_indent = true
  payload = '''
  G.GAME.joy_excavated = nil
  '''
  