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

Add an optional surrounding key for the pattern patch #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TheBearodactyl
Copy link

this makes it easier to only patch one instance of a piece of code when there's more than one in the target file with a pattern patch as opposed to needing a regex patch. For example:

lovely.toml:

[[patches]]
[patches.pattern]
target = "cardarea.lua"
pattern = "card:highlight(false)"
surrounding = { before = "end", after = "if self == G.hand and G.STATE == G.SELECTING_HAND then" }
position = "at"
payload = '''
if card then
    card:highlight(false)
end
'''
match_indent = true

Turns this:

cardarea.lua:

...
    if #self.highlighted >= self.config.highlighted_limit then
        card:highlight(false)
    else
...
        end
    end
    card:highlight(false)
    if self == G.hand and G.STATE == G.SELECTING_HAND then
...

into this:
cardarea.lua:

...
    if #self.highlighted >= self.config.highlighted_limit then
        card:highlight(false) -- Unaffected
    else
...
        end
    end
    if card then
        card:highlight(false) -- Had the patch applied
    end
    if self == G.hand and G.STATE == G.SELECTING_HAND then
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant